@@ -31,12 +31,10 @@ public static void write(PrintWriter out, String packageName) {
31
31
+ "\n "
32
32
+ "import static java.util.function.Predicate.not;\n "
33
33
+ "\n "
34
- + "import java.io.BufferedReader;\n "
35
- + "import java.io.IOException;\n "
36
- + "import java.io.InputStreamReader;\n "
37
- + "import java.util.Collection;\n "
38
- + "import java.util.Optional;\n "
39
- + "import java.util.Set;\n "
34
+ + "import java.io.*;\n "
35
+ + "import java.net.URI;\n "
36
+ + "import java.nio.file.Path;\n "
37
+ + "import java.util.*;\n "
40
38
+ "import java.util.stream.Stream;\n "
41
39
+ "\n "
42
40
+ "import javax.annotation.processing.Filer;\n "
@@ -384,7 +382,31 @@ public static void write(PrintWriter out, String packageName) {
384
382
+ " .toURL()\n "
385
383
+ " .openStream();\n "
386
384
+ " return new BufferedReader(new InputStreamReader(inputStream));\n "
387
- + " }\n "
385
+ + " }\n \n "
386
+ + " /**\n "
387
+ + " * Given the relative path, gets a {@link Path} from the Maven {@code target}/Gradle {@code build} folder.\n "
388
+ + " * @param path the relative path of the file in the target/build folder\n "
389
+ + " *\n "
390
+ + " * @return the file object\n "
391
+ + " * @throws IOException if unable to retrieve the file\n "
392
+ + " */\n "
393
+ + " public static Path getBuildResource(String path) throws IOException {\n "
394
+ + "\n "
395
+ + " var id = UUID.randomUUID().toString();\n "
396
+ + " final var uri =\n "
397
+ + " filer()\n "
398
+ + " .createResource(StandardLocation.CLASS_OUTPUT, \" \" , path + id)\n "
399
+ + " .toUri()\n "
400
+ + " .toString()\n "
401
+ + " .replaceFirst(id, \" \" )\n "
402
+ + " .replaceFirst(\" /classes\" , \" \" )\n "
403
+ + " .replaceFirst(\" /classes/java/main\" , \" \" );\n "
404
+ + " var updatedPath = Path.of(URI.create(uri));\n "
405
+ + " if (path.contains(\" /\" )) {\n "
406
+ + " updatedPath.getParent().toFile().mkdirs();\n "
407
+ + " }\n "
408
+ + " return updatedPath;\n "
409
+ + " }"
388
410
+ "}\n "
389
411
+ "" );
390
412
}
0 commit comments