68 // compile com.sun.image.codec.jpeg types 69 Path codecSrc = Paths.get(TEST_SRC, "patches", "java.desktop"); 70 Path codecDest = PATCHES_DIR; 71 assertTrue(CompilerUtils.compile(codecSrc, codecDest)); 72 73 // patch jdk.unsupported and set -cp to codec types 74 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "p"), 75 CLASSES_DIR, 76 "--patch-module", "jdk.unsupported=" + patchDir, 77 "-cp", codecDest.toString())); 78 } 79 80 @DataProvider(name = "deps") 81 public Object[][] deps() { 82 return new Object[][] { 83 { "classes", new ModuleMetaData("classes", false) 84 .reference("p.Main", "java.lang.Class", "java.base") 85 .reference("p.Main", "java.lang.Object", "java.base") 86 .reference("p.Main", "java.util.Iterator", "java.base") 87 .reference("p.S", "java.lang.Object", "java.base") 88 .jdkInternal("p.Main", "sun.reflect.Reflection", "jdk.unsupported") 89 .removedJdkInternal("p.Main", "com.sun.image.codec.jpeg.JPEGCodec") 90 .removedJdkInternal("p.Main", "sun.misc.Service") 91 .removedJdkInternal("p.Main", "sun.misc.SoftCache") 92 }, 93 }; 94 } 95 96 @Test(dataProvider = "deps") 97 public void runTest(String name, ModuleMetaData data) throws Exception { 98 String cmd = String.format("jdeps -verbose:class %s%n", CLASSES_DIR); 99 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { 100 jdeps.verbose("-verbose:class") 101 .addRoot(CLASSES_DIR); 102 103 DepsAnalyzer analyzer = jdeps.getDepsAnalyzer(); 104 assertTrue(analyzer.run()); 105 jdeps.dumpOutput(System.err); 106 107 Graph<DepsAnalyzer.Node> g = analyzer.dependenceGraph(); 108 // there are two node with p.Main as origin 109 // one for exported API and one for removed JDK internal 110 g.nodes().stream() 111 .filter(u -> u.source.equals(data.moduleName)) 112 .forEach(u -> g.adjacentNodes(u).stream() 113 .forEach(v -> data.checkDependence(u.name, v.name, v.source, v.info))); 114 } 115 } 116 117 private static final Map<String, String> REPLACEMENTS = Map.of( 118 "com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4", 119 "sun.misc.Service", "Use java.util.ServiceLoader @since 1.6", 120 "sun.misc.SoftCache", "Removed. See http://openjdk.java.net/jeps/260", 121 "sun.reflect.Reflection", "Use java.lang.StackWalker @since 9" 122 ); 123 124 @Test 125 public void checkReplacement() { 126 JdepsRunner jdeps = JdepsRunner.run("-jdkinternals", CLASSES_DIR.toString()); 127 String[] output = jdeps.output(); 128 int i = 0; 129 while (!output[i].contains("Suggested Replacement")) { 130 i++; 131 } 132 133 // must match the number of JDK internal APIs 134 int count = output.length-i-2; 135 assertEquals(count, REPLACEMENTS.size()); 136 137 for (int j=i+2; j < output.length; j++) { 138 String line = output[j]; 139 int pos = line.indexOf("Use "); 140 if (pos < 0) 141 pos = line.indexOf("Removed. "); 142 143 assertTrue(pos > 0); 144 String name = line.substring(0, pos).trim(); 145 String repl = line.substring(pos, line.length()).trim(); 146 assertEquals(REPLACEMENTS.get(name), repl); 147 } 148 } 149 } | 68 // compile com.sun.image.codec.jpeg types 69 Path codecSrc = Paths.get(TEST_SRC, "patches", "java.desktop"); 70 Path codecDest = PATCHES_DIR; 71 assertTrue(CompilerUtils.compile(codecSrc, codecDest)); 72 73 // patch jdk.unsupported and set -cp to codec types 74 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "src", "p"), 75 CLASSES_DIR, 76 "--patch-module", "jdk.unsupported=" + patchDir, 77 "-cp", codecDest.toString())); 78 } 79 80 @DataProvider(name = "deps") 81 public Object[][] deps() { 82 return new Object[][] { 83 { "classes", new ModuleMetaData("classes", false) 84 .reference("p.Main", "java.lang.Class", "java.base") 85 .reference("p.Main", "java.lang.Object", "java.base") 86 .reference("p.Main", "java.util.Iterator", "java.base") 87 .reference("p.S", "java.lang.Object", "java.base") 88 .jdkInternal("p.Main", "sun.reflect.ReflectionFactory", "jdk.unsupported") 89 .removedJdkInternal("p.Main", "sun.reflect.Reflection") 90 .removedJdkInternal("p.Main", "com.sun.image.codec.jpeg.JPEGCodec") 91 .removedJdkInternal("p.Main", "sun.misc.Service") 92 .removedJdkInternal("p.Main", "sun.misc.SoftCache") 93 }, 94 }; 95 } 96 97 @Test(dataProvider = "deps") 98 public void runTest(String name, ModuleMetaData data) throws Exception { 99 String cmd = String.format("jdeps -verbose:class %s%n", CLASSES_DIR); 100 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { 101 jdeps.verbose("-verbose:class") 102 .addRoot(CLASSES_DIR); 103 104 DepsAnalyzer analyzer = jdeps.getDepsAnalyzer(); 105 assertTrue(analyzer.run()); 106 jdeps.dumpOutput(System.err); 107 108 Graph<DepsAnalyzer.Node> g = analyzer.dependenceGraph(); 109 // there are two node with p.Main as origin 110 // one for exported API and one for removed JDK internal 111 g.nodes().stream() 112 .filter(u -> u.source.equals(data.moduleName)) 113 .forEach(u -> g.adjacentNodes(u).stream() 114 .forEach(v -> data.checkDependence(u.name, v.name, v.source, v.info))); 115 } 116 } 117 118 private static final Map<String, String> REPLACEMENTS = Map.of( 119 "com.sun.image.codec.jpeg.JPEGCodec", "Use javax.imageio @since 1.4", 120 "sun.misc.Service", "Use java.util.ServiceLoader @since 1.6", 121 "sun.misc.SoftCache", "Removed. See http://openjdk.java.net/jeps/260", 122 "sun.reflect.Reflection", "Use java.lang.StackWalker @since 9", 123 "sun.reflect.ReflectionFactory", "See http://openjdk.java.net/jeps/260" 124 ); 125 126 @Test 127 public void checkReplacement() { 128 JdepsRunner jdeps = JdepsRunner.run("-jdkinternals", CLASSES_DIR.toString()); 129 String[] output = jdeps.output(); 130 int i = 0; 131 while (!output[i].contains("Suggested Replacement")) { 132 i++; 133 } 134 135 // must match the number of JDK internal APIs 136 int count = output.length-i-2; 137 assertEquals(count, REPLACEMENTS.size()); 138 139 for (int j=i+2; j < output.length; j++) { 140 String line = output[j]; 141 int pos = line.indexOf("Use "); 142 if (pos < 0) 143 pos = line.indexOf("Removed. "); 144 if (pos < 0) 145 pos = line.indexOf("See "); 146 147 assertTrue(pos > 0); 148 String name = line.substring(0, pos).trim(); 149 String repl = line.substring(pos, line.length()).trim(); 150 assertEquals(REPLACEMENTS.get(name), repl); 151 } 152 } 153 } |