--- old/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java 2019-12-13 13:37:53.777077400 -0500 +++ new/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java 2019-12-13 13:37:52.686899100 -0500 @@ -30,6 +30,7 @@ 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; @@ -119,6 +120,10 @@ @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 expectedVerboseOutputStrings = new ArrayList<>(); @@ -139,17 +144,17 @@ } TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); - List nonVerboseOutput = cmd.createExecutor().executeAndGetOutput(); + List nonVerboseOutput = cmd.execute().getOutput(); List[] verboseOutput = (List[])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(), @@ -189,7 +194,7 @@ } @Test - // Regular app + // Regular app @Parameter("Hello") // Modular app @Parameter("com.other/com.other.Hello") @@ -227,62 +232,66 @@ */ @Test public void testTemp() throws IOException { - TKit.withTempDirectory("temp-root", tempRoot -> { - Function getTempDir = cmd -> { - return tempRoot.resolve(cmd.outputBundle().getFileName()); - }; + final Path tempRoot = TKit.createTempDirectory("temp-root"); - ThrowingConsumer addTempDir = cmd -> { + Function getTempDir = cmd -> { + return tempRoot.resolve(cmd.outputBundle().getFileName()); + }; + + Supplier 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) - .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(); + }); + }; - new PackageTest().configureHelloApp().addInitializer(addTempDir) - .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(); - }); + 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(PackageTest.Action.CREATE); + + 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(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(); @@ -292,50 +301,45 @@ @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); + + JPackageCommand cmd = JPackageCommand.helloAppImage(appDesc); - // 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]); + 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" - }; - - Executor jlink = getToolProvider(JavaTool.JLINK) - .saveOutput(false) - .addArguments( - "--add-modules", String.join(",", modules), - "--output", runtimeDir.toString(), - "--strip-debug", - "--no-header-files", - "--no-man-pages"); - - if (moduleName != null) { - jlink.addArguments("--add-modules", moduleName, "--module-path", - Path.of(cmd.getArgumentValue("--module-path")).resolve( - "hello.jar").toString()); - } + // List of modules required for test app. + final var modules = new String[] { + "java.base", + "java.desktop" + }; - jlink.execute().assertExitCodeIsZero(); + Executor jlink = getToolProvider(JavaTool.JLINK) + .saveOutput(false) + .addArguments( + "--add-modules", String.join(",", modules), + "--output", runtimeDir.toString(), + "--strip-debug", + "--no-header-files", + "--no-man-pages"); - cmd.addArguments("--runtime-image", runtimeDir); - cmd.executeAndAssertHelloAppImageCreated(); - }); + if (moduleName != null) { + jlink.addArguments("--add-modules", moduleName, "--module-path", + Path.of(cmd.getArgumentValue("--module-path")).resolve( + "hello.jar").toString()); + } + + jlink.execute(); + + cmd.addArguments("--runtime-image", runtimeDir); + cmd.executeAndAssertHelloAppImageCreated(); } private static Executor getJPackageToolProvider() {