Skip to content

Commit 5a57945

Browse files
author
Alexander Matveev
committed
8231591: [TESTBUG] Create additional two phase jpackage tests
Reviewed-by: asemenyuk, herrick
1 parent b159e4e commit 5a57945

File tree

5 files changed

+147
-13
lines changed

5 files changed

+147
-13
lines changed

src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import javax.imageio.ImageIO;
4747
import javax.xml.stream.XMLStreamException;
4848
import javax.xml.stream.XMLStreamWriter;
49+
import jdk.incubator.jpackage.internal.Arguments.CLIOptions;
4950
import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.DEFAULT_ICON;
5051
import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.ICON_PNG;
5152
import static jdk.incubator.jpackage.internal.OverridableResource.createResource;
@@ -54,6 +55,7 @@
5455
import static jdk.incubator.jpackage.internal.StandardBundlerParam.DESCRIPTION;
5556
import static jdk.incubator.jpackage.internal.StandardBundlerParam.FILE_ASSOCIATIONS;
5657
import static jdk.incubator.jpackage.internal.StandardBundlerParam.ICON;
58+
import static jdk.incubator.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;
5759

5860
/**
5961
* Helper to create files for desktop integration.
@@ -133,12 +135,32 @@ private DesktopIntegration(PlatformPackage thePackage,
133135
createDataForDesktopFile(params));
134136

135137
nestedIntegrations = new ArrayList<>();
136-
for (var launcherParams : launchers) {
137-
launcherParams = AddLauncherArguments.merge(params, launcherParams,
138+
// Read launchers information from predefine app image
139+
if (launchers.isEmpty() &&
140+
PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
141+
List<String> launcherPaths = AppImageFile.getLauncherNames(
142+
PREDEFINED_APP_IMAGE.fetchFrom(params), params);
143+
if (!launcherPaths.isEmpty()) {
144+
launcherPaths.remove(0); // Remove main launcher
145+
}
146+
for (var launcherPath : launcherPaths) {
147+
Map<String, ? super Object> launcherParams = new HashMap<>();
148+
Arguments.putUnlessNull(launcherParams, CLIOptions.NAME.getId(),
149+
launcherPath);
150+
launcherParams = AddLauncherArguments.merge(params, launcherParams,
138151
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
139-
FILE_ASSOCIATIONS.getID());
140-
nestedIntegrations.add(new DesktopIntegration(thePackage,
141-
launcherParams, params));
152+
FILE_ASSOCIATIONS.getID(), PREDEFINED_APP_IMAGE.getID());
153+
nestedIntegrations.add(new DesktopIntegration(thePackage,
154+
launcherParams, params));
155+
}
156+
} else {
157+
for (var launcherParams : launchers) {
158+
launcherParams = AddLauncherArguments.merge(params, launcherParams,
159+
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
160+
FILE_ASSOCIATIONS.getID());
161+
nestedIntegrations.add(new DesktopIntegration(thePackage,
162+
launcherParams, params));
163+
}
142164
}
143165
}
144166

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AdditionalLauncher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Optional;
3333
import java.util.function.BiConsumer;
3434
import java.util.stream.Stream;
35+
import jdk.incubator.jpackage.internal.ApplicationLayout;
3536
import jdk.jpackage.test.Functional.ThrowingBiConsumer;
3637

3738
public final class AdditionalLauncher {
@@ -110,6 +111,7 @@ public void applyTo(JPackageCommand cmd) {
110111
}
111112

112113
public void applyTo(PackageTest test) {
114+
test.addLauncherName(name);
113115
test.addInitializer(this::initialize);
114116
test.addInstallVerifier(this::verify);
115117
}

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ public PackageTest configureHelloApp(String javaAppDesc) {
317317
return this;
318318
}
319319

320+
public PackageTest addLauncherName(String name) {
321+
launcherNames.add(name);
322+
return this;
323+
}
324+
320325
public final static class Group extends RunnablePackageTest {
321326
public Group(PackageTest... tests) {
322327
handlers = Stream.of(tests)
@@ -556,7 +561,12 @@ private void verifyPackageInstalled(JPackageCommand cmd) {
556561
if (PackageType.WINDOWS.contains(cmd.packageType())
557562
&& !cmd.isPackageUnpacked(
558563
"Not verifying desktop integration")) {
559-
new WindowsHelper.DesktopIntegrationVerifier(cmd);
564+
// Check main launcher
565+
new WindowsHelper.DesktopIntegrationVerifier(cmd, null);
566+
// Check additional launchers
567+
launcherNames.forEach(name -> {
568+
new WindowsHelper.DesktopIntegrationVerifier(cmd, name);
569+
});
560570
}
561571
}
562572
cmd.assertAppLayout();
@@ -571,7 +581,12 @@ private void verifyPackageUninstalled(JPackageCommand cmd) {
571581
TKit.assertPathExists(cmd.appLauncherPath(), false);
572582

573583
if (PackageType.WINDOWS.contains(cmd.packageType())) {
574-
new WindowsHelper.DesktopIntegrationVerifier(cmd);
584+
// Check main launcher
585+
new WindowsHelper.DesktopIntegrationVerifier(cmd, null);
586+
// Check additional launchers
587+
launcherNames.forEach(name -> {
588+
new WindowsHelper.DesktopIntegrationVerifier(cmd, name);
589+
});
575590
}
576591
}
577592

@@ -618,6 +633,7 @@ private static Map<PackageType, PackageHandlers> createDefaultPackageHandlers()
618633
private Map<PackageType, Handler> handlers;
619634
private Set<String> namedInitializers;
620635
private Map<PackageType, PackageHandlers> packageHandlers;
636+
private final List<String> launcherNames = new ArrayList();
621637

622638
private final static File BUNDLE_OUTPUT_DIR;
623639

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,17 @@ private static boolean isUserLocalInstall(JPackageCommand cmd) {
134134

135135
static class DesktopIntegrationVerifier {
136136

137-
DesktopIntegrationVerifier(JPackageCommand cmd) {
137+
DesktopIntegrationVerifier(JPackageCommand cmd, String name) {
138138
cmd.verifyIsOfType(PackageType.WINDOWS);
139139
this.cmd = cmd;
140+
this.name = (name == null ? cmd.name() : name);
140141
verifyStartMenuShortcut();
141142
verifyDesktopShortcut();
142143
verifyFileAssociationsRegistry();
143144
}
144145

145146
private void verifyDesktopShortcut() {
146-
boolean appInstalled = cmd.appLauncherPath().toFile().exists();
147+
boolean appInstalled = cmd.appLauncherPath(name).toFile().exists();
147148
if (cmd.hasArgument("--win-shortcut")) {
148149
if (isUserLocalInstall(cmd)) {
149150
verifyUserLocalDesktopShortcut(appInstalled);
@@ -159,7 +160,7 @@ private void verifyDesktopShortcut() {
159160
}
160161

161162
private Path desktopShortcutPath() {
162-
return Path.of(cmd.name() + ".lnk");
163+
return Path.of(name + ".lnk");
163164
}
164165

165166
private void verifyShortcut(Path path, boolean exists) {
@@ -183,7 +184,7 @@ private void verifyUserLocalDesktopShortcut(boolean exists) {
183184
}
184185

185186
private void verifyStartMenuShortcut() {
186-
boolean appInstalled = cmd.appLauncherPath().toFile().exists();
187+
boolean appInstalled = cmd.appLauncherPath(name).toFile().exists();
187188
if (cmd.hasArgument("--win-menu")) {
188189
if (isUserLocalInstall(cmd)) {
189190
verifyUserLocalStartMenuShortcut(appInstalled);
@@ -200,7 +201,7 @@ private void verifyStartMenuShortcut() {
200201

201202
private Path startMenuShortcutPath() {
202203
return Path.of(cmd.getArgumentValue("--win-menu-group",
203-
() -> "Unknown"), cmd.name() + ".lnk");
204+
() -> "Unknown"), name + ".lnk");
204205
}
205206

206207
private void verifyStartMenuShortcut(Path shortcutsRoot, boolean exists) {
@@ -228,7 +229,7 @@ private void verifyFileAssociationsRegistry() {
228229
}
229230

230231
private void verifyFileAssociationsRegistry(Path faFile) {
231-
boolean appInstalled = cmd.appLauncherPath().toFile().exists();
232+
boolean appInstalled = cmd.appLauncherPath(name).toFile().exists();
232233
try {
233234
TKit.trace(String.format(
234235
"Get file association properties from [%s] file",
@@ -279,6 +280,7 @@ private void verifyFileAssociations(boolean exists, String suffix,
279280
}
280281

281282
private final JPackageCommand cmd;
283+
private final String name;
282284
}
283285

284286
private static String queryRegistryValue(String keyPath, String valueName) {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.file.Path;
25+
import java.io.IOException;
26+
import jdk.jpackage.test.AdditionalLauncher;
27+
import jdk.jpackage.test.PackageTest;
28+
import jdk.jpackage.test.PackageType;
29+
import jdk.jpackage.test.TKit;
30+
import jdk.jpackage.test.Annotations.Test;
31+
import jdk.jpackage.test.JPackageCommand;
32+
33+
/**
34+
* Test multiple launchers in two phases. First test creates app image and then
35+
* creates installer from this image. Output of the test should be
36+
* MultiLauncherTwoPhaseTest*.* installer. The output installer should be basic
37+
* installer with 3 launcher MultiLauncherTwoPhaseTest, bar and foo. On Windows
38+
* we should have start menu integration under MultiLauncherTwoPhaseTest and
39+
* desktop shortcuts for all 3 launchers. Linux should also create shortcuts for
40+
* all launchers.
41+
*/
42+
43+
/*
44+
* @test
45+
* @summary Multiple launchers in two phases
46+
* @library ../helpers
47+
* @library /test/lib
48+
* @key jpackagePlatformPackage
49+
* @build jdk.jpackage.test.*
50+
* @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
51+
* @compile MultiLauncherTwoPhaseTest.java
52+
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
53+
* --jpt-run=MultiLauncherTwoPhaseTest
54+
*/
55+
56+
public class MultiLauncherTwoPhaseTest {
57+
58+
@Test
59+
public static void test() throws IOException {
60+
Path appimageOutput = TKit.createTempDirectory("appimage");
61+
62+
JPackageCommand appImageCmd = JPackageCommand.helloAppImage()
63+
.setArgumentValue("--dest", appimageOutput);
64+
65+
AdditionalLauncher launcher1 = new AdditionalLauncher("bar");
66+
launcher1.setDefaultArguments().applyTo(appImageCmd);
67+
68+
AdditionalLauncher launcher2 = new AdditionalLauncher("foo");
69+
launcher2.applyTo(appImageCmd);
70+
71+
PackageTest packageTest = new PackageTest()
72+
.addLauncherName("bar") // Add launchers name for verification
73+
.addLauncherName("foo")
74+
.addRunOnceInitializer(() -> appImageCmd.execute())
75+
.addBundleDesktopIntegrationVerifier(true)
76+
.addInitializer(cmd -> {
77+
cmd.addArguments("--app-image", appImageCmd.outputBundle());
78+
cmd.removeArgumentWithValue("--input");
79+
})
80+
.forTypes(PackageType.WINDOWS)
81+
.addInitializer(cmd -> {
82+
cmd.addArguments("--win-shortcut", "--win-menu",
83+
"--win-menu-group", "MultiLauncherTwoPhaseTest");
84+
})
85+
.forTypes(PackageType.LINUX)
86+
.addInitializer(cmd -> {
87+
cmd.addArguments("--linux-shortcut");
88+
});
89+
90+
packageTest.run();
91+
}
92+
}

0 commit comments

Comments
 (0)