< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/jdeprscan/Main.java

Print this page




  89  *  - add module support: --add-modules, --module-path, module arg
  90  *  - load deprecation declarations from a designated class library instead
  91  *    of the JDK
  92  *  - load deprecation declarations from a module
  93  *  - scan a module (but a modular jar can be treated just a like an ordinary jar)
  94  *  - multi-version jar
  95  */
  96 public class Main implements DiagnosticListener<JavaFileObject> {
  97     final PrintStream out;
  98     final PrintStream err;
  99     final List<File> bootClassPath = new ArrayList<>();
 100     final List<File> classPath = new ArrayList<>();
 101     final List<File> systemModules = new ArrayList<>();
 102     final List<String> options = new ArrayList<>();
 103     final List<String> comments = new ArrayList<>();
 104 
 105     // Valid releases need to match what the compiler supports.
 106     // Keep these updated manually until there's a compiler API
 107     // that allows querying of supported releases.
 108     final Set<String> releasesWithoutForRemoval = Set.of("6", "7", "8");
 109     final Set<String> releasesWithForRemoval = Set.of("9", "10");
 110 
 111     final Set<String> validReleases;
 112     {
 113         Set<String> temp = new HashSet<>(releasesWithoutForRemoval);
 114         temp.addAll(releasesWithForRemoval);
 115         validReleases = Set.of(temp.toArray(new String[0]));
 116     }
 117 
 118     boolean verbose = false;
 119     boolean forRemoval = false;
 120 
 121     final JavaCompiler compiler;
 122     final StandardJavaFileManager fm;
 123 
 124     List<DeprData> deprList; // non-null after successful load phase
 125 
 126     /**
 127      * Processes a collection of class names. Names should fully qualified
 128      * names in the form "pkg.pkg.pkg.classname".
 129      *


 341             Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
 342                                       .getPath("/modules");
 343 
 344             // names are /modules/<modulename>/pkg/.../Classname.class
 345             try (Stream<Path> paths = Files.walk(modules)) {
 346                 Stream<String> files =
 347                     paths.filter(p -> p.getNameCount() > 2)
 348                          .map(p -> p.subpath(1, p.getNameCount()))
 349                          .map(Path::toString);
 350                 return doModularFileNames(files);
 351             }
 352         } else {
 353             return doClassNames(classes);
 354         }
 355     }
 356 
 357     /**
 358      * Process classes from a particular JDK release, using only information
 359      * in this JDK.
 360      *
 361      * @param release "6", "7", "8", "9", or "10"
 362      * @param classes collection of classes to process, may be empty
 363      * @return success value
 364      */
 365     boolean processRelease(String release, Collection<String> classes) throws IOException {
 366         options.addAll(List.of("--release", release));
 367 
 368         if (release.equals("9") || release.equals("10")) {

 369             List<String> rootMods = List.of("java.se", "java.se.ee");
 370             TraverseProc proc = new TraverseProc(rootMods);
 371             JavaCompiler.CompilationTask task =
 372                 compiler.getTask(null, fm, this,
 373                                  // options
 374                                  List.of("--add-modules", String.join(",", rootMods)),
 375                                  // classes
 376                                  List.of("java.lang.Object"),
 377                                  null);
 378             task.setProcessors(List.of(proc));
 379             if (!task.call()) {
 380                 return false;
 381             }
 382             Map<PackageElement, List<TypeElement>> types = proc.getPublicTypes();
 383             options.add("--add-modules");
 384             options.add(String.join(",", rootMods));
 385             return doClassNames(
 386                 types.values().stream()
 387                      .flatMap(List::stream)
 388                      .map(TypeElement::toString)


 464      * @param diagnostic the tool diagnostic to print
 465      */
 466     @Override
 467     public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
 468         err.println(diagnostic);
 469     }
 470 
 471     /**
 472      * Parses arguments and performs the requested processing.
 473      *
 474      * @param argArray command-line arguments
 475      * @return true on success, false on error
 476      */
 477     boolean run(String... argArray) {
 478         Queue<String> args = new ArrayDeque<>(Arrays.asList(argArray));
 479         LoadMode loadMode = LoadMode.RELEASE;
 480         ScanMode scanMode = ScanMode.ARGS;
 481         String dir = null;
 482         String jar = null;
 483         String jdkHome = null;
 484         String release = "10";
 485         List<String> loadClasses = new ArrayList<>();
 486         String csvFile = null;
 487 
 488         try {
 489             while (!args.isEmpty()) {
 490                 String a = args.element();
 491                 if (a.startsWith("-")) {
 492                     args.remove();
 493                     switch (a) {
 494                         case "--class-path":
 495                             classPath.clear();
 496                             Arrays.stream(args.remove().split(File.pathSeparator))
 497                                   .map(File::new)
 498                                   .forEachOrdered(classPath::add);
 499                             break;
 500                         case "--for-removal":
 501                             forRemoval = true;
 502                             break;
 503                         case "--full-version":
 504                             out.println(System.getProperty("java.vm.version"));




  89  *  - add module support: --add-modules, --module-path, module arg
  90  *  - load deprecation declarations from a designated class library instead
  91  *    of the JDK
  92  *  - load deprecation declarations from a module
  93  *  - scan a module (but a modular jar can be treated just a like an ordinary jar)
  94  *  - multi-version jar
  95  */
  96 public class Main implements DiagnosticListener<JavaFileObject> {
  97     final PrintStream out;
  98     final PrintStream err;
  99     final List<File> bootClassPath = new ArrayList<>();
 100     final List<File> classPath = new ArrayList<>();
 101     final List<File> systemModules = new ArrayList<>();
 102     final List<String> options = new ArrayList<>();
 103     final List<String> comments = new ArrayList<>();
 104 
 105     // Valid releases need to match what the compiler supports.
 106     // Keep these updated manually until there's a compiler API
 107     // that allows querying of supported releases.
 108     final Set<String> releasesWithoutForRemoval = Set.of("6", "7", "8");
 109     final Set<String> releasesWithForRemoval = Set.of("9", "10", "11");
 110 
 111     final Set<String> validReleases;
 112     {
 113         Set<String> temp = new HashSet<>(releasesWithoutForRemoval);
 114         temp.addAll(releasesWithForRemoval);
 115         validReleases = Set.of(temp.toArray(new String[0]));
 116     }
 117 
 118     boolean verbose = false;
 119     boolean forRemoval = false;
 120 
 121     final JavaCompiler compiler;
 122     final StandardJavaFileManager fm;
 123 
 124     List<DeprData> deprList; // non-null after successful load phase
 125 
 126     /**
 127      * Processes a collection of class names. Names should fully qualified
 128      * names in the form "pkg.pkg.pkg.classname".
 129      *


 341             Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
 342                                       .getPath("/modules");
 343 
 344             // names are /modules/<modulename>/pkg/.../Classname.class
 345             try (Stream<Path> paths = Files.walk(modules)) {
 346                 Stream<String> files =
 347                     paths.filter(p -> p.getNameCount() > 2)
 348                          .map(p -> p.subpath(1, p.getNameCount()))
 349                          .map(Path::toString);
 350                 return doModularFileNames(files);
 351             }
 352         } else {
 353             return doClassNames(classes);
 354         }
 355     }
 356 
 357     /**
 358      * Process classes from a particular JDK release, using only information
 359      * in this JDK.
 360      *
 361      * @param release "6", "7", "8", "9", "10", or "11"
 362      * @param classes collection of classes to process, may be empty
 363      * @return success value
 364      */
 365     boolean processRelease(String release, Collection<String> classes) throws IOException {
 366         options.addAll(List.of("--release", release));
 367 
 368         if (release.equals("9") || release.equals("10") ||
 369             release.equals("11")) {
 370             List<String> rootMods = List.of("java.se", "java.se.ee");
 371             TraverseProc proc = new TraverseProc(rootMods);
 372             JavaCompiler.CompilationTask task =
 373                 compiler.getTask(null, fm, this,
 374                                  // options
 375                                  List.of("--add-modules", String.join(",", rootMods)),
 376                                  // classes
 377                                  List.of("java.lang.Object"),
 378                                  null);
 379             task.setProcessors(List.of(proc));
 380             if (!task.call()) {
 381                 return false;
 382             }
 383             Map<PackageElement, List<TypeElement>> types = proc.getPublicTypes();
 384             options.add("--add-modules");
 385             options.add(String.join(",", rootMods));
 386             return doClassNames(
 387                 types.values().stream()
 388                      .flatMap(List::stream)
 389                      .map(TypeElement::toString)


 465      * @param diagnostic the tool diagnostic to print
 466      */
 467     @Override
 468     public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
 469         err.println(diagnostic);
 470     }
 471 
 472     /**
 473      * Parses arguments and performs the requested processing.
 474      *
 475      * @param argArray command-line arguments
 476      * @return true on success, false on error
 477      */
 478     boolean run(String... argArray) {
 479         Queue<String> args = new ArrayDeque<>(Arrays.asList(argArray));
 480         LoadMode loadMode = LoadMode.RELEASE;
 481         ScanMode scanMode = ScanMode.ARGS;
 482         String dir = null;
 483         String jar = null;
 484         String jdkHome = null;
 485         String release = "11";
 486         List<String> loadClasses = new ArrayList<>();
 487         String csvFile = null;
 488 
 489         try {
 490             while (!args.isEmpty()) {
 491                 String a = args.element();
 492                 if (a.startsWith("-")) {
 493                     args.remove();
 494                     switch (a) {
 495                         case "--class-path":
 496                             classPath.clear();
 497                             Arrays.stream(args.remove().split(File.pathSeparator))
 498                                   .map(File::new)
 499                                   .forEachOrdered(classPath::add);
 500                             break;
 501                         case "--for-removal":
 502                             forRemoval = true;
 503                             break;
 504                         case "--full-version":
 505                             out.println(System.getProperty("java.vm.version"));


< prev index next >