< prev index next >

test/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java

Print this page




  47  * @test
  48  * @bug 8142968 8173381 8174740
  49  * @library /lib/testlibrary
  50  * @modules jdk.compiler jdk.jlink
  51  * @build UserModuleTest CompilerUtils jdk.testlibrary.FileUtils jdk.testlibrary.ProcessTools
  52  * @run testng UserModuleTest
  53  */
  54 
  55 public class UserModuleTest {
  56     private static final String JAVA_HOME = System.getProperty("java.home");
  57     private static final String TEST_SRC = System.getProperty("test.src");
  58 
  59     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
  60     private static final Path MODS_DIR = Paths.get("mods");
  61     private static final Path JMODS_DIR = Paths.get("jmods");
  62 
  63     private static final Path IMAGE = Paths.get("image");
  64     private static final String MAIN_MID = "m1/p1.Main";
  65 
  66     // the names of the modules in this test
  67     private static String[] modules = new String[] {"m1", "m2", "m3", "m4"};
  68 
  69 
  70     private static boolean hasJmods() {
  71         if (!Files.exists(Paths.get(JAVA_HOME, "jmods"))) {
  72             System.err.println("Test skipped. NO jmods directory");
  73             return false;
  74         }
  75         return true;
  76     }
  77 
  78     /*
  79      * Compiles all modules used by the test
  80      */
  81     @BeforeTest
  82     public void compileAll() throws Throwable {
  83         if (!hasJmods()) return;
  84 
  85         for (String mn : modules) {
  86             Path msrc = SRC_DIR.resolve(mn);
  87             assertTrue(CompilerUtils.compile(msrc, MODS_DIR,


 143                         .getExitValue() == 0);
 144     }
 145 
 146     /*
 147      * Test the optimization that deduplicates Set<String> on targets of exports,
 148      * uses, provides.
 149      */
 150     @Test
 151     public void testDedupSet() throws Throwable {
 152         if (!hasJmods()) return;
 153 
 154         Path dir = Paths.get("dedupSetTest");
 155         createImage(dir, "m1", "m2", "m3", "m4");
 156         Path java = dir.resolve("bin").resolve("java");
 157         assertTrue(executeProcess(java.toString(), "-m", MAIN_MID)
 158                         .outputTo(System.out)
 159                         .errorTo(System.out)
 160                         .getExitValue() == 0);
 161     }
 162 












































 163     private void createJmods(String... modules) throws IOException {
 164         // use the same target platform as in java.base
 165         ModuleDescriptor md = Layer.boot().findModule("java.base").get()
 166                                    .getDescriptor();
 167         String osName = md.osName().get();
 168         String osArch = md.osArch().get();
 169 
 170         // create JMOD files
 171         Files.createDirectories(JMODS_DIR);
 172         Stream.of(modules).forEach(mn ->
 173             assertTrue(jmod("create",
 174                 "--class-path", MODS_DIR.resolve(mn).toString(),
 175                 "--os-name", osName,
 176                 "--os-arch", osArch,
 177                 "--main-class", mn.replace('m', 'p') + ".Main",
 178                 JMODS_DIR.resolve(mn + ".jmod").toString()) == 0)
 179         );
 180     }
 181 
 182 




  47  * @test
  48  * @bug 8142968 8173381 8174740
  49  * @library /lib/testlibrary
  50  * @modules jdk.compiler jdk.jlink
  51  * @build UserModuleTest CompilerUtils jdk.testlibrary.FileUtils jdk.testlibrary.ProcessTools
  52  * @run testng UserModuleTest
  53  */
  54 
  55 public class UserModuleTest {
  56     private static final String JAVA_HOME = System.getProperty("java.home");
  57     private static final String TEST_SRC = System.getProperty("test.src");
  58 
  59     private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
  60     private static final Path MODS_DIR = Paths.get("mods");
  61     private static final Path JMODS_DIR = Paths.get("jmods");
  62 
  63     private static final Path IMAGE = Paths.get("image");
  64     private static final String MAIN_MID = "m1/p1.Main";
  65 
  66     // the names of the modules in this test
  67     private static String[] modules = new String[] {"m1", "m2", "m3", "m4", "m5"};
  68 
  69 
  70     private static boolean hasJmods() {
  71         if (!Files.exists(Paths.get(JAVA_HOME, "jmods"))) {
  72             System.err.println("Test skipped. NO jmods directory");
  73             return false;
  74         }
  75         return true;
  76     }
  77 
  78     /*
  79      * Compiles all modules used by the test
  80      */
  81     @BeforeTest
  82     public void compileAll() throws Throwable {
  83         if (!hasJmods()) return;
  84 
  85         for (String mn : modules) {
  86             Path msrc = SRC_DIR.resolve(mn);
  87             assertTrue(CompilerUtils.compile(msrc, MODS_DIR,


 143                         .getExitValue() == 0);
 144     }
 145 
 146     /*
 147      * Test the optimization that deduplicates Set<String> on targets of exports,
 148      * uses, provides.
 149      */
 150     @Test
 151     public void testDedupSet() throws Throwable {
 152         if (!hasJmods()) return;
 153 
 154         Path dir = Paths.get("dedupSetTest");
 155         createImage(dir, "m1", "m2", "m3", "m4");
 156         Path java = dir.resolve("bin").resolve("java");
 157         assertTrue(executeProcess(java.toString(), "-m", MAIN_MID)
 158                         .outputTo(System.out)
 159                         .errorTo(System.out)
 160                         .getExitValue() == 0);
 161     }
 162 
 163     @Test
 164     public void testRequiresStatic() throws Throwable {
 165         if (!hasJmods()) return;
 166 
 167         Path dir = Paths.get("requiresStatic");
 168         createImage(dir, "m5");
 169         Path java = dir.resolve("bin").resolve("java");
 170         assertTrue(executeProcess(java.toString(), "-m", "m5/p5.Main")
 171                         .outputTo(System.out)
 172                         .errorTo(System.out)
 173                         .getExitValue() == 0);
 174 
 175         // run with m3 present
 176         assertTrue(executeProcess(java.toString(),
 177                                   "--module-path", MODS_DIR.toString(),
 178                                   "--add-modules", "m3",
 179                                   "-m", "m5/p5.Main")
 180                         .outputTo(System.out)
 181                         .errorTo(System.out)
 182                         .getExitValue() == 0);
 183     }
 184 
 185     @Test
 186     public void testRequiresStatic2() throws Throwable {
 187         if (!hasJmods()) return;
 188 
 189         Path dir = Paths.get("requiresStatic2");
 190         createImage(dir, "m3", "m5");
 191 
 192         Path java = dir.resolve("bin").resolve("java");
 193         assertTrue(executeProcess(java.toString(), "-m", "m5/p5.Main")
 194                         .outputTo(System.out)
 195                         .errorTo(System.out)
 196                         .getExitValue() == 0);
 197 
 198         // boot layer with m3 and m5
 199         assertTrue(executeProcess(java.toString(),
 200                                   "--add-modules", "m3",
 201                                   "-m", "m5/p5.Main")
 202                         .outputTo(System.out)
 203                         .errorTo(System.out)
 204                         .getExitValue() == 0);
 205     }
 206 
 207     private void createJmods(String... modules) throws IOException {
 208         // use the same target platform as in java.base
 209         ModuleDescriptor md = Layer.boot().findModule("java.base").get()
 210                                    .getDescriptor();
 211         String osName = md.osName().get();
 212         String osArch = md.osArch().get();
 213 
 214         // create JMOD files
 215         Files.createDirectories(JMODS_DIR);
 216         Stream.of(modules).forEach(mn ->
 217             assertTrue(jmod("create",
 218                 "--class-path", MODS_DIR.resolve(mn).toString(),
 219                 "--os-name", osName,
 220                 "--os-arch", osArch,
 221                 "--main-class", mn.replace('m', 'p') + ".Main",
 222                 JMODS_DIR.resolve(mn + ".jmod").toString()) == 0)
 223         );
 224     }
 225 
 226 


< prev index next >