< prev index next >
test/jdk/tools/jlink/plugins/SystemModuleDescriptors/src/m4/p4/Main.java
Print this page
rev 47454 : [mq]: jdk-new-asm-test.patch
*** 33,73 ****
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
! import jdk.internal.module.ClassFileAttributes;
! import jdk.internal.module.ClassFileAttributes.ModuleTargetAttribute;
! import jdk.internal.module.ClassFileConstants;
! import jdk.internal.org.objectweb.asm.Attribute;
! import jdk.internal.org.objectweb.asm.ClassReader;
! import jdk.internal.org.objectweb.asm.ClassVisitor;
! import jdk.internal.org.objectweb.asm.Opcodes;
public class Main {
private static boolean hasModuleTarget(InputStream in) throws IOException {
! ModuleTargetAttribute[] modTargets = new ModuleTargetAttribute[1];
! ClassVisitor cv = new ClassVisitor(Opcodes.ASM5) {
! @Override
! public void visitAttribute(Attribute attr) {
! if (attr instanceof ModuleTargetAttribute) {
! modTargets[0] = (ModuleTargetAttribute)attr;
}
- }
- };
- // prototype of attributes that should be parsed
- Attribute[] attrs = new Attribute[] {
- new ModuleTargetAttribute()
- };
-
- // parse module-info.class
- ClassReader cr = new ClassReader(in);
- cr.accept(cv, attrs, 0);
- return modTargets[0] != null && modTargets[0].targetPlatform() != null;
- }
-
private static boolean hasModuleTarget(String modName) throws IOException {
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Map.of());
Path path = fs.getPath("/", "modules", modName, "module-info.class");
try (InputStream in = Files.newInputStream(path)) {
return hasModuleTarget(in);
--- 33,51 ----
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
! import jdk.internal.module.ModuleInfo;
! import jdk.internal.module.ModuleInfo.Attributes;
public class Main {
private static boolean hasModuleTarget(InputStream in) throws IOException {
! ModuleInfo.Attributes attrs = ModuleInfo.read(in, null);
! return attrs.target() != null;
}
private static boolean hasModuleTarget(String modName) throws IOException {
FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Map.of());
Path path = fs.getPath("/", "modules", modName, "module-info.class");
try (InputStream in = Files.newInputStream(path)) {
return hasModuleTarget(in);
< prev index next >