test/tools/jdeps/Basic.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562 8005428
  27  * @summary Basic tests for jdeps tool
  28  * @build Test p.Foo
  29  * @run main Basic
  30  */
  31 
  32 import java.io.File;
  33 import java.io.IOException;
  34 import java.io.PrintWriter;
  35 import java.io.StringWriter;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.util.*;
  39 import java.util.regex.*;
  40 
  41 public class Basic {
  42     private static boolean symbolFileExist = initProfiles();
  43     private static boolean initProfiles() {
  44         // check if ct.sym exists; if not use the profiles.properties file
  45         Path home = Paths.get(System.getProperty("java.home"));
  46         if (home.endsWith("jre")) {


  62 
  63     public static void main(String... args) throws Exception {
  64         int errors = 0;
  65         errors += new Basic().run();
  66         if (errors > 0)
  67             throw new Exception(errors + " errors found");
  68     }
  69 
  70     int run() throws IOException {
  71         File testDir = new File(System.getProperty("test.classes", "."));
  72         // test a .class file
  73         test(new File(testDir, "Test.class"),
  74              new String[] {"java.lang", "p"},
  75              new String[] {"compact1", "not found"});
  76         // test a directory
  77         test(new File(testDir, "p"),
  78              new String[] {"java.lang", "java.util", "java.lang.management"},
  79              new String[] {"compact1", "compact1", "compact3"});
  80         // test class-level dependency output
  81         test(new File(testDir, "Test.class"),
  82              new String[] {"java.lang.Object", "p.Foo"},
  83              new String[] {"compact1", "not found"},
  84              new String[] {"-V", "class"});
  85         // test -p option
  86         test(new File(testDir, "Test.class"),
  87              new String[] {"p.Foo"},
  88              new String[] {"not found"},
  89              new String[] {"--verbose-level=class", "-p", "p"});
  90         // test -e option
  91         test(new File(testDir, "Test.class"),
  92              new String[] {"p.Foo"},
  93              new String[] {"not found"},
  94              new String[] {"-V", "class", "-e", "p\\..*"});
  95         test(new File(testDir, "Test.class"),
  96              new String[] {"java.lang"},
  97              new String[] {"compact1"},
  98              new String[] {"-V", "package", "-e", "java\\.lang\\..*"});
  99         // test -classpath and wildcard options
 100         test(null,
 101              new String[] {"com.sun.tools.jdeps", "java.lang", "java.util",
 102                            "java.util.regex", "java.io", "java.nio.file",
 103                            "java.lang.management"},
 104              new String[] {(symbolFileExist? "not found" : "JDK internal API (classes)"),
 105                            "compact1", "compact1", "compact1",
 106                            "compact1", "compact1", "compact3"},
 107              new String[] {"--classpath", testDir.getPath(), "*"});
 108         /* Temporary disable this test case.  Test.class has a dependency
 109          * on java.lang.String on certain windows machine (8008479).
 110          // -v shows intra-dependency
 111          test(new File(testDir, "Test.class"),
 112               new String[] {"java.lang.Object", "p.Foo"},
 113               new String[] {"compact1", testDir.getName()},
 114               new String[] {"-v", "--classpath", testDir.getPath(), "Test.class"});
 115         */
 116         return errors;
 117     }
 118 
 119     void test(File file, String[] expect, String[] profiles) {
 120         test(file, expect, profiles, new String[0]);
 121     }
 122 
 123     void test(File file, String[] expect, String[] profiles, String[] options) {
 124         List<String> args = new ArrayList<>(Arrays.asList(options));
 125         if (file != null) {
 126             args.add(file.getPath());
 127         }
 128         List<String> argsWithDashP = new ArrayList<>();
 129         argsWithDashP.add("-P");
 130         argsWithDashP.addAll(args);
 131         // test without -P
 132         checkResult("dependencies", expect, jdeps(args.toArray(new String[0])).keySet());
 133         // test with -P
 134         checkResult("profiles", expect, profiles, jdeps(argsWithDashP.toArray(new String[0])));
 135     }




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8003562 8005428 8015912
  27  * @summary Basic tests for jdeps tool
  28  * @build Test p.Foo
  29  * @run main Basic
  30  */
  31 
  32 import java.io.File;
  33 import java.io.IOException;
  34 import java.io.PrintWriter;
  35 import java.io.StringWriter;
  36 import java.nio.file.Path;
  37 import java.nio.file.Paths;
  38 import java.util.*;
  39 import java.util.regex.*;
  40 
  41 public class Basic {
  42     private static boolean symbolFileExist = initProfiles();
  43     private static boolean initProfiles() {
  44         // check if ct.sym exists; if not use the profiles.properties file
  45         Path home = Paths.get(System.getProperty("java.home"));
  46         if (home.endsWith("jre")) {


  62 
  63     public static void main(String... args) throws Exception {
  64         int errors = 0;
  65         errors += new Basic().run();
  66         if (errors > 0)
  67             throw new Exception(errors + " errors found");
  68     }
  69 
  70     int run() throws IOException {
  71         File testDir = new File(System.getProperty("test.classes", "."));
  72         // test a .class file
  73         test(new File(testDir, "Test.class"),
  74              new String[] {"java.lang", "p"},
  75              new String[] {"compact1", "not found"});
  76         // test a directory
  77         test(new File(testDir, "p"),
  78              new String[] {"java.lang", "java.util", "java.lang.management"},
  79              new String[] {"compact1", "compact1", "compact3"});
  80         // test class-level dependency output
  81         test(new File(testDir, "Test.class"),
  82              new String[] {"java.lang.Object", "java.lang.String", "p.Foo"},
  83              new String[] {"compact1", "compact1", "not found"},
  84              new String[] {"-verbose:class"});
  85         // test -p option
  86         test(new File(testDir, "Test.class"),
  87              new String[] {"p.Foo"},
  88              new String[] {"not found"},
  89              new String[] {"-verbose:class", "-p", "p"});
  90         // test -e option
  91         test(new File(testDir, "Test.class"),
  92              new String[] {"p.Foo"},
  93              new String[] {"not found"},
  94              new String[] {"-verbose:class", "-e", "p\\..*"});
  95         test(new File(testDir, "Test.class"),
  96              new String[] {"java.lang"},
  97              new String[] {"compact1"},
  98              new String[] {"-verbose:package", "-e", "java\\.lang\\..*"});
  99         // test -classpath and -include options
 100         test(null,
 101              new String[] {"java.lang", "java.util",

 102                            "java.lang.management"},
 103              new String[] {"compact1", "compact1", "compact3"},
 104              new String[] {"-classpath", testDir.getPath(), "-include", "p.+|Test.class"});
 105         test(new File(testDir, "Test.class"),
 106              new String[] {"java.lang.Object", "java.lang.String", "p.Foo"},
 107              new String[] {"compact1", "compact1", testDir.getName()},
 108              new String[] {"-v", "-classpath", testDir.getPath(), "Test.class"});






 109         return errors;
 110     }
 111 
 112     void test(File file, String[] expect, String[] profiles) {
 113         test(file, expect, profiles, new String[0]);
 114     }
 115 
 116     void test(File file, String[] expect, String[] profiles, String[] options) {
 117         List<String> args = new ArrayList<>(Arrays.asList(options));
 118         if (file != null) {
 119             args.add(file.getPath());
 120         }
 121         List<String> argsWithDashP = new ArrayList<>();
 122         argsWithDashP.add("-P");
 123         argsWithDashP.addAll(args);
 124         // test without -P
 125         checkResult("dependencies", expect, jdeps(args.toArray(new String[0])).keySet());
 126         // test with -P
 127         checkResult("profiles", expect, profiles, jdeps(argsWithDashP.toArray(new String[0])));
 128     }