< prev index next >

jdk/test/tools/jlink/plugins/SystemModuleDescriptors/SystemModulesTest.java

Print this page




  54 
  55 public class SystemModulesTest {
  56     private static final JavaLangModuleAccess JLMA =
  57         SharedSecrets.getJavaLangModuleAccess();
  58     private static final String OS_NAME = System.getProperty("os.name");
  59     private static final String OS_ARCH = System.getProperty("os.arch");
  60     //  system modules containing no package
  61     private static final Set<String> EMPTY_MODULES =
  62         Set.of("java.se", "java.se.ee", "jdk.jdwp.agent", "jdk.pack");
  63 
  64     @Test
  65     public void testSystemModules() {
  66         Path jimage = Paths.get(System.getProperty("java.home"), "lib", "modules");
  67         if (Files.notExists(jimage))
  68             return;
  69 
  70         ModuleFinder.ofSystem().findAll().stream()
  71                     .forEach(this::checkAttributes);
  72     }
  73 
  74     // JMOD files are created with osName and osArch that may be different
  75     // than os.name and os.arch system property
  76     private boolean checkOSName(String name) {
  77         if (name.equals(OS_NAME))
  78             return true;
  79 
  80         if (OS_NAME.startsWith("Windows")) {
  81             return name.startsWith("Windows");
  82         } else {
  83             System.err.println("ERROR: " + name + " but expected: " + OS_NAME);
  84             return false;










  85         }
  86     }
  87 
  88     private boolean checkOSArch(String name) {
  89         if (name.equals(OS_ARCH))
  90             return true;
  91 
  92         switch (OS_ARCH) {
  93             case "i386":
  94             case "x86":
  95                 return name.equals("x86");
  96             case "amd64":
  97                 return name.equals("x86_64");


  98             default:
  99                 System.err.println("ERROR: " + name + " but expected: " + OS_ARCH);
 100                 return false;

 101         }
 102     }
 103 
 104     private void checkAttributes(ModuleReference modRef) {
 105         try {
 106             if (modRef.descriptor().name().equals("java.base")) {
 107                 ModuleTargetHelper.ModuleTarget mt = ModuleTargetHelper.read(modRef);
 108                 assertTrue(checkOSName(mt.osName()));
 109                 assertTrue(checkOSArch(mt.osArch()));
 110             } else {
 111                 // target platform attribute is dropped by jlink plugin for other modules
 112                 ModuleTargetHelper.ModuleTarget mt = ModuleTargetHelper.read(modRef);
 113                 assertTrue(mt == null || (mt.osName() == null && mt.osArch() == null));
 114             }
 115         } catch (IOException exp) {
 116             throw new UncheckedIOException(exp);
 117         }
 118     }
 119 
 120     /**




  54 
  55 public class SystemModulesTest {
  56     private static final JavaLangModuleAccess JLMA =
  57         SharedSecrets.getJavaLangModuleAccess();
  58     private static final String OS_NAME = System.getProperty("os.name");
  59     private static final String OS_ARCH = System.getProperty("os.arch");
  60     //  system modules containing no package
  61     private static final Set<String> EMPTY_MODULES =
  62         Set.of("java.se", "java.se.ee", "jdk.jdwp.agent", "jdk.pack");
  63 
  64     @Test
  65     public void testSystemModules() {
  66         Path jimage = Paths.get(System.getProperty("java.home"), "lib", "modules");
  67         if (Files.notExists(jimage))
  68             return;
  69 
  70         ModuleFinder.ofSystem().findAll().stream()
  71                     .forEach(this::checkAttributes);
  72     }
  73 
  74     // JMOD files are created with OS name and arch matching the bundle name

  75     private boolean checkOSName(String name) {



  76         if (OS_NAME.startsWith("Windows")) {
  77             return name.equals("windows");
  78         }
  79 
  80         switch (OS_NAME) {
  81             case "Linux":
  82                 return name.equals("linux");
  83             case "SunOS":
  84                 return name.equals("solaris");
  85             case "Mac OS X":
  86                 return name.equals("macos");
  87             default:
  88                 // skip validation on unknown platform
  89                 System.out.println("Skip checking OS name in ModuleTarget: " + name);
  90                 return true;
  91         }
  92     }
  93 
  94     private boolean checkOSArch(String name) {
  95         if (name.equals(OS_ARCH))
  96             return true;
  97 
  98         switch (OS_ARCH) {
  99             case "i386":
 100             case "x86":
 101                 return name.equals("x86");
 102             case "amd64":
 103             case "i586":
 104             case "x86_64":
 105                 return name.equals("amd64");
 106             default:
 107                 // skip validation on unknown platform
 108                 System.out.println("Skip checking OS arch in ModuleTarget: " + name);
 109                 return true;
 110         }
 111     }
 112 
 113     private void checkAttributes(ModuleReference modRef) {
 114         try {
 115             if (modRef.descriptor().name().equals("java.base")) {
 116                 ModuleTargetHelper.ModuleTarget mt = ModuleTargetHelper.read(modRef);
 117                 assertTrue(checkOSName(mt.osName()));
 118                 assertTrue(checkOSArch(mt.osArch()));
 119             } else {
 120                 // target platform attribute is dropped by jlink plugin for other modules
 121                 ModuleTargetHelper.ModuleTarget mt = ModuleTargetHelper.read(modRef);
 122                 assertTrue(mt == null || (mt.osName() == null && mt.osArch() == null));
 123             }
 124         } catch (IOException exp) {
 125             throw new UncheckedIOException(exp);
 126         }
 127     }
 128 
 129     /**


< prev index next >