Path: blob/master/test/jdk/tools/jpackage/share/AddLauncherTest.java
41149 views
/*1* Copyright (c) 2018, 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.nio.file.Path;24import java.io.File;25import java.util.Map;26import java.lang.invoke.MethodHandles;27import jdk.jpackage.test.PackageTest;28import jdk.jpackage.test.FileAssociations;29import jdk.jpackage.test.AdditionalLauncher;30import jdk.jpackage.test.JPackageCommand;31import jdk.jpackage.test.JavaAppDesc;32import jdk.jpackage.test.TKit;33import jdk.jpackage.test.Annotations.Test;34import jdk.jpackage.test.Annotations.Parameter;35import jdk.jpackage.test.CfgFile;3637/**38* Test --add-launcher parameter. Output of the test should be39* AddLauncherTest*.* installer. The output installer should provide the40* same functionality as the default installer (see description of the default41* installer in SimplePackageTest.java) plus install three extra application42* launchers.43*/4445/*46* @test47* @summary jpackage with --add-launcher48* @key jpackagePlatformPackage49* @requires (jpackage.test.SQETest != null)50* @library ../helpers51* @build jdk.jpackage.test.*52* @modules jdk.jpackage/jdk.jpackage.internal53* @compile AddLauncherTest.java54* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main55* --jpt-run=AddLauncherTest.test56*/5758/*59* @test60* @summary jpackage with --add-launcher61* @key jpackagePlatformPackage62* @requires (jpackage.test.SQETest == null)63* @library ../helpers64* @build jdk.jpackage.test.*65* @modules jdk.jpackage/jdk.jpackage.internal66* @compile AddLauncherTest.java67* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main68* --jpt-run=AddLauncherTest69*/7071public class AddLauncherTest {7273@Test74public void test() {75// Configure a bunch of additional launchers and also setup76// file association to make sure it will be linked only to the main77// launcher.7879PackageTest packageTest = new PackageTest().configureHelloApp();80packageTest.addInitializer(cmd -> {81cmd.addArguments("--arguments", "Duke", "--arguments", "is",82"--arguments", "the", "--arguments", "King");83});8485new FileAssociations(86MethodHandles.lookup().lookupClass().getSimpleName()).applyTo(87packageTest);8889new AdditionalLauncher("Baz2")90.setDefaultArguments()91.applyTo(packageTest);9293new AdditionalLauncher("foo")94.setDefaultArguments("yep!")95.applyTo(packageTest);9697new AdditionalLauncher("Bar")98.setDefaultArguments("one", "two", "three")99.setIcon(GOLDEN_ICON)100.applyTo(packageTest);101102packageTest.run();103}104105@Test106public void bug8230933() {107PackageTest packageTest = new PackageTest().configureHelloApp();108109new AdditionalLauncher("default_icon")110.applyTo(packageTest);111112new AdditionalLauncher("no_icon")113.setNoIcon().applyTo(packageTest);114115new AdditionalLauncher("custom_icon")116.setIcon(GOLDEN_ICON)117.applyTo(packageTest);118119packageTest.run();120}121122@Test123// Regular app124@Parameter("Hello")125// Modular app126@Parameter("com.other/com.other.CiaoBella")127public void testJavaOptions(String javaAppDesc) {128JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc)129.addArguments("--arguments", "courageous")130.addArguments("--java-options", "-Dparam1=xxx")131.addArguments("--java-options", "-Dparam2=yyy")132.addArguments("--java-options", "-Dparam3=zzz");133134new AdditionalLauncher("Jack")135.addDefaultArguments("Jack of All Trades", "Master of None")136.setJavaOptions("-Dparam1=Contractor")137.applyTo(cmd);138139new AdditionalLauncher("Monday")140.addDefaultArguments("Knock Your", "Socks Off")141.setJavaOptions("-Dparam2=Surprise workers!")142.applyTo(cmd);143144// Should inherit default arguments and java options from the main launcher145new AdditionalLauncher("void").applyTo(cmd);146147cmd.executeAndAssertHelloAppImageCreated();148}149150/**151* Test usage of modular and non modular apps in additional launchers.152*/153@Test154@Parameter("true")155@Parameter("fase")156public void testMainLauncherIsModular(boolean mainLauncherIsModular) {157final var nonModularAppDesc = JavaAppDesc.parse("a.b.c.Hello");158final var modularAppDesc = JavaAppDesc.parse(159"module.jar:com.that/com.that.main.Florence");160161final var nonModularJarCmd = JPackageCommand.helloAppImage(nonModularAppDesc);162final var modularJarCmd = JPackageCommand.helloAppImage(modularAppDesc);163164final JPackageCommand cmd;165if (mainLauncherIsModular) {166// Create non modular jar.167nonModularJarCmd.executePrerequisiteActions();168169cmd = modularJarCmd;170cmd.addArguments("--description",171"Test modular app with multiple add-launchers where one is modular app and other is non modular app");172cmd.addArguments("--input", nonModularJarCmd.getArgumentValue(173"--input"));174} else {175// Create modular jar.176modularJarCmd.executePrerequisiteActions();177178cmd = nonModularJarCmd;179cmd.addArguments("--description",180"Test non modular app with multiple add-launchers where one is modular app and other is non modular app");181cmd.addArguments("--module-path", modularJarCmd.getArgumentValue(182"--module-path"));183cmd.addArguments("--add-modules", modularAppDesc.moduleName());184cmd.ignoreDefaultRuntime(true); // because of --add-modules185}186187new AdditionalLauncher("ModularAppLauncher")188.addRawProperties(Map.entry("module", JavaAppDesc.parse(189modularAppDesc.toString()).setBundleFileName(null).toString()))190.addRawProperties(Map.entry("main-jar", ""))191.applyTo(cmd);192193new AdditionalLauncher("NonModularAppLauncher")194// Use space ( ) character instead of equality sign (=) as195// a key/value separator196.setPersistenceHandler((path, properties) -> TKit.createTextFile(path,197properties.stream().map(entry -> String.join(" ", entry.getKey(),198entry.getValue()))))199.addRawProperties(Map.entry("main-class", nonModularAppDesc.className()))200.addRawProperties(Map.entry("main-jar", nonModularAppDesc.jarFileName()))201.applyTo(cmd);202203cmd.executeAndAssertHelloAppImageCreated();204205// check value of app.mainmodule in ModularAppLauncher's cfg file206CfgFile cfg = cmd.readLauncherCfgFile("ModularAppLauncher");207String moduleValue = cfg.getValue("Application", "app.mainmodule");208String mainClass = null;209String classpath = null;210String expectedMod = JavaAppDesc.parse(211modularAppDesc.toString()).setBundleFileName(null).toString();212TKit.assertEquals(expectedMod, moduleValue,213String.format("Check value of app.mainmodule=[%s]" +214"in ModularAppLauncher cfg file is as expected", expectedMod));215216// check values of app.mainclass and app.classpath in cfg file217cfg = cmd.readLauncherCfgFile("NonModularAppLauncher");218moduleValue = null;219mainClass = cfg.getValue("Application", "app.mainclass");220classpath = cfg.getValue("Application", "app.classpath");221String ExpectedCN = nonModularAppDesc.className();222TKit.assertEquals(ExpectedCN, mainClass,223String.format("Check value of app.mainclass=[%s]" +224"in NonModularAppLauncher cfg file is as expected", ExpectedCN));225TKit.assertTrue(classpath.startsWith("$APPDIR" + File.separator226+ nonModularAppDesc.jarFileName()),227"Check app.classpath value in ModularAppLauncher cfg file");228}229230private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of(231"resources", "icon" + TKit.ICON_SUFFIX));232}233234235