Skip to content

Commit

Permalink
8220266: add support for additional metadata in add/remove programs
Browse files Browse the repository at this point in the history
Reviewed-by: herrick, almatvee
  • Loading branch information
Alexey Semenyuk committed Mar 24, 2021
1 parent 37f494c commit 3d7f912
Show file tree
Hide file tree
Showing 9 changed files with 573 additions and 10 deletions.
Expand Up @@ -198,6 +198,8 @@ public enum CLIOptions {

RELEASE ("linux-app-release", OptionCategories.PROPERTY),

ABOUT_URL ("about-url", OptionCategories.PROPERTY),

JAVA_OPTIONS ("java-options", OptionCategories.PROPERTY, () -> {
List<String> args = getArgumentList(popArg());
args.forEach(a -> setOptionValue("java-options", a));
Expand Down Expand Up @@ -327,6 +329,10 @@ public enum CLIOptions {

MAC_ENTITLEMENTS ("mac-entitlements", OptionCategories.PLATFORM_MAC),

WIN_HELP_URL ("win-help-url", OptionCategories.PLATFORM_WIN),

WIN_UPDATE_URL ("win-update-url", OptionCategories.PLATFORM_WIN),

WIN_MENU_HINT ("win-menu", OptionCategories.PLATFORM_WIN, () -> {
setOptionValue("win-menu", true);
}),
Expand Down
Expand Up @@ -193,6 +193,14 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(s, p) -> Path.of(s)
);

static final StandardBundlerParam<String> ABOUT_URL =
new StandardBundlerParam<>(
Arguments.CLIOptions.ABOUT_URL.getId(),
String.class,
params -> null,
(s, p) -> s
);

static final StandardBundlerParam<String> VENDOR =
new StandardBundlerParam<>(
Arguments.CLIOptions.VENDOR.getId(),
Expand Down
Expand Up @@ -87,12 +87,17 @@ enum USE {
options.put(CLIOptions.INSTALL_DIR.getId(), USE.INSTALL);
options.put(CLIOptions.PREDEFINED_APP_IMAGE.getId(), USE.INSTALL);

options.put(CLIOptions.ABOUT_URL.getId(), USE.INSTALL);

options.put(CLIOptions.FILE_ASSOCIATIONS.getId(),
(Platform.getPlatform() == Platform.MAC) ? USE.ALL : USE.INSTALL);

if (Platform.getPlatform() == Platform.WINDOWS) {
options.put(CLIOptions.WIN_CONSOLE_HINT.getId(), USE.LAUNCHER);

options.put(CLIOptions.WIN_HELP_URL.getId(), USE.INSTALL);
options.put(CLIOptions.WIN_UPDATE_URL.getId(), USE.INSTALL);

options.put(CLIOptions.WIN_MENU_HINT.getId(), USE.INSTALL);
options.put(CLIOptions.WIN_MENU_GROUP.getId(), USE.INSTALL);
options.put(CLIOptions.WIN_SHORTCUT_HINT.getId(), USE.INSTALL);
Expand Down
Expand Up @@ -166,6 +166,8 @@ Generic Options:\n\
\ option can be specified but not both.\n\
{2}\n\
\Options for creating the application package:\n\
\ --about-url <url>\n\
\ URL of the application's home page\n\
\ --app-image <file path>\n\
\ Location of the predefined application image that is used\n\
\ to build an installable package\n\
Expand Down Expand Up @@ -205,6 +207,8 @@ MSG_Help_win_install=\
\ --win-dir-chooser\n\
\ Adds a dialog to enable the user to choose a directory in which\n\
\ the product is installed\n\
\ --win-help-url <url>\n\
\ URL where user can obtain further information or technical support\n\
\ --win-menu\n\
\ Request to add a Start menu shortcut for this application\n\
\ --win-menu-group <menu group name>\n\
Expand All @@ -216,6 +220,8 @@ MSG_Help_win_install=\
\ --win-shortcut-prompt\n\
\ Adds a dialog to enable the user to choose if shortcuts\n\
\ will be created by installer\n\
\ --win-update-url <url>\n\
\ URL of available application update information\n\
\ --win-upgrade-uuid <id string>\n\
\ UUID associated with upgrades for this package\n\
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -42,6 +42,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -55,6 +56,7 @@
import javax.xml.xpath.XPathFactory;

import static jdk.jpackage.internal.OverridableResource.createResource;
import static jdk.jpackage.internal.StandardBundlerParam.ABOUT_URL;
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
import static jdk.jpackage.internal.StandardBundlerParam.CONFIG_ROOT;
Expand Down Expand Up @@ -110,6 +112,13 @@
* files.
* <li>JpIsSystemWide. Set to "yes" if --win-per-user-install command line
* option was not specified. Undefined otherwise
* <li>JpAppSizeKb. Set to estimated size of the application in kilobytes
* <li>JpHelpURL. Set to value of --win-help-url command line option if it
* was specified. Undefined otherwise
* <li>JpAboutURL. Set to value of --about-url command line option if it
* was specified. Undefined otherwise
* <li>JpUpdateURL. Set to value of --win-update-url command line option if it
* was specified. Undefined otherwise
* </ul>
*
* <p>
Expand Down Expand Up @@ -166,6 +175,20 @@ public class WinMsiBundler extends AbstractBundler {
(s, p) -> s
);

private static final BundlerParamInfo<String> HELP_URL =
new StandardBundlerParam<>(
Arguments.CLIOptions.WIN_HELP_URL.getId(),
String.class,
null,
(s, p) -> s);

private static final BundlerParamInfo<String> UPDATE_URL =
new StandardBundlerParam<>(
Arguments.CLIOptions.WIN_UPDATE_URL.getId(),
String.class,
null,
(s, p) -> s);

private static final BundlerParamInfo<String> UPGRADE_UUID =
new StandardBundlerParam<>(
Arguments.CLIOptions.WIN_UPGRADE_UUID.getId(),
Expand Down Expand Up @@ -396,6 +419,21 @@ public Path execute(Map<String, ? super Object> params,
}
}

private long getAppImageSizeKb(Map<String, ? super Object> params) throws
IOException {
ApplicationLayout appLayout;
if (StandardBundlerParam.isRuntimeInstaller(params)) {
appLayout = ApplicationLayout.javaRuntime();
} else {
appLayout = ApplicationLayout.windowsAppImage();
}
appLayout = appLayout.resolveAt(WIN_APP_IMAGE.fetchFrom(params));

long size = appLayout.sizeInBytes() >> 10;

return size;
}

private Map<String, String> prepareMainProjectFile(
Map<String, ? super Object> params) throws IOException {
Map<String, String> data = new HashMap<>();
Expand All @@ -422,6 +460,20 @@ private Map<String, String> prepareMainProjectFile(
data.put("JpIcon", installerIcon.toString());
}

Optional.ofNullable(HELP_URL.fetchFrom(params)).ifPresent(value -> {
data.put("JpHelpURL", value);
});

Optional.ofNullable(UPDATE_URL.fetchFrom(params)).ifPresent(value -> {
data.put("JpUpdateURL", value);
});

Optional.ofNullable(ABOUT_URL.fetchFrom(params)).ifPresent(value -> {
data.put("JpAboutURL", value);
});

data.put("JpAppSizeKb", Long.toString(getAppImageSizeKb(params)));

final Path configDir = CONFIG_ROOT.fetchFrom(params);

data.put("JpConfigDir", configDir.toAbsolutePath().toString());
Expand Down
Expand Up @@ -75,16 +75,44 @@
</Feature>

<CustomAction Id="JpSetARPINSTALLLOCATION" Property="ARPINSTALLLOCATION" Value="[INSTALLDIR]" />
<CustomAction Id="JpSetARPCOMMENTS" Property="ARPCOMMENTS" Value="$(var.JpAppDescription)" />
<CustomAction Id="JpSetARPCONTACT" Property="ARPCONTACT" Value="$(var.JpAppVendor)" />
<CustomAction Id="JpSetARPSIZE" Property="ARPSIZE" Value="$(var.JpAppSizeKb)" />

<?ifdef JpHelpURL ?>
<CustomAction Id="JpSetARPHELPLINK" Property="ARPHELPLINK" Value="$(var.JpHelpURL)" />
<?endif?>

<?ifdef JpAboutURL ?>
<CustomAction Id="JpSetARPURLINFOABOUT" Property="ARPURLINFOABOUT" Value="$(var.JpAboutURL)" />
<?endif?>

<?ifdef JpUpdateURL ?>
<CustomAction Id="JpSetARPURLUPDATEINFO" Property="ARPURLUPDATEINFO" Value="$(var.JpUpdateURL)" />
<?endif?>

<?ifdef JpIcon ?>
<Property Id="ARPPRODUCTICON" Value="JpARPPRODUCTICON"/>
<Icon Id="JpARPPRODUCTICON" SourceFile="$(var.JpIcon)"/>
<?endif?>

<UIRef Id="JpUI"/>

<InstallExecuteSequence>
<Custom Action="JpSetARPINSTALLLOCATION" After="CostFinalize">Not Installed</Custom>
<Custom Action="JpSetARPCOMMENTS" After="CostFinalize">Not Installed</Custom>
<Custom Action="JpSetARPCONTACT" After="CostFinalize">Not Installed</Custom>
<Custom Action="JpSetARPSIZE" After="CostFinalize">Not Installed</Custom>
<?ifdef JpHelpURL ?>
<Custom Action="JpSetARPHELPLINK" After="CostFinalize">Not Installed</Custom>
<?endif?>
<?ifdef JpAboutURL ?>
<Custom Action="JpSetARPURLINFOABOUT" After="CostFinalize">Not Installed</Custom>
<?endif?>
<?ifdef JpUpdateURL ?>
<Custom Action="JpSetARPURLUPDATEINFO" After="CostFinalize">Not Installed</Custom>
<?endif?>

<?ifndef JpAllowUpgrades ?>
<Custom Action="JpDisallowUpgrade" After="FindRelatedProducts">JP_UPGRADABLE_FOUND</Custom>
<?endif?>
Expand Down
117 changes: 117 additions & 0 deletions test/jdk/tools/jpackage/windows/WinUrlTest.java
@@ -0,0 +1,117 @@
/*
* Copyright (c) 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
* 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.util.ArrayList;
import jdk.jpackage.test.PackageTest;
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Annotations.Parameters;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import jdk.jpackage.test.PackageType;

/**
* Test all possible combinations of --about-url, --win-update-url and
* --win-help-url parameters.
*/

/*
* @test
* @summary jpackage with --about-url, --win-update-url and --win-help-url
* parameters
* @library ../helpers
* @key jpackagePlatformPackage
* @build jdk.jpackage.test.*
* @build WinUrlTest
* @requires (os.family == "windows")
* @modules jdk.jpackage/jdk.jpackage.internal
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=WinUrlTest
*/
public class WinUrlTest {

static enum URL {
About("--about-url"),
Update("--win-update-url"),
Help("--win-help-url");

URL(String cliOption) {
this.cliOption = cliOption;
}

final String cliOption;
}

public WinUrlTest(Boolean withAboutURL, Boolean withUpdateURL,
Boolean withHelpURL) {
urls = Stream.of(
withAboutURL ? URL.About : null,
withUpdateURL ? URL.Update : null,
withHelpURL ? URL.Help : null
).filter(Objects::nonNull).toList();
}

@Parameters
public static List<Object[]> data() {
List<Object[]> data = new ArrayList<>();
for (var withAboutURL : List.of(Boolean.TRUE, Boolean.FALSE)) {
for (var withUpdateURL : List.of(Boolean.TRUE, Boolean.FALSE)) {
for (var withHelpURL : List.of(Boolean.TRUE, Boolean.FALSE)) {
var args = new Object[]{withAboutURL, withUpdateURL, withHelpURL};
if (Stream.of(args).anyMatch(Boolean.TRUE::equals)) {
data.add(args);
}
}
}
}

return data;
}

@Test
public void test() {
PackageTest test = new PackageTest()
.forTypes(PackageType.WINDOWS)
.configureHelloApp();

test.addInitializer(JPackageCommand::setFakeRuntime);
test.addInitializer(this::setPackageName);

urls.forEach(url -> {
test.addInitializer(cmd -> cmd.addArguments(url.cliOption,
"http://localhost/" + url.name().toLowerCase()));
});

test.run();
}

private void setPackageName(JPackageCommand cmd) {
StringBuilder sb = new StringBuilder(cmd.name());
sb.append("With");
urls.forEach(url -> sb.append(url.name()));
cmd.setArgumentValue("--name", sb.toString());
}

private final List<URL> urls;
}

1 comment on commit 3d7f912

@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.