< prev index next >

test/langtools/tools/jdeps/listdeps/ListModuleDeps.java

Print this page

        

@@ -33,13 +33,15 @@
  * @library ../lib
  * @build CompilerUtils JdepsRunner
  * @run testng ListModuleDeps
  */
 
+import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
+import java.util.List;
 import java.util.stream.Collectors;
 
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;

@@ -51,10 +53,11 @@
     private static final String TEST_SRC = System.getProperty("test.src");
 
     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
     private static final Path CLASSES_DIR = Paths.get("classes");
     private static final Path LIB_DIR = Paths.get("lib");
+    private static final Path LIB2_DIR = Paths.get("lib2");
 
     private static final Path HI_CLASS =
         CLASSES_DIR.resolve("hi").resolve("Hi.class");
     private static final Path FOO_CLASS =
         CLASSES_DIR.resolve("z").resolve("Foo.class");

@@ -67,11 +70,12 @@
      * Compiles classes used by the test
      */
     @BeforeTest
     public void compileAll() throws Exception {
         // compile library
-        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib"), LIB_DIR));
+        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib2"), LIB2_DIR));
+        assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "lib"), LIB_DIR, "-cp", LIB2_DIR.toString()));
 
         // simple program depends only on java.base
         assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "hi"), CLASSES_DIR));
 
         // compile classes in unnamed module

@@ -109,11 +113,11 @@
     }
 
     @Test(dataProvider = "listdeps")
     public void testListDeps(Path classes, String[] expected) {
         JdepsRunner jdeps = JdepsRunner.run(
-            "--class-path", LIB_DIR.toString(),
+            "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
             "--list-deps", classes.toString()
         );
         String[] output = Arrays.stream(jdeps.output())
                                 .map(s -> s.trim())
                                 .toArray(String[]::new);

@@ -121,11 +125,11 @@
     }
 
     @Test(dataProvider = "reduceddeps")
     public void testListReducedDeps(Path classes, String[]  expected) {
         JdepsRunner jdeps = JdepsRunner.run(
-            "--class-path", LIB_DIR.toString(),
+            "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
             "--list-reduced-deps", classes.toString()
         );
         String[] output = Arrays.stream(jdeps.output())
                                 .map(s -> s.trim())
                                 .toArray(String[]::new);

@@ -138,10 +142,11 @@
         return new Object[][] {
             { CLASSES_DIR,  new String[] {
                                 "java.base/jdk.internal.misc",
                                 "java.base/sun.security.util",
                                 "java.logging",
+                                "java.management",
                                 "java.sql",
                                 "java.xml/jdk.xml.internal",
                                 "jdk.unsupported"
                             }
             },

@@ -152,10 +157,11 @@
             },
 
             { FOO_CLASS,    new String[] {
                                 "java.base",
                                 "java.logging",
+                                "java.management",
                                 "java.sql",
                                 "java.xml"
                             }
             },
 

@@ -179,10 +185,11 @@
 
         return new Object[][] {
             { CLASSES_DIR,  new String[] {
                                 "java.base/jdk.internal.misc",
                                 "java.base/sun.security.util",
+                                "java.management",
                                 "java.sql",
                                 "java.xml/jdk.xml.internal",
                                 "jdk.unsupported"
                             }
             },

@@ -192,10 +199,11 @@
                             }
             },
 
             { FOO_CLASS,    new String[] {
                                 "java.base",
+                                "java.management",
                                 "java.sql"
                             }
             },
 
             { BAR_CLASS,    new String[] {

@@ -213,11 +221,11 @@
     }
 
     @Test(dataProvider = "moduledeps")
     public void testPrintModuleDeps(Path classes, String expected) {
         JdepsRunner jdeps = JdepsRunner.run(
-            "--class-path", LIB_DIR.toString(),
+            "--class-path", LIB_DIR.toString() + File.pathSeparator + LIB2_DIR.toString(),
             "--print-module-deps", classes.toString()
         );
         String output = Arrays.stream(jdeps.output())
             .map(s -> s.trim())
             .collect(Collectors.joining(","));

@@ -229,13 +237,56 @@
     public Object[][] moduledeps() {
         Path barClass = CLASSES_DIR.resolve("z").resolve("Bar.class");
 
         return new Object[][] {
             // java.xml is an implied reads edge from java.sql
-            { CLASSES_DIR,  "java.base,java.sql,jdk.unsupported"},
+            { CLASSES_DIR,  "java.base,java.management,java.sql,jdk.unsupported"},
             { HI_CLASS,     "java.base"},
-            { FOO_CLASS,    "java.base,java.sql"},
+            { FOO_CLASS,    "java.base,java.management,java.sql"},
             { BAR_CLASS,    "java.base,java.xml"},
             { UNSAFE_CLASS, "java.base,jdk.unsupported"},
         };
     }
+
+    @DataProvider(name = "recursiveDeps")
+    public Object[][] recursiveDeps() {
+        return new Object[][] {
+            {   // lib2 is classpath but not analyzed because lib.Lib is not present
+                // but it is the only class depending on lib2.Lib2
+                List.of("--list-deps", "--class-path", LIB2_DIR.toString(),
+                        "--ignore-missing-deps", CLASSES_DIR.toString()),
+                new String[] {
+                    "java.base/jdk.internal.misc",
+                    "java.base/sun.security.util",
+                    "java.logging",
+                    "java.sql",
+                    "java.xml/jdk.xml.internal",
+                    "jdk.unsupported"
+                }
+            },
+            {   // lib2 is classpath but not analyzed because lib.Lib is not present
+                // but it is the only class depending on lib2.Lib2
+                List.of("--print-module-deps", "--class-path", LIB2_DIR.toString(),
+                        "--ignore-missing-deps", CLASSES_DIR.toString()),
+                new String[] {
+                    "java.base,java.sql,jdk.unsupported"
+                }
+            },
+            {   // Foo depends on lib.Lib which depends on lib2.Libs
+                List.of("--print-module-deps",
+                        "--ignore-missing-deps", FOO_CLASS.toString()),
+                new String[] {
+                    "java.base,java.sql"
+                }
+            },
+        };
+    }
+
+    @Test(dataProvider = "recursiveDeps")
+    public void testRecursiveDeps(List<String> options, String[] expected) {
+        JdepsRunner jdeps = JdepsRunner.run(options.toArray(new String[0]));
+        String[] output = Arrays.stream(jdeps.output())
+                                .map(s -> s.trim())
+                                .toArray(String[]::new);
+        assertEquals(output, expected);
+    }
 }
< prev index next >