1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.IOException; 25 import java.nio.file.Files; 26 import java.nio.file.Path; 27 import java.util.HashSet; 28 import java.util.Optional; 29 import java.util.Set; 30 import java.util.stream.Collectors; 31 import jdk.jpackage.test.*; 32 import jdk.jpackage.test.Annotations.Test; 33 34 /** 35 * Test --runtime-image parameter. 36 * Output of the test should be RuntimePackageTest*.* installer. 37 * The installer should install Java Runtime without an application. 38 * Installation directory should not have "app" subfolder and should not have 39 * an application launcher. 40 * 41 * 42 * Windows: 43 * 44 * Java runtime should be installed in %ProgramFiles%\RuntimePackageTest directory. 45 */ 46 47 /* 48 * @test 49 * @summary jpackage with --runtime-image 50 * @library ../helpers 51 * @key jpackagePlatformPackage 52 * @build jdk.jpackage.test.* 53 * @comment Temporary disable for Linux and OSX until functionality implemented 54 * @requires (os.family != "mac") 55 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 56 * @compile RuntimePackageTest.java 57 * @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main 58 * --jpt-run=RuntimePackageTest 59 */ 60 public class RuntimePackageTest { 61 62 @Test 63 public static void test() { 64 new PackageTest() 65 .addInitializer(cmd -> { 66 cmd.addArguments("--runtime-image", Optional.ofNullable( 67 JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of( 68 System.getProperty("java.home")))); 69 // Remove --input parameter from jpackage command line as we don't 70 // create input directory in the test and jpackage fails 71 // if --input references non existant directory. 72 cmd.removeArgumentWithValue("--input"); 73 }) 74 .addInstallVerifier(cmd -> { 75 Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image"))); 76 Set<Path> dstRuntime = listFiles(cmd.appRuntimeDirectory()); 77 78 Set<Path> intersection = new HashSet<>(srcRuntime); 79 intersection.retainAll(dstRuntime); 80 81 srcRuntime.removeAll(intersection); 82 dstRuntime.removeAll(intersection); 83 84 assertFileListEmpty(srcRuntime, "Missing"); 85 assertFileListEmpty(dstRuntime, "Unexpected"); 86 }) 87 .run(); 88 } 89 90 private static Set<Path> listFiles(Path root) throws IOException { 91 try (var files = Files.walk(root)) { 92 return files.map(root::relativize).collect(Collectors.toSet()); 93 } 94 } 95 96 private static void assertFileListEmpty(Set<Path> paths, String msg) { 97 TKit.assertTrue(paths.isEmpty(), String.format( 98 "Check there are no %s files in installed image", 99 msg.toLowerCase()), () -> { 100 String msg2 = String.format("%s %d files", msg, paths.size()); 101 TKit.trace(msg2 + ":"); 102 paths.stream().map(Path::toString).sorted().forEachOrdered( 103 TKit::trace); 104 TKit.trace("Done"); 105 }); 106 } 107 }