Skip to content

Commit

Permalink
8236127: Use value of --icon CLI option to set icon for exe installers
Browse files Browse the repository at this point in the history
Reviewed-by: almatvee, herrick
  • Loading branch information
Alexey Semenyuk committed Apr 8, 2021
1 parent 81d35e4 commit 5bd6c74
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 34 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
Expand Down Expand Up @@ -70,14 +70,14 @@ enum USE {
options.put(CLIOptions.VENDOR.getId(), USE.ALL);
options.put(CLIOptions.COPYRIGHT.getId(), USE.ALL);
options.put(CLIOptions.PACKAGE_TYPE.getId(), USE.ALL);
options.put(CLIOptions.ICON.getId(), USE.ALL);

options.put(CLIOptions.INPUT.getId(), USE.LAUNCHER);
options.put(CLIOptions.MODULE.getId(), USE.LAUNCHER);
options.put(CLIOptions.MODULE_PATH.getId(), USE.LAUNCHER);
options.put(CLIOptions.ADD_MODULES.getId(), USE.LAUNCHER);
options.put(CLIOptions.MAIN_JAR.getId(), USE.LAUNCHER);
options.put(CLIOptions.APPCLASS.getId(), USE.LAUNCHER);
options.put(CLIOptions.ICON.getId(), USE.LAUNCHER);
options.put(CLIOptions.ARGUMENTS.getId(), USE.LAUNCHER);
options.put(CLIOptions.JAVA_OPTIONS.getId(), USE.LAUNCHER);
options.put(CLIOptions.ADD_LAUNCHER.getId(), USE.LAUNCHER);
Expand Down
Expand Up @@ -70,6 +70,9 @@ Generic Options:\n\
\ --help -h \n\
\ Print the usage text with a list and description of each valid\n\
\ option for the current platform to the output stream, and exit\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --name -n <name>\n\
\ Name of the application and/or package\n\
\ --dest -d <destination path>\n\
Expand Down Expand Up @@ -120,9 +123,6 @@ Generic Options:\n\
\ --strip-native-commands.\n\
\n\
\Options for creating the application image:\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --input -i <input path>\n\
\ Path of the input directory that contains the files to be packaged\n\
\ (absolute path or relative to the current directory)\n\
Expand Down
Expand Up @@ -70,6 +70,9 @@ Generic Options:\n\
\ --help -h \n\
\ Print the usage text with a list and description of each valid\n\
\ option for the current platform to the output stream, and exit\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --name -n <name>\n\
\ Name of the application and/or package\n\
\ --dest -d <destination path>\n\
Expand Down Expand Up @@ -120,9 +123,6 @@ Generic Options:\n\
\ --strip-native-commands.\n\
\n\
\Options for creating the application image:\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --input -i <input path>\n\
\ Path of the input directory that contains the files to be packaged\n\
\ (absolute path or relative to the current directory)\n\
Expand Down
Expand Up @@ -70,6 +70,9 @@ Generic Options:\n\
\ --help -h \n\
\ Print the usage text with a list and description of each valid\n\
\ option for the current platform to the output stream, and exit\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --name -n <name>\n\
\ Name of the application and/or package\n\
\ --dest -d <destination path>\n\
Expand Down Expand Up @@ -120,9 +123,6 @@ Generic Options:\n\
\ --strip-native-commands.\n\
\n\
\Options for creating the application image:\n\
\ --icon <icon file path>\n\
\ Path of the icon of the application package\n\
\ (absolute path or relative to the current directory)\n\
\ --input -i <input path>\n\
\ Path of the input directory that contains the files to be packaged\n\
\ (absolute path or relative to the current directory)\n\
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, 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
Expand Down Expand Up @@ -38,13 +38,15 @@
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.function.Supplier;
import static jdk.jpackage.internal.OverridableResource.createResource;
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
import static jdk.jpackage.internal.StandardBundlerParam.COPYRIGHT;
import static jdk.jpackage.internal.StandardBundlerParam.DESCRIPTION;
import static jdk.jpackage.internal.StandardBundlerParam.TEMP_ROOT;
import static jdk.jpackage.internal.StandardBundlerParam.VENDOR;
import static jdk.jpackage.internal.StandardBundlerParam.VERSION;
import static jdk.jpackage.internal.WindowsAppImageBuilder.ICON_ICO;


final class ExecutableRebrander {
Expand All @@ -63,34 +65,38 @@ final class ExecutableRebrander {

void rebrandInstaller(Map<String, ? super Object> params, Path target)
throws IOException {
if (!target.isAbsolute()) {
rebrandInstaller(params, target.toAbsolutePath());
return;
}
rebrandExecutable(params, target, (resourceLock) -> {
rebrandProperties(resourceLock, createResource(
INSTALLER_PROPERTIES_TEMPLATE, params).setPublicName(
INSTALLER_PROPERTIES_RESOURE_DIR_ID),
createSubstituteData(params), target);
});
Path icon = ICON_ICO.fetchFrom(params);
rebrandExecutable(params, icon, () -> {
return createResource(INSTALLER_PROPERTIES_TEMPLATE, params).setPublicName(
INSTALLER_PROPERTIES_RESOURE_DIR_ID);
}, target);
}

void rebrandLauncher(Map<String, ? super Object> params, Path icon,
Path target) throws IOException {
rebrandExecutable(params, icon, () -> {
return createResource(
LAUNCHER_PROPERTIES_TEMPLATE, params).setPublicName(
APP_NAME.fetchFrom(params) + ".properties");
}, target);
}

private void rebrandExecutable(Map<String, ? super Object> params, Path icon,
Supplier<OverridableResource> resourceSupplier, Path target) throws
IOException {
if (!target.isAbsolute() || (icon != null && !icon.isAbsolute())) {
Path absIcon = null;
if (icon != null) {
absIcon = icon.toAbsolutePath();
}
rebrandLauncher(params, absIcon, target.toAbsolutePath());
rebrandExecutable(params, absIcon, resourceSupplier,
target.toAbsolutePath());
return;
}
rebrandExecutable(params, target, (resourceLock) -> {
rebrandProperties(resourceLock, createResource(
LAUNCHER_PROPERTIES_TEMPLATE, params).setPublicName(
APP_NAME.fetchFrom(params) + ".properties"),
createSubstituteData(params), target);

rebrandProperties(resourceLock, resourceSupplier.get(),
createSubstituteData(
params), target);
if (icon != null) {
iconSwap(resourceLock, icon.toString());
}
Expand Down
Expand Up @@ -282,8 +282,8 @@ static void verifyPackageBundleEssential(JPackageCommand cmd) {
actualCriticalRuntimePaths);
} else {
// AppImagePackageTest.testEmpty() will have no dependencies,
// but will have more then 0 and less than 1K content size.
checkPrerequisites = packageSize > 1;
// but will have more then 0 and less than 5K content size when --icon is used.
checkPrerequisites = packageSize > 5;
}

List<String> prerequisites = LinuxHelper.getPrerequisitePackages(cmd);
Expand Down
18 changes: 14 additions & 4 deletions test/jdk/tools/jpackage/share/AppImagePackageTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
Expand All @@ -25,10 +25,10 @@
import java.nio.file.Files;
import java.io.IOException;
import java.util.List;
import jdk.jpackage.test.Annotations.Parameter;
import jdk.jpackage.test.TKit;
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.PackageType;
import jdk.jpackage.test.RunnablePackageTest.Action;
import jdk.jpackage.test.Annotations.Test;

Expand Down Expand Up @@ -68,7 +68,9 @@ public static void test() {
}

@Test
public static void testEmpty() throws IOException {
@Parameter("true")
@Parameter("false")
public static void testEmpty(boolean withIcon) throws IOException {
final String name = "EmptyAppImagePackageTest";
final String imageName = name + (TKit.isOSX() ? ".app" : "");
Path appImageDir = TKit.createTempDirectory(null).resolve(imageName);
Expand All @@ -81,14 +83,22 @@ public static void testEmpty() throws IOException {
new PackageTest()
.addInitializer(cmd -> {
cmd.addArguments("--app-image", appImageDir);
if (withIcon) {
cmd.addArguments("--icon", iconPath("icon"));
}
cmd.removeArgumentWithValue("--input");

// on mac, with --app-image and without --mac-package-identifier,
// will try to infer it from the image, so foreign image needs it.
if (TKit.isOSX()) {
cmd.addArguments("--mac-package-identifier", name);
}
}).run(new Action[] { Action.CREATE, Action.UNPACK });
}).run(Action.CREATE, Action.UNPACK);
// default: {CREATE, UNPACK, VERIFY}, but we can't verify foreign image
}

private static Path iconPath(String name) {
return TKit.TEST_SRC_ROOT.resolve(Path.of("resources", name
+ TKit.ICON_SUFFIX));
}
}

1 comment on commit 5bd6c74

@openjdk-notifier
Copy link

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.