Skip to content

Commit

Permalink
Remove temporary JavaTemplate files
Browse files Browse the repository at this point in the history
  • Loading branch information
pzygielo committed Aug 1, 2024
1 parent 65fb0cf commit 77ecb2b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ protected static Path getTemplateClasspathDir() {
if (TEMPLATE_CLASSPATH_DIR == null) {
try {
TEMPLATE_CLASSPATH_DIR = Files.createTempDirectory("java-template");
TEMPLATE_CLASSPATH_DIR.toFile().deleteOnExit();
Path templateDir = Files.createDirectories(TEMPLATE_CLASSPATH_DIR.resolve("org/openrewrite/java/internal/template"));
for (Path subDir : new Path[] {
TEMPLATE_CLASSPATH_DIR.resolve("org"),
TEMPLATE_CLASSPATH_DIR.resolve("org/openrewrite"),
TEMPLATE_CLASSPATH_DIR.resolve("org/openrewrite/java"),
TEMPLATE_CLASSPATH_DIR.resolve("org/openrewrite/java/internal")
}) {
subDir.toFile().deleteOnExit();
}
templateDir.toFile().deleteOnExit();
try (InputStream in = JavaTemplateParser.class.getClassLoader().getResourceAsStream("org/openrewrite/java/internal/template/__M__.class")) {
assert in != null;
Files.copy(in, templateDir.resolve("__M__.class"));
templateDir.resolve("__M__.class").toFile().deleteOnExit();
}
try (InputStream in = JavaTemplateParser.class.getClassLoader().getResourceAsStream("org/openrewrite/java/internal/template/__P__.class")) {
assert in != null;
Files.copy(in, templateDir.resolve("__P__.class"));
templateDir.resolve("__P__.class").toFile().deleteOnExit();
}
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 77ecb2b

Please sign in to comment.