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.file.Path; 25 import java.util.HashMap; 26 import java.util.Map; 27 import java.util.List; 28 import java.util.Optional; 29 import java.lang.invoke.MethodHandles; 30 import jdk.jpackage.test.HelloApp; 31 import jdk.jpackage.test.PackageTest; 32 import jdk.jpackage.test.PackageType; 33 import jdk.jpackage.test.FileAssociations; 34 import jdk.jpackage.test.Annotations.Test; 35 import jdk.jpackage.test.TKit; 36 37 /** 38 * Test --add-launcher parameter. Output of the test should be 39 * additionallauncherstest*.* installer. The output installer should provide the 40 * same functionality as the default installer (see description of the default 41 * installer in SimplePackageTest.java) plus install three extra application 42 * launchers. 43 */ 44 45 /* 46 * @test 47 * @summary jpackage with --add-launcher 48 * @key jpackagePlatformPackage 49 * @library ../helpers 50 * @build jdk.jpackage.test.* 51 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 52 * @compile AdditionalLaunchersTest.java 53 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 54 * --jpt-run=AdditionalLaunchersTest 55 */ 56 57 public class AdditionalLaunchersTest { 58 59 @Test 60 public void test() { 61 // Configure a bunch of additional launchers and also setup 62 // file association to make sure it will be linked only to the main 63 // launcher. 64 65 PackageTest packageTest = new PackageTest().configureHelloApp(); 66 packageTest.addInitializer(cmd -> { 67 cmd.addArguments("--arguments", "Duke", "--arguments", "is", 68 "--arguments", "the", "--arguments", "King"); 69 }); 70 71 new FileAssociations( 72 MethodHandles.lookup().lookupClass().getSimpleName()).applyTo( 73 packageTest); 74 75 new AdditionalLauncher("Baz2").setArguments().applyTo(packageTest); 76 new AdditionalLauncher("foo").setArguments("yep!").applyTo(packageTest); 77 78 AdditionalLauncher barLauncher = new AdditionalLauncher("Bar").setArguments( 79 "one", "two", "three"); 80 if (TKit.isLinux()) { 81 barLauncher.setIcon(TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png")); 82 } 83 barLauncher.applyTo(packageTest); 84 85 packageTest.run(); 86 } 87 88 private static Path replaceFileName(Path path, String newFileName) { 89 String fname = path.getFileName().toString(); 90 int lastDotIndex = fname.lastIndexOf("."); 91 if (lastDotIndex != -1) { 92 fname = newFileName + fname.substring(lastDotIndex); 93 } else { 94 fname = newFileName; 95 } 96 return path.getParent().resolve(fname); 97 } 98 99 static class AdditionalLauncher { 100 101 AdditionalLauncher(String name) { 102 this.name = name; 103 } 104 105 AdditionalLauncher setArguments(String... args) { 106 arguments = List.of(args); 107 return this; 108 } 109 110 AdditionalLauncher setIcon(Path iconPath) { 111 icon = iconPath; 112 return this; 113 } 114 115 void applyTo(PackageTest test) { 116 final Path propsFile = TKit.workDir().resolve(name + ".properties"); 117 118 test.addInitializer(cmd -> { 119 cmd.addArguments("--add-launcher", String.format("%s=%s", name, 120 propsFile)); 121 122 Map<String, String> properties = new HashMap<>(); 123 if (arguments != null) { 124 properties.put("arguments", String.join(" ", 125 arguments.toArray(String[]::new))); 126 } 127 128 if (icon != null) { 129 properties.put("icon", icon.toAbsolutePath().toString()); 130 } 131 132 TKit.createPropertiesFile(propsFile, properties); 133 }); 134 test.addInstallVerifier(cmd -> { 135 Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); 136 137 TKit.assertExecutableFileExists(launcherPath); 138 139 if (cmd.isFakeRuntime(String.format( 140 "Not running %s launcher", launcherPath))) { 141 return; 142 } 143 HelloApp.executeAndVerifyOutput(launcherPath, 144 Optional.ofNullable(arguments).orElse(List.of()).toArray( 145 String[]::new)); 146 }); 147 test.addUninstallVerifier(cmd -> { 148 Path launcherPath = replaceFileName(cmd.appLauncherPath(), name); 149 150 TKit.assertPathExists(launcherPath, false); 151 }); 152 } 153 154 private List<String> arguments; 155 private Path icon; 156 private final String name; 157 } 158 } | 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.file.Path; 25 import java.util.HashMap; 26 import java.util.Map; 27 import java.util.List; 28 import java.util.Optional; 29 import java.lang.invoke.MethodHandles; 30 import jdk.jpackage.test.*; 31 import jdk.jpackage.test.Annotations.*; 32 33 /** 34 * Test --add-launcher parameter. Output of the test should be 35 * additionallauncherstest*.* installer. The output installer should provide the 36 * same functionality as the default installer (see description of the default 37 * installer in SimplePackageTest.java) plus install three extra application 38 * launchers. 39 */ 40 41 /* 42 * @test 43 * @summary jpackage with --add-launcher 44 * @key jpackagePlatformPackage 45 * @requires (jpackage.test.SQETest != null) 46 * @library ../helpers 47 * @build jdk.jpackage.test.* 48 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal 49 * @compile AdditionalLaunchersTest.java 50 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main 51 * --jpt-run=AdditionalLaunchersTest.test 52 */ 53 54 /* 55 * @test 56 * @summary jpackage with --add-launcher 57 * @key jpackagePlatformPackage 58 * @requires (jpackage.test.SQETest == null) 59 * @library ../helpers 60 * @build jdk.jpackage.test.* 61 * @modules jdk.jpackage/jdk.jpackage.internal 62 * @compile AdditionalLaunchersTest.java 63 * @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main 64 * --jpt-run=AdditionalLaunchersTest 65 */ 66 67 public class AdditionalLaunchersTest { 68 69 @Test 70 public void test() { 71 // Configure a bunch of additional launchers and also setup 72 // file association to make sure it will be linked only to the main 73 // launcher. 74 75 PackageTest packageTest = new PackageTest().configureHelloApp(); 76 packageTest.addInitializer(cmd -> { 77 cmd.addArguments("--arguments", "Duke", "--arguments", "is", 78 "--arguments", "the", "--arguments", "King"); 79 }); 80 81 new FileAssociations( 82 MethodHandles.lookup().lookupClass().getSimpleName()).applyTo( 83 packageTest); 84 85 new AdditionalLauncher("Baz2") 86 .setDefaultArguments() 87 .applyTo(packageTest); 88 89 new AdditionalLauncher("foo") 90 .setDefaultArguments("yep!") 91 .applyTo(packageTest); 92 93 new AdditionalLauncher("Bar") 94 .setDefaultArguments("one", "two", "three") 95 .setIcon(GOLDEN_ICON) 96 .applyTo(packageTest); 97 98 packageTest.run(); 99 } 100 101 @Test 102 public void bug8230933() { 103 PackageTest packageTest = new PackageTest().configureHelloApp(); 104 105 new AdditionalLauncher("default_icon") 106 .applyTo(packageTest); 107 108 new AdditionalLauncher("no_icon") 109 .setNoIcon().applyTo(packageTest); 110 111 new AdditionalLauncher("custom_icon") 112 .setIcon(GOLDEN_ICON) 113 .applyTo(packageTest); 114 115 packageTest.run(); 116 } 117 118 @Test 119 // Regular app 120 @Parameter("Hello") 121 // Modular app 122 @Parameter("com.other/com.other.CiaoBella") 123 public void testJavaOptions(String javaAppDesc) { 124 JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc) 125 .addArguments("--arguments", "courageous") 126 .addArguments("--java-options", "-Dparam1=xxx") 127 .addArguments("--java-options", "-Dparam2=yyy") 128 .addArguments("--java-options", "-Dparam3=zzz"); 129 130 new AdditionalLauncher("Jack") 131 .addDefaultArguments("Jack of All Trades", "Master of None") 132 .setJavaOptions("-Dparam1=Contractor") 133 .applyTo(cmd); 134 135 new AdditionalLauncher("Monday") 136 .addDefaultArguments("Knock Your", "Socks Off") 137 .setJavaOptions("-Dparam2=Surprise workers!") 138 .applyTo(cmd); 139 140 // Should inherit default arguments and java options from the main launcher 141 new AdditionalLauncher("void").applyTo(cmd); 142 143 cmd.executeAndAssertHelloAppImageCreated(); 144 } 145 146 /** 147 * Test usage of modular and non modular apps in additional launchers. 148 */ 149 @Test 150 @Parameter("true") 151 @Parameter("fase") 152 public void testMainLauncherIsModular(boolean mainLauncherIsModular) { 153 final var nonModularAppDesc = JavaAppDesc.parse("a.b.c.Hello"); 154 final var modularAppDesc = JavaAppDesc.parse( 155 "module.jar:com.that/com.that.main.Florence"); 156 157 final var nonModularJarCmd = JPackageCommand.helloAppImage(nonModularAppDesc); 158 final var modularJarCmd = JPackageCommand.helloAppImage(modularAppDesc); 159 160 final JPackageCommand cmd; 161 if (mainLauncherIsModular) { 162 // Create non modular jar. 163 nonModularJarCmd.executePrerequisiteActions(); 164 165 cmd = modularJarCmd; 166 cmd.addArguments("--description", 167 "Test modular app with multiple add-launchers where one is modular app and other is non modular app"); 168 cmd.addArguments("--input", nonModularJarCmd.getArgumentValue( 169 "--input")); 170 } else { 171 // Create modular jar. 172 modularJarCmd.executePrerequisiteActions(); 173 174 cmd = nonModularJarCmd; 175 cmd.addArguments("--description", 176 "Test non modular app with multiple add-launchers where one is modular app and other is non modular app"); 177 cmd.addArguments("--module-path", modularJarCmd.getArgumentValue( 178 "--module-path")); 179 cmd.addArguments("--add-modules", modularAppDesc.moduleName()); 180 } 181 182 new AdditionalLauncher("ModularAppLauncher") 183 .addRawProperties(Map.entry("module", JavaAppDesc.parse( 184 modularAppDesc.toString()).setJarFileName(null).toString())) 185 .addRawProperties(Map.entry("main-jar", "")) 186 .applyTo(cmd); 187 188 new AdditionalLauncher("NonModularAppLauncher") 189 // Use space ( ) character instead of equality sign (=) as 190 // a key/value separator 191 .setPersistenceHandler((path, properties) -> TKit.createTextFile(path, 192 properties.stream().map(entry -> String.join(" ", entry.getKey(), 193 entry.getValue())))) 194 .addRawProperties(Map.entry("main-class", nonModularAppDesc.className())) 195 .addRawProperties(Map.entry("main-jar", nonModularAppDesc.jarFileName())) 196 .applyTo(cmd); 197 198 cmd.executeAndAssertHelloAppImageCreated(); 199 } 200 201 private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( 202 "resources", "icon" + TKit.ICON_SUFFIX)); 203 } |