< prev index next >

test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java

Print this page

        

@@ -28,10 +28,11 @@
 import java.nio.file.Path;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.Supplier;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import jdk.jpackage.test.*;
 import jdk.jpackage.test.Functional.ThrowingConsumer;

@@ -117,10 +118,14 @@
 
     @Test
     @SuppressWarnings("unchecked")
     public void testVerbose() {
         JPackageCommand cmd = JPackageCommand.helloAppImage()
+                // Disable default logic adding `--verbose` option
+                // to jpackage command line.
+                .ignoreDefaultVerbose(true)
+                .saveConsoleOutput(true)
                 .setFakeRuntime().executePrerequisiteActions();
 
         List<String> expectedVerboseOutputStrings = new ArrayList<>();
         expectedVerboseOutputStrings.add("Creating app package:");
         if (TKit.isWindows()) {

@@ -137,21 +142,21 @@
         } else {
             TKit.throwUnknownPlatformError();
         }
 
         TKit.deleteDirectoryContentsRecursive(cmd.outputDir());
-        List<String> nonVerboseOutput = cmd.createExecutor().executeAndGetOutput();
+        List<String> nonVerboseOutput = cmd.execute().getOutput();
         List<String>[] verboseOutput = (List<String>[])new List<?>[1];
 
         // Directory clean up is not 100% reliable on Windows because of
         // antivirus software that can lock .exe files. Setup
-        // diffreent output directory instead of cleaning the default one for
+        // different output directory instead of cleaning the default one for
         // verbose jpackage run.
         TKit.withTempDirectory("verbose-output", tempDir -> {
             cmd.setArgumentValue("--dest", tempDir);
-            verboseOutput[0] = cmd.createExecutor().addArgument(
-                    "--verbose").executeAndGetOutput();
+            cmd.addArgument("--verbose");
+            verboseOutput[0] = cmd.execute().getOutput();
         });
 
         TKit.assertTrue(nonVerboseOutput.size() < verboseOutput[0].size(),
                 "Check verbose output is longer than regular");
 

@@ -225,92 +230,92 @@
      * directory is used only on Windows. Test it in packaging mode.
      * @throws IOException
      */
     @Test
     public void testTemp() throws IOException {
-        TKit.withTempDirectory("temp-root", tempRoot -> {
+        final Path tempRoot = TKit.createTempDirectory("temp-root");
+
             Function<JPackageCommand, Path> getTempDir = cmd -> {
                 return tempRoot.resolve(cmd.outputBundle().getFileName());
             };
 
-            ThrowingConsumer<JPackageCommand> addTempDir = cmd -> {
+        Supplier<PackageTest> createTest = () -> {
+            return new PackageTest()
+            .configureHelloApp()
+            // Force save of package bundle in test work directory.
+            .addInitializer(JPackageCommand::setDefaultInputOutput)
+            .addInitializer(cmd -> {
                 Path tempDir = getTempDir.apply(cmd);
                 Files.createDirectories(tempDir);
                 cmd.addArguments("--temp", tempDir);
+            });
             };
 
-            new PackageTest().configureHelloApp().addInitializer(addTempDir)
+        createTest.get()
             .addBundleVerifier(cmd -> {
                 // Check jpackage actually used the supplied directory.
                 Path tempDir = getTempDir.apply(cmd);
                 TKit.assertNotEquals(0, tempDir.toFile().list().length,
                         String.format(
                                 "Check jpackage wrote some data in the supplied temporary directory [%s]",
                                 tempDir));
             })
-            .run();
+        .run(PackageTest.Action.CREATE);
 
-            new PackageTest().configureHelloApp().addInitializer(addTempDir)
+        createTest.get()
             .addInitializer(cmd -> {
                 // Clean output from the previus jpackage run.
                 Files.delete(cmd.outputBundle());
             })
             // Temporary directory should not be empty,
             // jpackage should exit with error.
             .setExpectedExitCode(1)
-            .run();
-        });
+        .run(PackageTest.Action.CREATE);
     }
 
     @Test
     public void testAtFile() throws IOException {
-        JPackageCommand cmd = JPackageCommand.helloAppImage();
+        JPackageCommand cmd = JPackageCommand
+                .helloAppImage()
+                .setArgumentValue("--dest", TKit.createTempDirectory("output"));
 
         // Init options file with the list of options configured
         // for JPackageCommand instance.
-        final Path optionsFile = TKit.workDir().resolve("options");
+        final Path optionsFile = TKit.createTempFile(Path.of("options"));
         Files.write(optionsFile,
                 List.of(String.join(" ", cmd.getAllArguments())));
 
         // Build app jar file.
         cmd.executePrerequisiteActions();
 
-        // Make sure output directory is empty. Normally JPackageCommand would
-        // do this automatically.
-        TKit.deleteDirectoryContentsRecursive(cmd.outputDir());
-
         // Instead of running jpackage command through configured
         // JPackageCommand instance, run vanilla jpackage command with @ file.
         getJPackageToolProvider()
                 .addArgument(String.format("@%s", optionsFile))
-                .execute().assertExitCodeIsZero();
+                .execute();
 
         // Verify output of jpackage command.
         cmd.assertImageCreated();
         HelloApp.executeLauncherAndVerifyOutput(cmd);
     }
 
     @Parameter("Hello")
     @Parameter("com.foo/com.foo.main.Aloha")
     @Test
-    public void testJLinkRuntime(String javaAppDesc) {
-        JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc);
+    public void testJLinkRuntime(String javaAppDesc) throws IOException {
+        JavaAppDesc appDesc = JavaAppDesc.parse(javaAppDesc);
 
-        // If `--module` parameter was set on jpackage command line, get its
-        // value and extract module name.
-        // E.g.: foo.bar2/foo.bar.Buz -> foo.bar2
-        // Note: HelloApp class manages `--module` parameter on jpackage command line
-        final String moduleName = cmd.getArgumentValue("--module", () -> null,
-                (v) -> v.split("/", 2)[0]);
+        JPackageCommand cmd = JPackageCommand.helloAppImage(appDesc);
+
+        final String moduleName = appDesc.moduleName();
 
         if (moduleName != null) {
             // Build module jar.
             cmd.executePrerequisiteActions();
         }
 
-        TKit.withTempDirectory("runtime", tempDir -> {
-            final Path runtimeDir = tempDir.resolve("data");
+        final Path runtimeDir = TKit.createTempDirectory("runtime").resolve("data");
 
             // List of modules required for test app.
             final var modules = new String[] {
                 "java.base",
                 "java.desktop"

@@ -329,15 +334,14 @@
                 jlink.addArguments("--add-modules", moduleName, "--module-path",
                         Path.of(cmd.getArgumentValue("--module-path")).resolve(
                                 "hello.jar").toString());
             }
 
-            jlink.execute().assertExitCodeIsZero();
+        jlink.execute();
 
             cmd.addArguments("--runtime-image", runtimeDir);
             cmd.executeAndAssertHelloAppImageCreated();
-        });
     }
 
     private static Executor getJPackageToolProvider() {
         return getToolProvider(JavaTool.JPACKAGE);
     }
< prev index next >