From 77ecb2b83b760e5fdc4350aa7c4e6568c431a123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20=C5=BBygie=C5=82o?= Date: Thu, 1 Aug 2024 23:37:48 +0200 Subject: [PATCH] Remove temporary JavaTemplate files --- .../main/java/org/openrewrite/java/JavaTemplate.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java index 954023b163a..3ea221f13b7 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java @@ -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);