Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246627: Consolidate app image bundlers
Reviewed-by: herrick, almatvee
  • Loading branch information
Alexey Semenyuk committed Jun 8, 2020
1 parent 045d61b commit 28d2cdf99aa4fbced870f6039274ed039df6f76d
Showing with 723 additions and 1,067 deletions.
  1. +20 −5 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/DesktopIntegration.java
  2. +4 −136 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxAppBundler.java
  3. +21 −51 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxAppImageBuilder.java
  4. +0 −1 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxDebBundler.java
  5. +30 −14 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxPackageBundler.java
  6. +0 −2 src/jdk.incubator.jpackage/linux/classes/jdk/incubator/jpackage/internal/LinuxRpmBundler.java
  7. +14 −100 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacAppBundler.java
  8. +26 −72 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacAppImageBuilder.java
  9. +13 −18 ...dk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacBaseInstallerBundler.java
  10. +18 −5 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java
  11. +4 −0 src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacPkgBundler.java
  12. +4 −6 src/jdk.incubator.jpackage/macosx/native/applauncher/MacLauncher.cpp
  13. +15 −118 ...jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AbstractAppImageBuilder.java
  14. +0 −81 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AbstractImageBundler.java
  15. +178 −0 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageBundler.java
  16. +23 −12 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/AppImageFile.java
  17. +45 −27 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/ApplicationLayout.java
  18. +133 −0 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/CfgFile.java
  19. +53 −82 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/JLinkBundlerHelper.java
  20. +6 −9 src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/StandardBundlerParam.java
  21. +4 −107 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinAppBundler.java
  22. +2 −12 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinExeBundler.java
  23. +43 −27 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WinMsiBundler.java
  24. +8 −54 ...dk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WindowsAppImageBuilder.java
  25. +0 −104 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WindowsBundlerParam.java
  26. +37 −5 src/jdk.incubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/WixSourcesBuilder.java
  27. +0 −1 ...ubator.jpackage/windows/classes/jdk/incubator/jpackage/internal/resources/WinResources.properties
  28. +1 −2 ...tor.jpackage/windows/classes/jdk/incubator/jpackage/internal/resources/WinResources_ja.properties
  29. +1 −2 ....jpackage/windows/classes/jdk/incubator/jpackage/internal/resources/WinResources_zh_CN.properties
  30. +1 −4 test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java
  31. +14 −4 test/jdk/tools/jpackage/share/jdk/jpackage/tests/AppVersionTest.java
  32. +1 −2 test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java
  33. +4 −4 test/jdk/tools/jpackage/share/jdk/jpackage/tests/JLinkOptionsTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@@ -25,19 +25,34 @@
package jdk.incubator.jpackage.internal;

import java.awt.image.BufferedImage;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.imageio.ImageIO;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import static jdk.incubator.jpackage.internal.LinuxAppBundler.ICON_PNG;
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;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.ADD_LAUNCHERS;
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;

/**
* Helper to create files for desktop integration.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@@ -25,140 +25,8 @@

package jdk.incubator.jpackage.internal;

import java.io.File;
import java.text.MessageFormat;
import java.util.*;

import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;

public class LinuxAppBundler extends AbstractImageBundler {

static final BundlerParamInfo<File> ICON_PNG =
new StandardBundlerParam<>(
"icon.png",
File.class,
params -> {
File f = ICON.fetchFrom(params);
if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
Log.error(MessageFormat.format(
I18N.getString("message.icon-not-png"), f));
return null;
}
return f;
},
(s, p) -> new File(s));

static final BundlerParamInfo<String> LINUX_INSTALL_DIR =
new StandardBundlerParam<>(
"linux-install-dir",
String.class,
params -> {
String dir = INSTALL_DIR.fetchFrom(params);
if (dir != null) {
if (dir.endsWith("/")) {
dir = dir.substring(0, dir.length()-1);
}
return dir;
}
return "/opt";
},
(s, p) -> s
);

static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES =
new StandardBundlerParam<>(
Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
String.class,
params -> {
return "";
},
(s, p) -> s
);

@Override
public boolean validate(Map<String, ? super Object> params)
throws ConfigException {
try {
Objects.requireNonNull(params);
return doValidate(params);
} catch (RuntimeException re) {
if (re.getCause() instanceof ConfigException) {
throw (ConfigException) re.getCause();
} else {
throw new ConfigException(re);
}
}
}

private boolean doValidate(Map<String, ? super Object> params)
throws ConfigException {

imageBundleValidation(params);

return true;
}

File doBundle(Map<String, ? super Object> params, File outputDirectory,
boolean dependentTask) throws PackagerException {
if (StandardBundlerParam.isRuntimeInstaller(params)) {
return PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
} else {
return doAppBundle(params, outputDirectory, dependentTask);
}
}

private File doAppBundle(Map<String, ? super Object> params,
File outputDirectory, boolean dependentTask)
throws PackagerException {
try {
File rootDirectory = createRoot(params, outputDirectory,
dependentTask, APP_NAME.fetchFrom(params));
AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(
params, outputDirectory.toPath());
if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null ) {
JLinkBundlerHelper.execute(params, appBuilder);
} else {
StandardBundlerParam.copyPredefinedRuntimeImage(
params, appBuilder);
}
return rootDirectory;
} catch (PackagerException pe) {
throw pe;
} catch (Exception ex) {
Log.verbose(ex);
throw new PackagerException(ex);
}
public class LinuxAppBundler extends AppImageBundler {
public LinuxAppBundler() {
setAppImageSupplier(LinuxAppImageBuilder::new);
}

@Override
public String getName() {
return I18N.getString("app.bundler.name");
}

@Override
public String getID() {
return "linux.app";
}

@Override
public String getBundleType() {
return "IMAGE";
}

@Override
public File execute(Map<String, ? super Object> params,
File outputParentDir) throws PackagerException {
return doBundle(params, outputParentDir, false);
}

@Override
public boolean supported(boolean runtimeInstaller) {
return true;
}

@Override
public boolean isDefault() {
return false;
}

}
@@ -30,31 +30,33 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import static jdk.incubator.jpackage.internal.LinuxAppBundler.ICON_PNG;
import static jdk.incubator.jpackage.internal.OverridableResource.createResource;

import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.APP_NAME;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.ICON;

public class LinuxAppImageBuilder extends AbstractAppImageBuilder {

final static String DEFAULT_ICON = "java32.png";

private final ApplicationLayout appLayout;
static final BundlerParamInfo<File> ICON_PNG =
new StandardBundlerParam<>(
"icon.png",
File.class,
params -> {
File f = ICON.fetchFrom(params);
if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
Log.error(MessageFormat.format(
I18N.getString("message.icon-not-png"), f));
return null;
}
return f;
},
(s, p) -> new File(s));

private static ApplicationLayout createAppLayout(Map<String, Object> params,
Path imageOutDir) {
return ApplicationLayout.linuxAppImage().resolveAt(
imageOutDir.resolve(APP_NAME.fetchFrom(params)));
}

public LinuxAppImageBuilder(Map<String, Object> params, Path imageOutDir)
throws IOException {
super(params, createAppLayout(params, imageOutDir).runtimeDirectory());
final static String DEFAULT_ICON = "java32.png";

appLayout = createAppLayout(params, imageOutDir);
LinuxAppImageBuilder(Path imageOutDir) {
super(imageOutDir);
}

private void writeEntry(InputStream in, Path dstFile) throws IOException {
@@ -66,34 +68,6 @@ public static String getLauncherName(Map<String, ? super Object> params) {
return APP_NAME.fetchFrom(params);
}

private Path getLauncherCfgPath(Map<String, ? super Object> params) {
return appLayout.appDirectory().resolve(
APP_NAME.fetchFrom(params) + ".cfg");
}

@Override
public Path getAppDir() {
return appLayout.appDirectory();
}

@Override
public Path getAppModsDir() {
return appLayout.appModsDirectory();
}

@Override
protected String getCfgAppDir() {
return Path.of("$ROOTDIR").resolve(
ApplicationLayout.linuxAppImage().appDirectory()).toString()
+ File.separator;
}

@Override
protected String getCfgRuntimeDir() {
return Path.of("$ROOTDIR").resolve(
ApplicationLayout.linuxAppImage().runtimeDirectory()).toString();
}

@Override
public void prepareApplicationFiles(Map<String, ? super Object> params)
throws IOException {
@@ -120,10 +94,6 @@ public void prepareApplicationFiles(Map<String, ? super Object> params)
copyApplication(params);
}

@Override
public void prepareJreFiles(Map<String, ? super Object> params)
throws IOException {}

private void createLauncherForEntryPoint(Map<String, ? super Object> params,
Map<String, ? super Object> mainParams) throws IOException {
// Copy executable to launchers folder
@@ -136,7 +106,7 @@ private void createLauncherForEntryPoint(Map<String, ? super Object> params,
executableFile.toFile().setExecutable(true, false);
executableFile.toFile().setWritable(true, true);

writeCfgFile(params, getLauncherCfgPath(params).toFile());
writeCfgFile(params);

var iconResource = createIconResource(DEFAULT_ICON, ICON_PNG, params,
mainParams);
@@ -40,7 +40,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static jdk.incubator.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
import static jdk.incubator.jpackage.internal.OverridableResource.createResource;

import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@@ -34,15 +34,14 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static jdk.incubator.jpackage.internal.DesktopIntegration.*;
import static jdk.incubator.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
import static jdk.incubator.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
import static jdk.incubator.jpackage.internal.StandardBundlerParam.*;


abstract class LinuxPackageBundler extends AbstractBundler {

LinuxPackageBundler(BundlerParamInfo<String> packageName) {
this.packageName = packageName;
appImageBundler = new LinuxAppBundler().setDependentTask(true);
}

@Override
@@ -51,7 +50,7 @@ final public boolean validate(Map<String, ? super Object> params)

// run basic validation to ensure requirements are met
// we are not interested in return code, only possible exception
APP_BUNDLER.fetchFrom(params).validate(params);
appImageBundler.validate(params);

validateInstallDir(LINUX_INSTALL_DIR.fetchFrom(params));

@@ -115,8 +114,8 @@ final public File execute(Map<String, ? super Object> params,
initAppImageLayout.apply(appImage).copy(
thePackage.sourceApplicationLayout());
} else {
appImage = APP_BUNDLER.fetchFrom(params).doBundle(params,
thePackage.sourceRoot().toFile(), true);
appImage = appImageBundler.execute(params,
thePackage.sourceRoot().toFile());
ApplicationLayout srcAppLayout = initAppImageLayout.apply(
appImage);
if (appImage.equals(PREDEFINED_RUNTIME_IMAGE.fetchFrom(params))) {
@@ -314,15 +313,32 @@ private static void validateInstallDir(String installDir) throws
}

private final BundlerParamInfo<String> packageName;
private final Bundler appImageBundler;
private boolean withFindNeededPackages;
private DesktopIntegration desktopIntegration;

private static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
new StandardBundlerParam<>(
"linux.app.bundler",
LinuxAppBundler.class,
(params) -> new LinuxAppBundler(),
null
);

private static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES =
new StandardBundlerParam<>(
Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
String.class,
params -> "",
(s, p) -> s
);

static final BundlerParamInfo<String> LINUX_INSTALL_DIR =
new StandardBundlerParam<>(
"linux-install-dir",
String.class,
params -> {
String dir = INSTALL_DIR.fetchFrom(params);
if (dir != null) {
if (dir.endsWith("/")) {
dir = dir.substring(0, dir.length()-1);
}
return dir;
}
return "/opt";
},
(s, p) -> s
);
}

0 comments on commit 28d2cdf

Please sign in to comment.