Skip to content

Commit

Permalink
8231591: [TESTBUG] Create additional two phase jpackage tests
Browse files Browse the repository at this point in the history
Reviewed-by: asemenyuk, herrick
  • Loading branch information
Alexander Matveev committed Sep 25, 2020
1 parent b159e4e commit 5a57945
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.imageio.ImageIO;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import jdk.incubator.jpackage.internal.Arguments.CLIOptions;
import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.DEFAULT_ICON;
import static jdk.incubator.jpackage.internal.LinuxAppImageBuilder.ICON_PNG;
import static jdk.incubator.jpackage.internal.OverridableResource.createResource;
Expand All @@ -54,6 +55,7 @@
import static jdk.incubator.jpackage.internal.StandardBundlerParam.DESCRIPTION;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.FILE_ASSOCIATIONS;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.ICON;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;

/**
* Helper to create files for desktop integration.
Expand Down Expand Up @@ -133,12 +135,32 @@ private DesktopIntegration(PlatformPackage thePackage,
createDataForDesktopFile(params));

nestedIntegrations = new ArrayList<>();
for (var launcherParams : launchers) {
launcherParams = AddLauncherArguments.merge(params, launcherParams,
// Read launchers information from predefine app image
if (launchers.isEmpty() &&
PREDEFINED_APP_IMAGE.fetchFrom(params) != null) {
List<String> launcherPaths = AppImageFile.getLauncherNames(
PREDEFINED_APP_IMAGE.fetchFrom(params), params);
if (!launcherPaths.isEmpty()) {
launcherPaths.remove(0); // Remove main launcher
}
for (var launcherPath : launcherPaths) {
Map<String, ? super Object> launcherParams = new HashMap<>();
Arguments.putUnlessNull(launcherParams, CLIOptions.NAME.getId(),
launcherPath);
launcherParams = AddLauncherArguments.merge(params, launcherParams,
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
FILE_ASSOCIATIONS.getID());
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
FILE_ASSOCIATIONS.getID(), PREDEFINED_APP_IMAGE.getID());
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
}
} else {
for (var launcherParams : launchers) {
launcherParams = AddLauncherArguments.merge(params, launcherParams,
ICON.getID(), ICON_PNG.getID(), ADD_LAUNCHERS.getID(),
FILE_ASSOCIATIONS.getID());
nestedIntegrations.add(new DesktopIntegration(thePackage,
launcherParams, params));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.stream.Stream;
import jdk.incubator.jpackage.internal.ApplicationLayout;
import jdk.jpackage.test.Functional.ThrowingBiConsumer;

public final class AdditionalLauncher {
Expand Down Expand Up @@ -110,6 +111,7 @@ public void applyTo(JPackageCommand cmd) {
}

public void applyTo(PackageTest test) {
test.addLauncherName(name);
test.addInitializer(this::initialize);
test.addInstallVerifier(this::verify);
}
Expand Down
20 changes: 18 additions & 2 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ public PackageTest configureHelloApp(String javaAppDesc) {
return this;
}

public PackageTest addLauncherName(String name) {
launcherNames.add(name);
return this;
}

public final static class Group extends RunnablePackageTest {
public Group(PackageTest... tests) {
handlers = Stream.of(tests)
Expand Down Expand Up @@ -556,7 +561,12 @@ private void verifyPackageInstalled(JPackageCommand cmd) {
if (PackageType.WINDOWS.contains(cmd.packageType())
&& !cmd.isPackageUnpacked(
"Not verifying desktop integration")) {
new WindowsHelper.DesktopIntegrationVerifier(cmd);
// Check main launcher
new WindowsHelper.DesktopIntegrationVerifier(cmd, null);
// Check additional launchers
launcherNames.forEach(name -> {
new WindowsHelper.DesktopIntegrationVerifier(cmd, name);
});
}
}
cmd.assertAppLayout();
Expand All @@ -571,7 +581,12 @@ private void verifyPackageUninstalled(JPackageCommand cmd) {
TKit.assertPathExists(cmd.appLauncherPath(), false);

if (PackageType.WINDOWS.contains(cmd.packageType())) {
new WindowsHelper.DesktopIntegrationVerifier(cmd);
// Check main launcher
new WindowsHelper.DesktopIntegrationVerifier(cmd, null);
// Check additional launchers
launcherNames.forEach(name -> {
new WindowsHelper.DesktopIntegrationVerifier(cmd, name);
});
}
}

Expand Down Expand Up @@ -618,6 +633,7 @@ private static Map<PackageType, PackageHandlers> createDefaultPackageHandlers()
private Map<PackageType, Handler> handlers;
private Set<String> namedInitializers;
private Map<PackageType, PackageHandlers> packageHandlers;
private final List<String> launcherNames = new ArrayList();

private final static File BUNDLE_OUTPUT_DIR;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ private static boolean isUserLocalInstall(JPackageCommand cmd) {

static class DesktopIntegrationVerifier {

DesktopIntegrationVerifier(JPackageCommand cmd) {
DesktopIntegrationVerifier(JPackageCommand cmd, String name) {
cmd.verifyIsOfType(PackageType.WINDOWS);
this.cmd = cmd;
this.name = (name == null ? cmd.name() : name);
verifyStartMenuShortcut();
verifyDesktopShortcut();
verifyFileAssociationsRegistry();
}

private void verifyDesktopShortcut() {
boolean appInstalled = cmd.appLauncherPath().toFile().exists();
boolean appInstalled = cmd.appLauncherPath(name).toFile().exists();
if (cmd.hasArgument("--win-shortcut")) {
if (isUserLocalInstall(cmd)) {
verifyUserLocalDesktopShortcut(appInstalled);
Expand All @@ -159,7 +160,7 @@ private void verifyDesktopShortcut() {
}

private Path desktopShortcutPath() {
return Path.of(cmd.name() + ".lnk");
return Path.of(name + ".lnk");
}

private void verifyShortcut(Path path, boolean exists) {
Expand All @@ -183,7 +184,7 @@ private void verifyUserLocalDesktopShortcut(boolean exists) {
}

private void verifyStartMenuShortcut() {
boolean appInstalled = cmd.appLauncherPath().toFile().exists();
boolean appInstalled = cmd.appLauncherPath(name).toFile().exists();
if (cmd.hasArgument("--win-menu")) {
if (isUserLocalInstall(cmd)) {
verifyUserLocalStartMenuShortcut(appInstalled);
Expand All @@ -200,7 +201,7 @@ private void verifyStartMenuShortcut() {

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

private void verifyStartMenuShortcut(Path shortcutsRoot, boolean exists) {
Expand Down Expand Up @@ -228,7 +229,7 @@ private void verifyFileAssociationsRegistry() {
}

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

private final JPackageCommand cmd;
private final String name;
}

private static String queryRegistryValue(String keyPath, String valueName) {
Expand Down
92 changes: 92 additions & 0 deletions test/jdk/tools/jpackage/share/MultiLauncherTwoPhaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2020, 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.
*/

import java.nio.file.Path;
import java.io.IOException;
import jdk.jpackage.test.AdditionalLauncher;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.PackageType;
import jdk.jpackage.test.TKit;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.JPackageCommand;

/**
* Test multiple launchers in two phases. First test creates app image and then
* creates installer from this image. Output of the test should be
* MultiLauncherTwoPhaseTest*.* installer. The output installer should be basic
* installer with 3 launcher MultiLauncherTwoPhaseTest, bar and foo. On Windows
* we should have start menu integration under MultiLauncherTwoPhaseTest and
* desktop shortcuts for all 3 launchers. Linux should also create shortcuts for
* all launchers.
*/

/*
* @test
* @summary Multiple launchers in two phases
* @library ../helpers
* @library /test/lib
* @key jpackagePlatformPackage
* @build jdk.jpackage.test.*
* @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
* @compile MultiLauncherTwoPhaseTest.java
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=MultiLauncherTwoPhaseTest
*/

public class MultiLauncherTwoPhaseTest {

@Test
public static void test() throws IOException {
Path appimageOutput = TKit.createTempDirectory("appimage");

JPackageCommand appImageCmd = JPackageCommand.helloAppImage()
.setArgumentValue("--dest", appimageOutput);

AdditionalLauncher launcher1 = new AdditionalLauncher("bar");
launcher1.setDefaultArguments().applyTo(appImageCmd);

AdditionalLauncher launcher2 = new AdditionalLauncher("foo");
launcher2.applyTo(appImageCmd);

PackageTest packageTest = new PackageTest()
.addLauncherName("bar") // Add launchers name for verification
.addLauncherName("foo")
.addRunOnceInitializer(() -> appImageCmd.execute())
.addBundleDesktopIntegrationVerifier(true)
.addInitializer(cmd -> {
cmd.addArguments("--app-image", appImageCmd.outputBundle());
cmd.removeArgumentWithValue("--input");
})
.forTypes(PackageType.WINDOWS)
.addInitializer(cmd -> {
cmd.addArguments("--win-shortcut", "--win-menu",
"--win-menu-group", "MultiLauncherTwoPhaseTest");
})
.forTypes(PackageType.LINUX)
.addInitializer(cmd -> {
cmd.addArguments("--linux-shortcut");
});

packageTest.run();
}
}

1 comment on commit 5a57945

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 5a57945 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.