8029216: (jdeps) Provide a specific option to report JDK internal APIs

Wed, 04 Dec 2013 15:39:36 -0800

author
mchung
date
Wed, 04 Dec 2013 15:39:36 -0800
changeset 2214
4a2ed1900428
parent 2213
1b69023743be
child 2215
b3d7e86a0647
child 2218
2d0a0ae7fa9c

8029216: (jdeps) Provide a specific option to report JDK internal APIs
Reviewed-by: alanb

src/share/classes/com/sun/tools/jdeps/JdepsTask.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties file | annotate | diff | comparison | revisions
test/tools/jdeps/APIDeps.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java	Tue Dec 03 23:10:23 2013 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java	Wed Dec 04 15:39:36 2013 -0800
     1.3 @@ -180,6 +180,15 @@
     1.4                  task.options.depth = 0;
     1.5              }
     1.6          },
     1.7 +        new Option(false, "-jdkinternals") {
     1.8 +            void process(JdepsTask task, String opt, String arg) {
     1.9 +                task.options.findJDKInternals = true;
    1.10 +                task.options.verbose = Analyzer.Type.CLASS;
    1.11 +                if (task.options.includePattern == null) {
    1.12 +                    task.options.includePattern = Pattern.compile(".*");
    1.13 +                }
    1.14 +            }
    1.15 +        },
    1.16          new Option(false, "-version") {
    1.17              void process(JdepsTask task, String opt, String arg) {
    1.18                  task.options.version = true;
    1.19 @@ -248,6 +257,11 @@
    1.20                  showHelp();
    1.21                  return EXIT_CMDERR;
    1.22              }
    1.23 +            if (options.findJDKInternals &&
    1.24 +                   (options.regex != null || options.packageNames.size() > 0 || options.showSummary)) {
    1.25 +                showHelp();
    1.26 +                return EXIT_CMDERR;
    1.27 +            }
    1.28              if (options.showSummary && options.verbose != Analyzer.Type.SUMMARY) {
    1.29                  showHelp();
    1.30                  return EXIT_CMDERR;
    1.31 @@ -571,6 +585,7 @@
    1.32          boolean wildcard;
    1.33          boolean apiOnly;
    1.34          boolean showLabel;
    1.35 +        boolean findJDKInternals;
    1.36          String dotOutputDir;
    1.37          String classpath = "";
    1.38          int depth = 1;
    1.39 @@ -681,11 +696,22 @@
    1.40          @Override
    1.41          public void visitDependence(String origin, Archive source,
    1.42                                      String target, Archive archive, Profile profile) {
    1.43 -            if (!origin.equals(pkg)) {
    1.44 -                pkg = origin;
    1.45 -                writer.format("   %s (%s)%n", origin, source.getFileName());
    1.46 +            if (options.findJDKInternals &&
    1.47 +                    !(archive instanceof JDKArchive && profile == null)) {
    1.48 +                // filter dependences other than JDK internal APIs
    1.49 +                return;
    1.50              }
    1.51 -            writer.format("      -> %-50s %s%n", target, getProfileArchiveInfo(archive, profile));
    1.52 +            if (options.verbose == Analyzer.Type.VERBOSE) {
    1.53 +                writer.format("   %-50s -> %-50s %s%n",
    1.54 +                              origin, target, getProfileArchiveInfo(archive, profile));
    1.55 +            } else {
    1.56 +                if (!origin.equals(pkg)) {
    1.57 +                    pkg = origin;
    1.58 +                    writer.format("   %s (%s)%n", origin, source.getFileName());
    1.59 +                }
    1.60 +                writer.format("      -> %-50s %s%n",
    1.61 +                              target, getProfileArchiveInfo(archive, profile));
    1.62 +            }
    1.63          }
    1.64  
    1.65          @Override
    1.66 @@ -717,6 +743,11 @@
    1.67          @Override
    1.68          public void visitDependence(String origin, Archive source,
    1.69                                      String target, Archive archive, Profile profile) {
    1.70 +            if (options.findJDKInternals &&
    1.71 +                    !(archive instanceof JDKArchive && profile == null)) {
    1.72 +                // filter dependences other than JDK internal APIs
    1.73 +                return;
    1.74 +            }
    1.75              // if -P option is specified, package name -> profile will
    1.76              // be shown and filter out multiple same edges.
    1.77              String name = getProfileArchiveInfo(archive, profile);
     2.1 --- a/src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Tue Dec 03 23:10:23 2013 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Wed Dec 04 15:39:36 2013 -0800
     2.3 @@ -59,10 +59,19 @@
     2.4  main.opt.dotoutput=\
     2.5  \  -dotoutput <dir>                   Destination directory for DOT file output
     2.6  
     2.7 +main.opt.jdkinternals=\
     2.8 +\  -jdkinternals                      Finds class-level dependences on JDK internal APIs.\n\
     2.9 +\                                     By default, it analyzes all classes on -classpath\n\
    2.10 +\                                     and input files unless -include option is specified.\n\
    2.11 +\                                     This option cannot be used with -p, -e and -s options.\n\
    2.12 +\                                     WARNING: JDK internal APIs may not be accessible in\n\
    2.13 +\                                     the next release.
    2.14 +
    2.15  main.opt.depth=\
    2.16  \  -depth=<depth>                     Specify the depth of the transitive\n\
    2.17  \                                     dependency analysis
    2.18  
    2.19 +
    2.20  err.unknown.option=unknown option: {0}
    2.21  err.missing.arg=no value given for {0}
    2.22  err.internal.error=internal error: {0} {1} {2}
     3.1 --- a/test/tools/jdeps/APIDeps.java	Tue Dec 03 23:10:23 2013 -0800
     3.2 +++ b/test/tools/jdeps/APIDeps.java	Wed Dec 04 15:39:36 2013 -0800
     3.3 @@ -23,8 +23,8 @@
     3.4  
     3.5  /*
     3.6   * @test
     3.7 - * @bug 8015912
     3.8 - * @summary find API dependencies
     3.9 + * @bug 8015912 8029216
    3.10 + * @summary Test -apionly and -jdkinternals options
    3.11   * @build m.Bar m.Foo m.Gee b.B c.C c.I d.D e.E f.F g.G
    3.12   * @run main APIDeps
    3.13   */
    3.14 @@ -88,6 +88,19 @@
    3.15               new String[] {"g.G", "sun.misc.Lock"},
    3.16               new String[] {testDirBasename, "JDK internal API"},
    3.17               new String[] {"-classpath", testDir.getPath(), "-verbose"});
    3.18 +
    3.19 +        // -jdkinternals
    3.20 +        test(new File(mDir, "Gee.class"),
    3.21 +             new String[] {"sun.misc.Lock"},
    3.22 +             new String[] {"JDK internal API"},
    3.23 +             new String[] {"-jdkinternals"});
    3.24 +        // -jdkinternals parses all classes on -classpath and the input arguments
    3.25 +        test(new File(mDir, "Gee.class"),
    3.26 +             new String[] {"sun.misc.Lock", "sun.misc.Unsafe"},
    3.27 +             new String[] {"JDK internal API"},
    3.28 +             new String[] {"-classpath", testDir.getPath(), "-jdkinternals"});
    3.29 +
    3.30 +        // parse only APIs
    3.31          // parse only APIs
    3.32          test(mDir,
    3.33               new String[] {"java.lang.Object", "java.lang.String",

mercurial