8231591: [TESTBUG] Create additional two phase jpackage tests

Reviewed-by: asemenyuk, herrick
This commit is contained in:
Alexander Matveev 2020-09-25 23:02:00 +00:00
parent b159e4ed9e
commit 5a57945f1a
5 changed files with 147 additions and 13 deletions

View File

@ -46,6 +46,7 @@ import java.util.stream.Stream;
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;
@ -54,6 +55,7 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.APP_NAME;
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.
@ -133,12 +135,32 @@ final class DesktopIntegration {
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));
}
}
}

View File

@ -32,6 +32,7 @@ import java.util.Map;
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 {
@ -110,6 +111,7 @@ public final class AdditionalLauncher {
}
public void applyTo(PackageTest test) {
test.addLauncherName(name);
test.addInitializer(this::initialize);
test.addInstallVerifier(this::verify);
}

View File

@ -317,6 +317,11 @@ public final class PackageTest extends RunnablePackageTest {
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)
@ -556,7 +561,12 @@ public final class PackageTest extends RunnablePackageTest {
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();
@ -571,7 +581,12 @@ public final class PackageTest extends RunnablePackageTest {
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);
});
}
}
@ -618,6 +633,7 @@ public final class PackageTest extends RunnablePackageTest {
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;

View File

@ -134,16 +134,17 @@ public class WindowsHelper {
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);
@ -159,7 +160,7 @@ public class WindowsHelper {
}
private Path desktopShortcutPath() {
return Path.of(cmd.name() + ".lnk");
return Path.of(name + ".lnk");
}
private void verifyShortcut(Path path, boolean exists) {
@ -183,7 +184,7 @@ public class WindowsHelper {
}
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);
@ -200,7 +201,7 @@ public class WindowsHelper {
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) {
@ -228,7 +229,7 @@ public class WindowsHelper {
}
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",
@ -279,6 +280,7 @@ public class WindowsHelper {
}
private final JPackageCommand cmd;
private final String name;
}
private static String queryRegistryValue(String keyPath, String valueName) {

View File

@ -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();
}
}