44 import jdk.tools.jlink.internal.plugins.asm.AsmPool; |
44 import jdk.tools.jlink.internal.plugins.asm.AsmPool; |
45 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ClassReaderVisitor; |
45 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ClassReaderVisitor; |
46 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ResourceFile; |
46 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ResourceFile; |
47 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ResourceFileVisitor; |
47 import jdk.tools.jlink.internal.plugins.asm.AsmPool.ResourceFileVisitor; |
48 import jdk.tools.jlink.internal.plugins.asm.AsmPools; |
48 import jdk.tools.jlink.internal.plugins.asm.AsmPools; |
49 import jdk.tools.jlink.plugin.Pool; |
49 import jdk.tools.jlink.plugin.ModuleEntry; |
50 import jdk.tools.jlink.plugin.Pool.ModuleData; |
50 import jdk.tools.jlink.plugin.ModulePool; |
51 |
51 |
52 public class VisitorTest extends AsmPluginTestBase { |
52 public class VisitorTest extends AsmPluginTestBase { |
53 |
53 |
54 public static void main(String[] args) throws Exception { |
54 public static void main(String[] args) throws Exception { |
55 if (!isImageBuild()) { |
55 if (!isImageBuild()) { |
67 new ResourceVisitorPlugin("Resource-global-pool", AsmPools::getGlobalPool), |
67 new ResourceVisitorPlugin("Resource-global-pool", AsmPools::getGlobalPool), |
68 new ResourceVisitorPlugin("Resource-module-pool", pools -> pools.getModulePool("java.base")) |
68 new ResourceVisitorPlugin("Resource-module-pool", pools -> pools.getModulePool("java.base")) |
69 }; |
69 }; |
70 for (TestPlugin p : plugins) { |
70 for (TestPlugin p : plugins) { |
71 System.err.println("Testing: " + p.getName()); |
71 System.err.println("Testing: " + p.getName()); |
72 Pool out = p.visit(getPool()); |
72 ModulePool out = p.visit(getPool()); |
73 p.test(getPool(), out); |
73 p.test(getPool(), out); |
74 } |
74 } |
75 } |
75 } |
76 |
76 |
77 private static class CustomClassReaderVisitor implements ClassReaderVisitor { |
77 private static class CustomClassReaderVisitor implements ClassReaderVisitor { |
147 AsmPool pool = getPool.apply(getPools()); |
147 AsmPool pool = getPool.apply(getPools()); |
148 pool.visitClassReaders(classReaderVisitor); |
148 pool.visitClassReaders(classReaderVisitor); |
149 } |
149 } |
150 |
150 |
151 @Override |
151 @Override |
152 public void test(Pool in, Pool out) throws Exception { |
152 public void test(ModulePool in, ModulePool out) throws Exception { |
153 Collection<ModuleData> inClasses = getPool.apply(getPools()).getClasses(); |
153 Collection<ModuleEntry> inClasses = getPool.apply(getPools()).getClasses(); |
154 if (inClasses.size() != classReaderVisitor.getAmount()) { |
154 if (inClasses.size() != classReaderVisitor.getAmount()) { |
155 throw new AssertionError("Testing " + name + ". Number of visited classes. Expected: " + |
155 throw new AssertionError("Testing " + name + ". Number of visited classes. Expected: " + |
156 inClasses.size() + ", got: " + classReaderVisitor.getAmount()); |
156 inClasses.size() + ", got: " + classReaderVisitor.getAmount()); |
157 } |
157 } |
158 Collection<ModuleData> outClasses = extractClasses(out); |
158 Collection<ModuleEntry> outClasses = extractClasses(out); |
159 int changedClasses = 0; |
159 int changedClasses = 0; |
160 for (ModuleData r : outClasses) { |
160 for (ModuleEntry r : outClasses) { |
161 if (r.getPath().endsWith("Changed.class")) { |
161 if (r.getPath().endsWith("Changed.class")) { |
162 ++changedClasses; |
162 ++changedClasses; |
163 } |
163 } |
164 } |
164 } |
165 if (changedClasses != classReaderVisitor.getNumberOfChanged()) { |
165 if (changedClasses != classReaderVisitor.getNumberOfChanged()) { |
190 AsmPool pool = getPool.apply(getPools()); |
190 AsmPool pool = getPool.apply(getPools()); |
191 pool.visitResourceFiles(resourceFileVisitor); |
191 pool.visitResourceFiles(resourceFileVisitor); |
192 } |
192 } |
193 |
193 |
194 @Override |
194 @Override |
195 public void test(Pool in, Pool out) throws Exception { |
195 public void test(ModulePool in, ModulePool out) throws Exception { |
196 Collection<ModuleData> inResources = getPool.apply(getPools()).getResourceFiles(); |
196 Collection<ModuleEntry> inResources = getPool.apply(getPools()).getResourceFiles(); |
197 if (inResources.size() != resourceFileVisitor.getAmount()) { |
197 if (inResources.size() != resourceFileVisitor.getAmount()) { |
198 throw new AssertionError("Testing " + name + ". Number of visited resources. Expected: " + |
198 throw new AssertionError("Testing " + name + ". Number of visited resources. Expected: " + |
199 inResources.size() + ", got: " + resourceFileVisitor.getAmount()); |
199 inResources.size() + ", got: " + resourceFileVisitor.getAmount()); |
200 } |
200 } |
201 Collection<ModuleData> outResources = extractResources(out); |
201 Collection<ModuleEntry> outResources = extractResources(out); |
202 int changedClasses = 0; |
202 int changedClasses = 0; |
203 for (ModuleData r : outResources) { |
203 for (ModuleEntry r : outResources) { |
204 if (r.getPath().endsWith("Changed")) { |
204 if (r.getPath().endsWith("Changed")) { |
205 ++changedClasses; |
205 ++changedClasses; |
206 } |
206 } |
207 } |
207 } |
208 if (changedClasses != resourceFileVisitor.getNumberOfChanged()) { |
208 if (changedClasses != resourceFileVisitor.getNumberOfChanged()) { |