84 * - add module support: --add-modules, --module-path, module arg
85 * - load deprecation declarations from a designated class library instead
86 * of the JDK
87 * - load deprecation declarations from a module
88 * - scan a module (but a modular jar can be treated just a like an ordinary jar)
89 * - multi-version jar
90 */
91 public class Main implements DiagnosticListener<JavaFileObject> {
92 final PrintStream out;
93 final PrintStream err;
94 final List<File> bootClassPath = new ArrayList<>();
95 final List<File> classPath = new ArrayList<>();
96 final List<File> systemModules = new ArrayList<>();
97 final List<String> options = new ArrayList<>();
98 final List<String> comments = new ArrayList<>();
99
100 // Valid releases need to match what the compiler supports.
101 // Keep these updated manually until there's a compiler API
102 // that allows querying of supported releases.
103 final Set<String> releasesWithoutForRemoval = Set.of("6", "7", "8");
104 final Set<String> releasesWithForRemoval = Set.of("9");
105
106 final Set<String> validReleases;
107 {
108 Set<String> temp = new HashSet<>(releasesWithoutForRemoval);
109 temp.addAll(releasesWithForRemoval);
110 validReleases = Set.of(temp.toArray(new String[0]));
111 }
112
113 boolean verbose = false;
114 boolean forRemoval = false;
115
116 final JavaCompiler compiler;
117 final StandardJavaFileManager fm;
118
119 List<DeprData> deprList; // non-null after successful load phase
120
121 /**
122 * Processes a collection of class names. Names should fully qualified
123 * names in the form "pkg.pkg.pkg.classname".
124 *
336 Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
337 .getPath("/modules");
338
339 // names are /modules/<modulename>/pkg/.../Classname.class
340 try (Stream<Path> paths = Files.walk(modules)) {
341 Stream<String> files =
342 paths.filter(p -> p.getNameCount() > 2)
343 .map(p -> p.subpath(1, p.getNameCount()))
344 .map(Path::toString);
345 return doModularFileNames(files);
346 }
347 } else {
348 return doClassNames(classes);
349 }
350 }
351
352 /**
353 * Process classes from a particular JDK release, using only information
354 * in this JDK.
355 *
356 * @param release "6", "7", "8", or "9"
357 * @param classes collection of classes to process, may be empty
358 * @return success value
359 */
360 boolean processRelease(String release, Collection<String> classes) throws IOException {
361 options.addAll(List.of("--release", release));
362
363 if (release.equals("9")) {
364 List<String> rootMods = List.of("java.se", "java.se.ee");
365 TraverseProc proc = new TraverseProc(rootMods);
366 JavaCompiler.CompilationTask task =
367 compiler.getTask(null, fm, this,
368 // options
369 List.of("--add-modules", String.join(",", rootMods)),
370 // classes
371 List.of("java.lang.Object"),
372 null);
373 task.setProcessors(List.of(proc));
374 if (!task.call()) {
375 return false;
376 }
377 Map<PackageElement, List<TypeElement>> types = proc.getPublicTypes();
378 options.add("--add-modules");
379 options.add(String.join(",", rootMods));
380 return doClassNames(
381 types.values().stream()
382 .flatMap(List::stream)
383 .map(TypeElement::toString)
|
84 * - add module support: --add-modules, --module-path, module arg
85 * - load deprecation declarations from a designated class library instead
86 * of the JDK
87 * - load deprecation declarations from a module
88 * - scan a module (but a modular jar can be treated just a like an ordinary jar)
89 * - multi-version jar
90 */
91 public class Main implements DiagnosticListener<JavaFileObject> {
92 final PrintStream out;
93 final PrintStream err;
94 final List<File> bootClassPath = new ArrayList<>();
95 final List<File> classPath = new ArrayList<>();
96 final List<File> systemModules = new ArrayList<>();
97 final List<String> options = new ArrayList<>();
98 final List<String> comments = new ArrayList<>();
99
100 // Valid releases need to match what the compiler supports.
101 // Keep these updated manually until there's a compiler API
102 // that allows querying of supported releases.
103 final Set<String> releasesWithoutForRemoval = Set.of("6", "7", "8");
104 final Set<String> releasesWithForRemoval = Set.of("9", "10");
105
106 final Set<String> validReleases;
107 {
108 Set<String> temp = new HashSet<>(releasesWithoutForRemoval);
109 temp.addAll(releasesWithForRemoval);
110 validReleases = Set.of(temp.toArray(new String[0]));
111 }
112
113 boolean verbose = false;
114 boolean forRemoval = false;
115
116 final JavaCompiler compiler;
117 final StandardJavaFileManager fm;
118
119 List<DeprData> deprList; // non-null after successful load phase
120
121 /**
122 * Processes a collection of class names. Names should fully qualified
123 * names in the form "pkg.pkg.pkg.classname".
124 *
336 Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
337 .getPath("/modules");
338
339 // names are /modules/<modulename>/pkg/.../Classname.class
340 try (Stream<Path> paths = Files.walk(modules)) {
341 Stream<String> files =
342 paths.filter(p -> p.getNameCount() > 2)
343 .map(p -> p.subpath(1, p.getNameCount()))
344 .map(Path::toString);
345 return doModularFileNames(files);
346 }
347 } else {
348 return doClassNames(classes);
349 }
350 }
351
352 /**
353 * Process classes from a particular JDK release, using only information
354 * in this JDK.
355 *
356 * @param release "6", "7", "8", "9", or "10"
357 * @param classes collection of classes to process, may be empty
358 * @return success value
359 */
360 boolean processRelease(String release, Collection<String> classes) throws IOException {
361 options.addAll(List.of("--release", release));
362
363 if (release.equals("9") || release.equals("10")) {
364 List<String> rootMods = List.of("java.se", "java.se.ee");
365 TraverseProc proc = new TraverseProc(rootMods);
366 JavaCompiler.CompilationTask task =
367 compiler.getTask(null, fm, this,
368 // options
369 List.of("--add-modules", String.join(",", rootMods)),
370 // classes
371 List.of("java.lang.Object"),
372 null);
373 task.setProcessors(List.of(proc));
374 if (!task.call()) {
375 return false;
376 }
377 Map<PackageElement, List<TypeElement>> types = proc.getPublicTypes();
378 options.add("--add-modules");
379 options.add(String.join(",", rootMods));
380 return doClassNames(
381 types.values().stream()
382 .flatMap(List::stream)
383 .map(TypeElement::toString)
|