< prev index next >

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

Print this page

        

*** 28,37 **** --- 28,38 ---- 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,126 **** --- 118,131 ---- @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,157 **** } else { TKit.throwUnknownPlatformError(); } TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); ! List<String> nonVerboseOutput = cmd.createExecutor().executeAndGetOutput(); 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 // verbose jpackage run. TKit.withTempDirectory("verbose-output", tempDir -> { cmd.setArgumentValue("--dest", tempDir); ! verboseOutput[0] = cmd.createExecutor().addArgument( ! "--verbose").executeAndGetOutput(); }); TKit.assertTrue(nonVerboseOutput.size() < verboseOutput[0].size(), "Check verbose output is longer than regular"); --- 142,162 ---- } else { TKit.throwUnknownPlatformError(); } TKit.deleteDirectoryContentsRecursive(cmd.outputDir()); ! 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 ! // different output directory instead of cleaning the default one for // verbose jpackage run. TKit.withTempDirectory("verbose-output", tempDir -> { cmd.setArgumentValue("--dest", tempDir); ! cmd.addArgument("--verbose"); ! verboseOutput[0] = cmd.execute().getOutput(); }); TKit.assertTrue(nonVerboseOutput.size() < verboseOutput[0].size(), "Check verbose output is longer than regular");
*** 225,316 **** * directory is used only on Windows. Test it in packaging mode. * @throws IOException */ @Test public void testTemp() throws IOException { ! TKit.withTempDirectory("temp-root", tempRoot -> { Function<JPackageCommand, Path> getTempDir = cmd -> { return tempRoot.resolve(cmd.outputBundle().getFileName()); }; ! ThrowingConsumer<JPackageCommand> addTempDir = 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(); ! }); } @Test public void testAtFile() throws IOException { ! JPackageCommand cmd = JPackageCommand.helloAppImage(); // Init options file with the list of options configured // for JPackageCommand instance. ! final Path optionsFile = TKit.workDir().resolve("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(); // 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); ! // 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]); if (moduleName != null) { // Build module jar. cmd.executePrerequisiteActions(); } ! TKit.withTempDirectory("runtime", tempDir -> { ! final Path runtimeDir = tempDir.resolve("data"); // List of modules required for test app. final var modules = new String[] { "java.base", "java.desktop" --- 230,321 ---- * directory is used only on Windows. Test it in packaging mode. * @throws IOException */ @Test public void testTemp() throws IOException { ! final Path tempRoot = TKit.createTempDirectory("temp-root"); ! Function<JPackageCommand, Path> getTempDir = cmd -> { return tempRoot.resolve(cmd.outputBundle().getFileName()); }; ! 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); + }); }; ! 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() ! .setArgumentValue("--dest", TKit.createTempDirectory("output")); // Init options file with the list of options configured // for JPackageCommand instance. ! final Path optionsFile = TKit.createTempFile(Path.of("options")); Files.write(optionsFile, List.of(String.join(" ", cmd.getAllArguments()))); // Build app jar file. cmd.executePrerequisiteActions(); // Instead of running jpackage command through configured // JPackageCommand instance, run vanilla jpackage command with @ file. getJPackageToolProvider() .addArgument(String.format("@%s", optionsFile)) ! .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) throws IOException { ! JavaAppDesc appDesc = JavaAppDesc.parse(javaAppDesc); ! JPackageCommand cmd = JPackageCommand.helloAppImage(appDesc); ! ! final String moduleName = appDesc.moduleName(); if (moduleName != null) { // Build module jar. cmd.executePrerequisiteActions(); } ! 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,343 **** jlink.addArguments("--add-modules", moduleName, "--module-path", Path.of(cmd.getArgumentValue("--module-path")).resolve( "hello.jar").toString()); } ! jlink.execute().assertExitCodeIsZero(); cmd.addArguments("--runtime-image", runtimeDir); cmd.executeAndAssertHelloAppImageCreated(); - }); } private static Executor getJPackageToolProvider() { return getToolProvider(JavaTool.JPACKAGE); } --- 334,347 ---- 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() { return getToolProvider(JavaTool.JPACKAGE); }
< prev index next >