changeset 2213:4a2ed1900428

8029216: (jdeps) Provide a specific option to report JDK internal APIs Reviewed-by: alanb
author mchung
date Wed, 04 Dec 2013 15:39:36 -0800
parents 1b69023743be
children b3d7e86a0647
files src/share/classes/com/sun/tools/jdeps/JdepsTask.java src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties test/tools/jdeps/APIDeps.java
diffstat 3 files changed, 59 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java	Tue Dec 03 23:10:23 2013 -0800
+++ b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java	Wed Dec 04 15:39:36 2013 -0800
@@ -180,6 +180,15 @@
                 task.options.depth = 0;
             }
         },
+        new Option(false, "-jdkinternals") {
+            void process(JdepsTask task, String opt, String arg) {
+                task.options.findJDKInternals = true;
+                task.options.verbose = Analyzer.Type.CLASS;
+                if (task.options.includePattern == null) {
+                    task.options.includePattern = Pattern.compile(".*");
+                }
+            }
+        },
         new Option(false, "-version") {
             void process(JdepsTask task, String opt, String arg) {
                 task.options.version = true;
@@ -248,6 +257,11 @@
                 showHelp();
                 return EXIT_CMDERR;
             }
+            if (options.findJDKInternals &&
+                   (options.regex != null || options.packageNames.size() > 0 || options.showSummary)) {
+                showHelp();
+                return EXIT_CMDERR;
+            }
             if (options.showSummary && options.verbose != Analyzer.Type.SUMMARY) {
                 showHelp();
                 return EXIT_CMDERR;
@@ -571,6 +585,7 @@
         boolean wildcard;
         boolean apiOnly;
         boolean showLabel;
+        boolean findJDKInternals;
         String dotOutputDir;
         String classpath = "";
         int depth = 1;
@@ -681,11 +696,22 @@
         @Override
         public void visitDependence(String origin, Archive source,
                                     String target, Archive archive, Profile profile) {
-            if (!origin.equals(pkg)) {
-                pkg = origin;
-                writer.format("   %s (%s)%n", origin, source.getFileName());
+            if (options.findJDKInternals &&
+                    !(archive instanceof JDKArchive && profile == null)) {
+                // filter dependences other than JDK internal APIs
+                return;
             }
-            writer.format("      -> %-50s %s%n", target, getProfileArchiveInfo(archive, profile));
+            if (options.verbose == Analyzer.Type.VERBOSE) {
+                writer.format("   %-50s -> %-50s %s%n",
+                              origin, target, getProfileArchiveInfo(archive, profile));
+            } else {
+                if (!origin.equals(pkg)) {
+                    pkg = origin;
+                    writer.format("   %s (%s)%n", origin, source.getFileName());
+                }
+                writer.format("      -> %-50s %s%n",
+                              target, getProfileArchiveInfo(archive, profile));
+            }
         }
 
         @Override
@@ -717,6 +743,11 @@
         @Override
         public void visitDependence(String origin, Archive source,
                                     String target, Archive archive, Profile profile) {
+            if (options.findJDKInternals &&
+                    !(archive instanceof JDKArchive && profile == null)) {
+                // filter dependences other than JDK internal APIs
+                return;
+            }
             // if -P option is specified, package name -> profile will
             // be shown and filter out multiple same edges.
             String name = getProfileArchiveInfo(archive, profile);
--- a/src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Tue Dec 03 23:10:23 2013 -0800
+++ b/src/share/classes/com/sun/tools/jdeps/resources/jdeps.properties	Wed Dec 04 15:39:36 2013 -0800
@@ -59,10 +59,19 @@
 main.opt.dotoutput=\
 \  -dotoutput <dir>                   Destination directory for DOT file output
 
+main.opt.jdkinternals=\
+\  -jdkinternals                      Finds class-level dependences on JDK internal APIs.\n\
+\                                     By default, it analyzes all classes on -classpath\n\
+\                                     and input files unless -include option is specified.\n\
+\                                     This option cannot be used with -p, -e and -s options.\n\
+\                                     WARNING: JDK internal APIs may not be accessible in\n\
+\                                     the next release.
+
 main.opt.depth=\
 \  -depth=<depth>                     Specify the depth of the transitive\n\
 \                                     dependency analysis
 
+
 err.unknown.option=unknown option: {0}
 err.missing.arg=no value given for {0}
 err.internal.error=internal error: {0} {1} {2}
--- a/test/tools/jdeps/APIDeps.java	Tue Dec 03 23:10:23 2013 -0800
+++ b/test/tools/jdeps/APIDeps.java	Wed Dec 04 15:39:36 2013 -0800
@@ -23,8 +23,8 @@
 
 /*
  * @test
- * @bug 8015912
- * @summary find API dependencies
+ * @bug 8015912 8029216
+ * @summary Test -apionly and -jdkinternals options
  * @build m.Bar m.Foo m.Gee b.B c.C c.I d.D e.E f.F g.G
  * @run main APIDeps
  */
@@ -88,6 +88,19 @@
              new String[] {"g.G", "sun.misc.Lock"},
              new String[] {testDirBasename, "JDK internal API"},
              new String[] {"-classpath", testDir.getPath(), "-verbose"});
+
+        // -jdkinternals
+        test(new File(mDir, "Gee.class"),
+             new String[] {"sun.misc.Lock"},
+             new String[] {"JDK internal API"},
+             new String[] {"-jdkinternals"});
+        // -jdkinternals parses all classes on -classpath and the input arguments
+        test(new File(mDir, "Gee.class"),
+             new String[] {"sun.misc.Lock", "sun.misc.Unsafe"},
+             new String[] {"JDK internal API"},
+             new String[] {"-classpath", testDir.getPath(), "-jdkinternals"});
+
+        // parse only APIs
         // parse only APIs
         test(mDir,
              new String[] {"java.lang.Object", "java.lang.String",