test/jdk/tools/jlink/basic/BasicTest.java
changeset 57821 182f94955cfb
parent 51977 a8862960c19f
equal deleted inserted replaced
57819:40006c0ada91 57821:182f94955cfb
    98 
    98 
    99         image = Paths.get("myimage");
    99         image = Paths.get("myimage");
   100         runJmod(classes.toString(), TEST_MODULE, true);
   100         runJmod(classes.toString(), TEST_MODULE, true);
   101         runJlink(image, TEST_MODULE, "--launcher", "bar=" + TEST_MODULE);
   101         runJlink(image, TEST_MODULE, "--launcher", "bar=" + TEST_MODULE);
   102         execute(image, "bar");
   102         execute(image, "bar");
   103 
       
   104         Files.delete(jmods.resolve(TEST_MODULE + ".jmod"));
   103         Files.delete(jmods.resolve(TEST_MODULE + ".jmod"));
   105 
   104 
   106         image = Paths.get("myimage2");
   105         image = Paths.get("myimage2");
   107         runJmod(classes.toString(), TEST_MODULE, false /* no ModuleMainClass! */);
   106         runJmod(classes.toString(), TEST_MODULE, false /* no ModuleMainClass! */);
   108         // specify main class in --launcher command line
   107         // specify main class in --launcher command line
   109         runJlink(image, TEST_MODULE, "--launcher", "bar2=" + TEST_MODULE + "/jdk.test.Test");
   108         runJlink(image, TEST_MODULE, "--launcher", "bar2=" + TEST_MODULE + "/jdk.test.Test");
   110         execute(image, "bar2");
   109         execute(image, "bar2");
       
   110         Files.delete(jmods.resolve(TEST_MODULE + ".jmod"));
   111 
   111 
       
   112         image = Paths.get("myadder");
       
   113         runJmod(classes.toString(), TEST_MODULE, false /* no ModuleMainClass! */);
       
   114         // specify main class in --launcher command line
       
   115         runJlink(image, TEST_MODULE, "--launcher", "adder=" + TEST_MODULE + "/jdk.test.Adder");
       
   116         addAndCheck(image, "adder");
       
   117     }
       
   118 
       
   119     private void addAndCheck(Path image, String scriptName) throws Throwable {
       
   120         String cmd = image.resolve("bin").resolve(scriptName).toString();
       
   121         OutputAnalyzer analyzer;
       
   122         if (System.getProperty("os.name").startsWith("Windows")) {
       
   123             analyzer = ProcessTools.executeProcess("sh.exe", cmd, "12", "8", "7", "--", "foo bar");
       
   124         } else {
       
   125             analyzer = ProcessTools.executeProcess(cmd, "12", "8", "7", "--", "foo bar");
       
   126         }
       
   127         if (analyzer.getExitValue() != 27) {
       
   128             throw new AssertionError("Image invocation failed: expected 27, rc=" + analyzer.getExitValue());
       
   129         }
       
   130         // last argument contains space and should be properly quoted.
       
   131         analyzer.stdoutShouldContain("Num args: 5");
   112     }
   132     }
   113 
   133 
   114     private void execute(Path image, String scriptName) throws Throwable {
   134     private void execute(Path image, String scriptName) throws Throwable {
   115         String cmd = image.resolve("bin").resolve(scriptName).toString();
   135         String cmd = image.resolve("bin").resolve(scriptName).toString();
   116         OutputAnalyzer analyzer;
   136         OutputAnalyzer analyzer;