Path: blob/master/test/jdk/tools/jpackage/linux/ShortcutHintTest.java
41149 views
/*1* Copyright (c) 2019, 2020, 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.List;27import jdk.jpackage.test.AdditionalLauncher;28import jdk.jpackage.test.FileAssociations;29import jdk.jpackage.test.PackageType;30import jdk.jpackage.test.PackageTest;31import jdk.jpackage.test.TKit;32import jdk.jpackage.test.JPackageCommand;33import jdk.jpackage.test.LinuxHelper;34import jdk.jpackage.test.Annotations.Test;3536/**37* Test --linux-shortcut parameter. Output of the test should be38* shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package39* bundle. The output package should provide the same functionality as the40* default package and also create a desktop shortcut.41*42* Finding a shortcut of the application launcher through GUI depends on desktop43* environment.44*45* deb:46* Search online for `Ways To Open A Ubuntu Application` for instructions.47*48* rpm:49*50*/5152/*53* @test54* @summary jpackage with --linux-shortcut55* @library ../helpers56* @key jpackagePlatformPackage57* @requires jpackage.test.SQETest == null58* @build jdk.jpackage.test.*59* @requires (os.family == "linux")60* @modules jdk.jpackage/jdk.jpackage.internal61* @compile ShortcutHintTest.java62* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main63* --jpt-run=ShortcutHintTest64*/6566/*67* @test68* @summary jpackage with --linux-shortcut69* @library ../helpers70* @key jpackagePlatformPackage71* @build jdk.jpackage.test.*72* @requires (os.family == "linux")73* @requires jpackage.test.SQETest != null74* @modules jdk.jpackage/jdk.jpackage.internal75* @compile ShortcutHintTest.java76* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main77* --jpt-run=ShortcutHintTest.testBasic78*/7980public class ShortcutHintTest {8182@Test83public static void testBasic() {84createTest().addInitializer(cmd -> {85cmd.addArgument("--linux-shortcut");86}).run();87}8889private static PackageTest createTest() {90return new PackageTest()91.forTypes(PackageType.LINUX)92.configureHelloApp()93.addBundleDesktopIntegrationVerifier(true)94.addInitializer(cmd -> {95String defaultAppName = cmd.name();96String appName = defaultAppName.replace(97ShortcutHintTest.class.getSimpleName(),98"Shortcut Hint Test");99cmd.setArgumentValue("--name", appName);100cmd.addArguments("--linux-package-name",101defaultAppName.toLowerCase());102});103}104105/**106* Adding `--icon` to jpackage command line should create desktop shortcut107* even though `--linux-shortcut` is omitted.108*/109@Test110public static void testCustomIcon() {111createTest().addInitializer(cmd -> {112cmd.setFakeRuntime();113cmd.addArguments("--icon", TKit.TEST_SRC_ROOT.resolve(114"apps/dukeplug.png"));115}).run();116}117118/**119* Adding `--file-associations` to jpackage command line should create120* desktop shortcut even though `--linux-shortcut` is omitted.121*/122@Test123public static void testFileAssociations() {124PackageTest test = createTest().addInitializer(125JPackageCommand::setFakeRuntime);126new FileAssociations("ShortcutHintTest_testFileAssociations").applyTo(127test);128test.run();129}130131/**132* Additional launcher with icon should create desktop shortcut even though133* `--linux-shortcut` is omitted.134*/135@Test136public static void testAdditionaltLaunchers() {137PackageTest test = createTest();138139new AdditionalLauncher("Foo").setIcon(TKit.TEST_SRC_ROOT.resolve(140"apps/dukeplug.png")).applyTo(test);141142test.addInitializer(JPackageCommand::setFakeRuntime).run();143}144145/**146* .desktop file from resource dir.147*/148@Test149public static void testDesktopFileFromResourceDir() throws IOException {150final String expectedVersionString = "Version=12345678";151152final Path tempDir = TKit.createTempDirectory("resources");153154createTest().addInitializer(cmd -> {155cmd.setFakeRuntime();156157cmd.addArgument("--linux-shortcut");158cmd.addArguments("--resource-dir", tempDir);159160// Create custom .desktop file in resource directory161TKit.createTextFile(tempDir.resolve(cmd.name() + ".desktop"),162List.of(163"[Desktop Entry]",164"Name=APPLICATION_NAME",165"Exec=APPLICATION_LAUNCHER",166"Terminal=false",167"Type=Application",168"Comment=",169"Icon=APPLICATION_ICON",170"Categories=DEPLOY_BUNDLE_CATEGORY",171expectedVersionString172));173})174.addInstallVerifier(cmd -> {175Path desktopFile = LinuxHelper.getDesktopFile(cmd);176TKit.assertFileExists(desktopFile);177TKit.assertTextStream(expectedVersionString)178.label(String.format("[%s] file", desktopFile))179.predicate(String::equals)180.apply(Files.readAllLines(desktopFile).stream());181}).run();182}183}184185186