/* * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Test --add-launcher parameter. Output of the test should be * AddLauncherTest*.* installer. The output installer should provide the * same functionality as the default installer (see description of the default * installer in SimplePackageTest.java) plus install three extra application * launchers with unique description ("LauncherName Description").
*/
@Test publicvoid test() { // Configure a bunch of additional launchers and also setup // file association to make sure it will be linked only to the main // launcher.
final JPackageCommand cmd; if (mainLauncherIsModular) { // Create non modular jar.
nonModularJarCmd.executePrerequisiteActions();
cmd = modularJarCmd;
cmd.addArguments("--description", "Test modular app with multiple add-launchers where one is modular app and other is non modular app");
cmd.addArguments("--input", nonModularJarCmd.getArgumentValue( "--input"));
} else { // Create modular jar.
modularJarCmd.executePrerequisiteActions();
cmd = nonModularJarCmd;
cmd.addArguments("--description", "Test non modular app with multiple add-launchers where one is modular app and other is non modular app");
cmd.addArguments("--module-path", modularJarCmd.getArgumentValue( "--module-path"));
cmd.addArguments("--add-modules", modularAppDesc.moduleName());
cmd.ignoreDefaultRuntime(true); // because of --add-modules
}
final String expectedMod = JavaAppDesc.parse(modularAppDesc.toString())
.setBundleFileName(null)
.setSrcJavaPath(null)
.toString();
new AdditionalLauncher("ModularAppLauncher")
.addRawProperties(Map.entry("module", expectedMod))
.addRawProperties(Map.entry("main-jar", ""))
.applyTo(cmd);
new AdditionalLauncher("NonModularAppLauncher") // Use space ( ) character instead of equality sign (=) as // a key/value separator
.setPersistenceHandler((path, properties) -> TKit.createTextFile(path,
properties.stream().map(entry -> String.join(" ", entry.getKey(),
entry.getValue()))))
.addRawProperties(Map.entry("main-class", nonModularAppDesc.className()))
.addRawProperties(Map.entry("main-jar", nonModularAppDesc.jarFileName()))
.applyTo(cmd);
cmd.executeAndAssertHelloAppImageCreated();
// check value of app.mainmodule in ModularAppLauncher's cfg file
CfgFile cfg = cmd.readLauncherCfgFile("ModularAppLauncher");
String moduleValue = cfg.getValue("Application", "app.mainmodule");
String mainClass = null;
String classpath = null;
TKit.assertEquals(expectedMod, moduleValue,
String.format("Check value of app.mainmodule=[%s]" + "in ModularAppLauncher cfg file is as expected", expectedMod));
// check values of app.mainclass and app.classpath in cfg file
cfg = cmd.readLauncherCfgFile("NonModularAppLauncher");
moduleValue = null;
mainClass = cfg.getValue("Application", "app.mainclass");
classpath = cfg.getValue("Application", "app.classpath");
String ExpectedCN = nonModularAppDesc.className();
TKit.assertEquals(ExpectedCN, mainClass,
String.format("Check value of app.mainclass=[%s]" + "in NonModularAppLauncher cfg file is as expected", ExpectedCN));
TKit.assertTrue(classpath.startsWith("$APPDIR" + File.separator
+ nonModularAppDesc.jarFileName()), "Check app.classpath value in ModularAppLauncher cfg file");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.