< 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


  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package p4;
  25 
  26 import java.io.IOException;
  27 import java.io.InputStream;
  28 import java.lang.module.ModuleDescriptor;
  29 import java.lang.module.ModuleFinder;
  30 import java.net.URI;
  31 import java.nio.file.FileSystem;
  32 import java.nio.file.FileSystems;
  33 import java.nio.file.Files;
  34 import java.nio.file.Path;
  35 import java.util.Map;
  36 import java.util.Set;
  37 
  38 import jdk.internal.module.ClassFileAttributes;
  39 import jdk.internal.module.ClassFileAttributes.ModuleTargetAttribute;
  40 import jdk.internal.module.ClassFileConstants;
  41 import jdk.internal.org.objectweb.asm.Attribute;
  42 import jdk.internal.org.objectweb.asm.ClassReader;
  43 import jdk.internal.org.objectweb.asm.ClassVisitor;
  44 import jdk.internal.org.objectweb.asm.Opcodes;
  45 
  46 public class Main {
  47     private static boolean hasModuleTarget(InputStream in) throws IOException {
  48         ModuleTargetAttribute[] modTargets = new ModuleTargetAttribute[1];
  49         ClassVisitor cv = new ClassVisitor(Opcodes.ASM5) {
  50             @Override
  51             public void visitAttribute(Attribute attr) {
  52                 if (attr instanceof ModuleTargetAttribute) {
  53                     modTargets[0] = (ModuleTargetAttribute)attr;
  54                 }
  55             }
  56         };
  57 
  58         // prototype of attributes that should be parsed
  59         Attribute[] attrs = new Attribute[] {
  60             new ModuleTargetAttribute()
  61         };
  62 
  63         // parse module-info.class
  64         ClassReader cr = new ClassReader(in);
  65         cr.accept(cv, attrs, 0);
  66         return modTargets[0] != null && modTargets[0].targetPlatform() != null;
  67     }
  68 
  69     private static boolean hasModuleTarget(String modName) throws IOException {
  70         FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Map.of());
  71         Path path = fs.getPath("/", "modules", modName, "module-info.class");
  72         try (InputStream in = Files.newInputStream(path)) {
  73             return hasModuleTarget(in);
  74         }
  75     }
  76 
  77     // the system module plugin by default drops ModuleTarget attribute
  78     private static boolean expectModuleTarget = false;
  79     public static void main(String... args) throws IOException {
  80         if (args.length > 0) {
  81             if (!args[0].equals("retainModuleTarget")) {
  82                 throw new IllegalArgumentException(args[0]);
  83             }
  84 
  85             expectModuleTarget = true;
  86         }
  87 
  88         // java.base is packaged with ModuleTarget




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package p4;
  25 
  26 import java.io.IOException;
  27 import java.io.InputStream;
  28 import java.lang.module.ModuleDescriptor;
  29 import java.lang.module.ModuleFinder;
  30 import java.net.URI;
  31 import java.nio.file.FileSystem;
  32 import java.nio.file.FileSystems;
  33 import java.nio.file.Files;
  34 import java.nio.file.Path;
  35 import java.util.Map;
  36 import java.util.Set;
  37 
  38 import jdk.internal.module.ModuleInfo;
  39 import jdk.internal.module.ModuleInfo.Attributes;





  40 
  41 public class Main {
  42     private static boolean hasModuleTarget(InputStream in) throws IOException {
  43         ModuleInfo.Attributes attrs = ModuleInfo.read(in, null);
  44         return attrs.target() != null;




  45     }


  46 











  47     private static boolean hasModuleTarget(String modName) throws IOException {
  48         FileSystem fs = FileSystems.newFileSystem(URI.create("jrt:/"), Map.of());
  49         Path path = fs.getPath("/", "modules", modName, "module-info.class");
  50         try (InputStream in = Files.newInputStream(path)) {
  51             return hasModuleTarget(in);
  52         }
  53     }
  54 
  55     // the system module plugin by default drops ModuleTarget attribute
  56     private static boolean expectModuleTarget = false;
  57     public static void main(String... args) throws IOException {
  58         if (args.length > 0) {
  59             if (!args[0].equals("retainModuleTarget")) {
  60                 throw new IllegalArgumentException(args[0]);
  61             }
  62 
  63             expectModuleTarget = true;
  64         }
  65 
  66         // java.base is packaged with ModuleTarget


< prev index next >