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.nio.charset.StandardCharsets; 25 import java.nio.file.Files; 26 import java.util.Map; 27 import java.nio.file.Path; 28 import java.util.List; 29 import java.util.stream.Collectors; 30 import jdk.jpackage.test.FileAssociations; 31 import jdk.jpackage.test.PackageType; 32 import jdk.jpackage.test.PackageTest; 33 import jdk.jpackage.test.TKit; 34 import jdk.jpackage.test.Annotations.Test; 35 import jdk.jpackage.test.*; 36 37 /** 38 * Test --linux-shortcut parameter. Output of the test should be 39 * shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package 40 * bundle. The output package should provide the same functionality as the 41 * default package and also create a desktop shortcut. 42 * 43 * Finding a shortcut of the application launcher through GUI depends on desktop 44 * environment. 45 * 46 * deb: 47 * Search online for `Ways To Open A Ubuntu Application` for instructions. 48 * 49 * rpm: 110 111 /** 112 * Adding `--file-associations` to jpackage command line should create 113 * desktop shortcut even though `--linux-shortcut` is omitted. 114 */ 115 @Test 116 public static void testFileAssociations() { 117 PackageTest test = createTest().addInitializer( 118 JPackageCommand::setFakeRuntime); 119 new FileAssociations("ShortcutHintTest_testFileAssociations").applyTo( 120 test); 121 test.run(); 122 } 123 124 /** 125 * Additional launcher with icon should create desktop shortcut even though 126 * `--linux-shortcut` is omitted. 127 */ 128 @Test 129 public static void testAdditionaltLaunchers() { 130 createTest().addInitializer(cmd -> { 131 cmd.setFakeRuntime(); 132 133 final String launcherName = "Foo"; 134 final Path propsFile = TKit.workDir().resolve( 135 launcherName + ".properties"); 136 137 cmd.addArguments("--add-launcher", String.format("%s=%s", 138 launcherName, propsFile)); 139 140 TKit.createPropertiesFile(propsFile, Map.entry("icon", 141 TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png").toString())); 142 }).run(); 143 } 144 145 /** 146 * .desktop file from resource dir. 147 */ 148 @Test 149 public static void testDesktopFileFromResourceDir() { 150 final String expectedVersionString = "Version=12345678"; 151 TKit.withTempDirectory("resources", tempDir -> { 152 createTest().addInitializer(cmd -> { 153 cmd.setFakeRuntime(); 154 155 cmd.addArgument("--linux-shortcut"); 156 cmd.addArguments("--resource-dir", tempDir); 157 158 // Create custom .desktop file in resource directory 159 TKit.createTextFile(tempDir.resolve(cmd.name() + ".desktop"), 160 List.of( 161 "[Desktop Entry]", 162 "Name=APPLICATION_NAME", 163 "Exec=APPLICATION_LAUNCHER", 164 "Terminal=false", 165 "Type=Application", 166 "Categories=DEPLOY_BUNDLE_CATEGORY", 167 expectedVersionString 168 )); 169 }) 170 .addInstallVerifier(cmd -> { 171 Path desktopFile = cmd.appLayout().destktopIntegrationDirectory().resolve( 172 String.format("%s-%s.desktop", 173 LinuxHelper.getPackageName(cmd), cmd.name())); 174 TKit.assertFileExists(desktopFile); 175 TKit.assertTextStream(expectedVersionString) 176 .label(String.format("[%s] file", desktopFile)) 177 .predicate(String::equals) 178 .apply(Files.readAllLines(desktopFile).stream()); 179 }).run(); 180 }); 181 } 182 } | 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.util.Map; 27 import java.nio.file.Path; 28 import java.util.List; 29 import jdk.jpackage.test.AdditionalLauncher; 30 import jdk.jpackage.test.FileAssociations; 31 import jdk.jpackage.test.PackageType; 32 import jdk.jpackage.test.PackageTest; 33 import jdk.jpackage.test.TKit; 34 import jdk.jpackage.test.Annotations.Test; 35 import jdk.jpackage.test.*; 36 37 /** 38 * Test --linux-shortcut parameter. Output of the test should be 39 * shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package 40 * bundle. The output package should provide the same functionality as the 41 * default package and also create a desktop shortcut. 42 * 43 * Finding a shortcut of the application launcher through GUI depends on desktop 44 * environment. 45 * 46 * deb: 47 * Search online for `Ways To Open A Ubuntu Application` for instructions. 48 * 49 * rpm: 110 111 /** 112 * Adding `--file-associations` to jpackage command line should create 113 * desktop shortcut even though `--linux-shortcut` is omitted. 114 */ 115 @Test 116 public static void testFileAssociations() { 117 PackageTest test = createTest().addInitializer( 118 JPackageCommand::setFakeRuntime); 119 new FileAssociations("ShortcutHintTest_testFileAssociations").applyTo( 120 test); 121 test.run(); 122 } 123 124 /** 125 * Additional launcher with icon should create desktop shortcut even though 126 * `--linux-shortcut` is omitted. 127 */ 128 @Test 129 public static void testAdditionaltLaunchers() { 130 PackageTest test = createTest(); 131 132 new AdditionalLauncher("Foo").setIcon(TKit.TEST_SRC_ROOT.resolve( 133 "apps/dukeplug.png")).applyTo(test); 134 135 test.addInitializer(JPackageCommand::setFakeRuntime).run(); 136 } 137 138 /** 139 * .desktop file from resource dir. 140 */ 141 @Test 142 public static void testDesktopFileFromResourceDir() throws IOException { 143 final String expectedVersionString = "Version=12345678"; 144 145 final Path tempDir = TKit.createTempDirectory("resources"); 146 147 createTest().addInitializer(cmd -> { 148 cmd.setFakeRuntime(); 149 150 cmd.addArgument("--linux-shortcut"); 151 cmd.addArguments("--resource-dir", tempDir); 152 153 // Create custom .desktop file in resource directory 154 TKit.createTextFile(tempDir.resolve(cmd.name() + ".desktop"), 155 List.of( 156 "[Desktop Entry]", 157 "Name=APPLICATION_NAME", 158 "Exec=APPLICATION_LAUNCHER", 159 "Terminal=false", 160 "Type=Application", 161 "Categories=DEPLOY_BUNDLE_CATEGORY", 162 expectedVersionString 163 )); 164 }) 165 .addInstallVerifier(cmd -> { 166 Path desktopFile = cmd.appLayout().destktopIntegrationDirectory().resolve( 167 String.format("%s-%s.desktop", 168 LinuxHelper.getPackageName(cmd), cmd.name())); 169 TKit.assertFileExists(desktopFile); 170 TKit.assertTextStream(expectedVersionString) 171 .label(String.format("[%s] file", desktopFile)) 172 .predicate(String::equals) 173 .apply(Files.readAllLines(desktopFile).stream()); 174 }).run(); 175 } 176 } |