Skip to content

Commit

Permalink
Write generated Java files to disk only if debug flag is set
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann committed Aug 28, 2019
1 parent b66329f commit 398e64e
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ public T instantiate() {
} else {
final String name = String.format("CompiledDataset%d", CLASS_CACHE.size());
final String code = generateCode(name);
final Path sourceFile = SOURCE_DIR.resolve(String.format("%s.java", name));
Files.write(sourceFile, code.getBytes(StandardCharsets.UTF_8));
COMPILER.cookFile(sourceFile.toFile());
if (SOURCE_DIR != null) {
final Path sourceFile = SOURCE_DIR.resolve(String.format("%s.java", name));
Files.write(sourceFile, code.getBytes(StandardCharsets.UTF_8));
COMPILER.cookFile(sourceFile.toFile());
} else {
COMPILER.cook(code);
}
COMPILER.setParentClassLoader(COMPILER.getClassLoader());
clazz = (Class<T>) COMPILER.getClassLoader().loadClass(
String.format("org.logstash.generated.%s", name)
Expand Down Expand Up @@ -125,17 +129,15 @@ private String generateCode(final String name) {
}

private static Path debugDir() {
final Path sourceDir;
Path sourceDir = null;
try {
final Path parentDir;
final String dir = System.getProperty(ICookable.SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR);
if (dir == null) {
parentDir = Files.createTempDirectory("logstash");
} else {
if (dir != null) {
parentDir = Paths.get(dir);
sourceDir = parentDir.resolve("org").resolve("logstash").resolve("generated");
Files.createDirectories(sourceDir);
}
sourceDir = parentDir.resolve("org").resolve("logstash").resolve("generated");
Files.createDirectories(sourceDir);
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
Expand Down

0 comments on commit 398e64e

Please sign in to comment.