Path: blob/master/test/jdk/tools/jpackage/share/RuntimePackageTest.java
41152 views
/*1* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;24import java.nio.file.Files;25import java.nio.file.Path;26import java.util.HashSet;27import java.util.Optional;28import java.util.Set;29import java.util.function.Predicate;30import java.util.stream.Collectors;31import jdk.jpackage.test.PackageType;32import jdk.jpackage.test.PackageTest;33import jdk.jpackage.test.JPackageCommand;34import jdk.jpackage.test.TKit;35import jdk.jpackage.test.Annotations.Test;36import jdk.jpackage.test.LinuxHelper;37import static jdk.jpackage.test.TKit.assertTrue;38import static jdk.jpackage.test.TKit.assertFalse;3940/**41* Test --runtime-image parameter.42* Output of the test should be RuntimePackageTest*.* installer.43* The installer should install Java Runtime without an application.44* Installation directory should not have "app" subfolder and should not have45* an application launcher.46*47*48* Windows:49*50* Java runtime should be installed in %ProgramFiles%\RuntimePackageTest directory.51*/5253/*54* @test55* @summary jpackage with --runtime-image56* @library ../helpers57* @key jpackagePlatformPackage58* @build jdk.jpackage.test.*59* @requires (jpackage.test.SQETest == null)60* @modules jdk.jpackage/jdk.jpackage.internal61* @compile RuntimePackageTest.java62* @run main/othervm/timeout=1400 -Xmx512m jdk.jpackage.test.Main63* --jpt-run=RuntimePackageTest64*/6566/*67* @test68* @summary jpackage with --runtime-image69* @library ../helpers70* @key jpackagePlatformPackage71* @build jdk.jpackage.test.*72* @requires (jpackage.test.SQETest != null)73* @modules jdk.jpackage/jdk.jpackage.internal74* @compile RuntimePackageTest.java75* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main76* --jpt-run=RuntimePackageTest.test77*/78public class RuntimePackageTest {7980@Test81public static void test() {82init(PackageType.NATIVE).run();83}8485@Test86public static void testUsrInstallDir() {87init(PackageType.LINUX)88.addInitializer(cmd -> cmd.addArguments("--install-dir", "/usr"))89.run();90}9192@Test93public static void testUsrInstallDir2() {94init(PackageType.LINUX)95.addInitializer(cmd -> cmd.addArguments("--install-dir", "/usr/lib/Java"))96.run();97}9899private static PackageTest init(Set<PackageType> types) {100return new PackageTest()101.forTypes(types)102.addInitializer(cmd -> {103cmd.addArguments("--runtime-image", Optional.ofNullable(104JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of(105System.getProperty("java.home"))));106// Remove --input parameter from jpackage command line as we don't107// create input directory in the test and jpackage fails108// if --input references non existant directory.109cmd.removeArgumentWithValue("--input");110})111.addInstallVerifier(cmd -> {112Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image")));113Path dest = cmd.appRuntimeDirectory();114if (TKit.isOSX()) {115dest = dest.resolve("Contents/Home");116}117Set<Path> dstRuntime = listFiles(dest);118119Set<Path> intersection = new HashSet<>(srcRuntime);120intersection.retainAll(dstRuntime);121122srcRuntime.removeAll(intersection);123dstRuntime.removeAll(intersection);124125assertFileListEmpty(srcRuntime, "Missing");126assertFileListEmpty(dstRuntime, "Unexpected");127})128.forTypes(PackageType.LINUX_DEB)129.addInstallVerifier(cmd -> {130String installDir = cmd.getArgumentValue("--install-dir", () -> "/opt");131Path copyright = Path.of("/usr/share/doc",132LinuxHelper.getPackageName(cmd), "copyright");133boolean withCopyright = LinuxHelper.getPackageFiles(cmd).anyMatch(134Predicate.isEqual(copyright));135if (installDir.startsWith("/usr/") || installDir.equals("/usr")) {136assertTrue(withCopyright, String.format(137"Check the package delivers [%s] copyright file",138copyright));139} else {140assertFalse(withCopyright, String.format(141"Check the package doesn't deliver [%s] copyright file",142copyright));143}144});145}146147private static Set<Path> listFiles(Path root) throws IOException {148try (var files = Files.walk(root)) {149// Ignore files created by system prefs if any.150final Path prefsDir = Path.of(".systemPrefs");151return files.map(root::relativize)152.filter(x -> !x.startsWith(prefsDir))153.filter(x -> !x.endsWith(".DS_Store"))154.collect(Collectors.toSet());155}156}157158private static void assertFileListEmpty(Set<Path> paths, String msg) {159TKit.assertTrue(paths.isEmpty(), String.format(160"Check there are no %s files in installed image",161msg.toLowerCase()), () -> {162String msg2 = String.format("%s %d files", msg, paths.size());163TKit.trace(msg2 + ":");164paths.stream().map(Path::toString).sorted().forEachOrdered(165TKit::trace);166TKit.trace("Done");167});168}169}170171172