48 public class SplitPackage { 49 private static final String TEST_SRC = System.getProperty("test.src"); 50 51 private static final Path CLASSES_DIR = Paths.get("classes"); 52 53 private static final String SPLIT_PKG_NAME = "javax.annotation"; 54 private static final String JAVA_ANNOTATIONS_COMMON = "java.annotations.common"; 55 /** 56 * Compiles classes used by the test 57 */ 58 @BeforeTest 59 public void compileAll() throws Exception { 60 CompilerUtils.cleanDir(CLASSES_DIR); 61 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "patches"), CLASSES_DIR)); 62 } 63 64 @Test 65 public void runTest() throws Exception { 66 // Test jdeps classes 67 runTest(null); 68 // Test jdeps -addmods 69 runTest(JAVA_ANNOTATIONS_COMMON, SPLIT_PKG_NAME); 70 } 71 72 private void runTest(String root, String... splitPackages) throws Exception { 73 String cmd = String.format("jdeps -verbose:class -addmods %s %s%n", 74 root, CLASSES_DIR); 75 76 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { 77 jdeps.verbose("-verbose:class") 78 .addRoot(CLASSES_DIR); 79 if (root != null) 80 jdeps.addmods(Set.of(root)); 81 82 JdepsConfiguration config = jdeps.configuration(); 83 Map<String, Set<String>> pkgs = config.splitPackages(); 84 85 final Set<String> expected; 86 if (splitPackages != null) { 87 expected = Arrays.stream(splitPackages).collect(Collectors.toSet()); 88 } else { 89 expected = Collections.emptySet(); 90 } 91 92 if (!pkgs.keySet().equals(expected)) { 93 throw new RuntimeException(splitPackages.toString()); | 48 public class SplitPackage { 49 private static final String TEST_SRC = System.getProperty("test.src"); 50 51 private static final Path CLASSES_DIR = Paths.get("classes"); 52 53 private static final String SPLIT_PKG_NAME = "javax.annotation"; 54 private static final String JAVA_ANNOTATIONS_COMMON = "java.annotations.common"; 55 /** 56 * Compiles classes used by the test 57 */ 58 @BeforeTest 59 public void compileAll() throws Exception { 60 CompilerUtils.cleanDir(CLASSES_DIR); 61 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "patches"), CLASSES_DIR)); 62 } 63 64 @Test 65 public void runTest() throws Exception { 66 // Test jdeps classes 67 runTest(null); 68 // Test jdeps --add-modules 69 runTest(JAVA_ANNOTATIONS_COMMON, SPLIT_PKG_NAME); 70 } 71 72 private void runTest(String root, String... splitPackages) throws Exception { 73 String cmd = String.format("jdeps -verbose:class --add-modules %s %s%n", 74 root, CLASSES_DIR); 75 76 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { 77 jdeps.verbose("-verbose:class") 78 .addRoot(CLASSES_DIR); 79 if (root != null) 80 jdeps.addmods(Set.of(root)); 81 82 JdepsConfiguration config = jdeps.configuration(); 83 Map<String, Set<String>> pkgs = config.splitPackages(); 84 85 final Set<String> expected; 86 if (splitPackages != null) { 87 expected = Arrays.stream(splitPackages).collect(Collectors.toSet()); 88 } else { 89 expected = Collections.emptySet(); 90 } 91 92 if (!pkgs.keySet().equals(expected)) { 93 throw new RuntimeException(splitPackages.toString()); |