Skip to content
Permalink
Browse files
8274346: Support for additional content in an app-image.
Reviewed-by: asemenyuk, almatvee
  • Loading branch information
Andy Herrick committed Oct 18, 2021
1 parent a619f89 commit d548f2fc0dbc9e7864dd1701873bbf3d12a75ecb
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@@ -29,10 +29,12 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Map;
import java.util.List;
import static jdk.jpackage.internal.OverridableResource.createResource;
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
import static jdk.jpackage.internal.StandardBundlerParam.ICON;
import static jdk.jpackage.internal.StandardBundlerParam.SOURCE_DIR;
import static jdk.jpackage.internal.StandardBundlerParam.APP_CONTENT;
import jdk.jpackage.internal.resources.ResourceLocator;

/*
@@ -75,6 +77,11 @@ protected void copyApplication(Map<String, ? super Object> params)
appLayout.appDirectory());
}
AppImageFile.save(root, params);
List<String> items = APP_CONTENT.fetchFrom(params);
for (String item : items) {
IOUtils.copyRecursive(Path.of(item),
appLayout.contentDirectory().resolve(Path.of(item).getFileName()));
}
}

public static OverridableResource createIconResource(String defaultIconName,
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 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
@@ -66,7 +66,12 @@
/**
* Linux app launcher shared library.
*/
LINUX_APPLAUNCHER_LIB
LINUX_APPLAUNCHER_LIB,

/**
* Location of additional application content
*/
CONTENT
}

ApplicationLayout(Map<Object, Path> paths) {
@@ -129,6 +134,13 @@ public Path destktopIntegrationDirectory() {
return pathGroup().getPath(PathRole.DESKTOP);
}

/**
* Path to directory with additional application content.
*/
public Path contentDirectory() {
return pathGroup().getPath(PathRole.CONTENT);
}

static ApplicationLayout linuxAppImage() {
return new ApplicationLayout(Map.of(
PathRole.LAUNCHERS, Path.of("bin"),
@@ -137,7 +149,8 @@ static ApplicationLayout linuxAppImage() {
PathRole.RUNTIME_HOME, Path.of("lib/runtime"),
PathRole.DESKTOP, Path.of("lib"),
PathRole.MODULES, Path.of("lib/app/mods"),
PathRole.LINUX_APPLAUNCHER_LIB, Path.of("lib/libapplauncher.so")
PathRole.LINUX_APPLAUNCHER_LIB, Path.of("lib/libapplauncher.so"),
PathRole.CONTENT, Path.of("lib")
));
}

@@ -148,7 +161,8 @@ static ApplicationLayout windowsAppImage() {
PathRole.RUNTIME, Path.of("runtime"),
PathRole.RUNTIME_HOME, Path.of("runtime"),
PathRole.DESKTOP, Path.of(""),
PathRole.MODULES, Path.of("app/mods")
PathRole.MODULES, Path.of("app/mods"),
PathRole.CONTENT, Path.of("")
));
}

@@ -159,7 +173,8 @@ static ApplicationLayout macAppImage() {
PathRole.RUNTIME, Path.of("Contents/runtime"),
PathRole.RUNTIME_HOME, Path.of("Contents/runtime/Contents/Home"),
PathRole.DESKTOP, Path.of("Contents/Resources"),
PathRole.MODULES, Path.of("Contents/app/mods")
PathRole.MODULES, Path.of("Contents/app/mods"),
PathRole.CONTENT, Path.of("Contents")
));
}

@@ -194,7 +209,8 @@ public static ApplicationLayout linuxUsrTreePackageImage(Path prefix,
PathRole.DESKTOP, lib,
PathRole.MODULES, lib.resolve("app/mods"),
PathRole.LINUX_APPLAUNCHER_LIB, lib.resolve(
"lib/libapplauncher.so")
"lib/libapplauncher.so"),
PathRole.CONTENT, lib
));
}

@@ -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
@@ -206,6 +206,11 @@ public Arguments(String[] args) {
args.forEach(a -> setOptionValue("java-options", a));
}),

APP_CONTENT ("app-content", OptionCategories.PROPERTY, () -> {
getArgumentList(popArg()).forEach(
a -> setOptionValue("app-content", a));
}),

FILE_ASSOCIATIONS ("file-associations",
OptionCategories.PROPERTY, () -> {
Map<String, ? super Object> args = new HashMap<>();
@@ -294,6 +294,7 @@ boolean isTargetAppImage() {
StandardBundlerParam.ADD_MODULES.getID(),
StandardBundlerParam.LIMIT_MODULES.getID(),
StandardBundlerParam.FILE_ASSOCIATIONS.getID(),
StandardBundlerParam.APP_CONTENT.getID(),
StandardBundlerParam.JLINK_OPTIONS.getID()
));

@@ -306,8 +307,8 @@ public void addBundleArgument(String key, Object value) {
String delim = "\n\n";
if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
delim = File.pathSeparator;
} else if (key.equals(
StandardBundlerParam.ADD_MODULES.getID())) {
} else if (key.equals(StandardBundlerParam.ADD_MODULES.getID()) ||
key.equals(StandardBundlerParam.APP_CONTENT.getID())) {
delim = ",";
}
bundlerArguments.put(key, existingValue + delim + value);
@@ -404,6 +404,16 @@
(s, p) -> Path.of(s)
);

@SuppressWarnings("unchecked")
static final StandardBundlerParam<List<String>> APP_CONTENT =
new StandardBundlerParam<>(
Arguments.CLIOptions.APP_CONTENT.getId(),
(Class<List<String>>) (Object)List.class,
p->Collections.emptyList(),
(s, p) -> Arrays.asList(s.split(","))

);

@SuppressWarnings("unchecked")
static final BundlerParamInfo<List<Path>> MODULE_PATH =
new StandardBundlerParam<>(
@@ -82,6 +82,7 @@
options.put(CLIOptions.JAVA_OPTIONS.getId(), USE.LAUNCHER);
options.put(CLIOptions.ADD_LAUNCHER.getId(), USE.LAUNCHER);
options.put(CLIOptions.JLINK_OPTIONS.getId(), USE.LAUNCHER);
options.put(CLIOptions.APP_CONTENT.getId(), USE.LAUNCHER);

options.put(CLIOptions.LICENSE_FILE.getId(), USE.INSTALL);
options.put(CLIOptions.INSTALL_DIR.getId(), USE.INSTALL);
@@ -128,6 +128,10 @@ Generic Options:\n\
\ (absolute path or relative to the current directory)\n\
\ All files in the input directory will be packaged into the\n\
\ application image.\n\
\ --app-content <additional content>[,<additional content>...]\n\
\ A comma separated list of paths to files and/or directories\n\
\ to add to the application payload.\n\
\ This option can be used more than once.\n\
\n\
\Options for creating the application launcher(s):\n\
\ --add-launcher <launcher name>=<file path>\n\
@@ -128,6 +128,10 @@ Generic Options:\n\
\ (absolute path or relative to the current directory)\n\
\ All files in the input directory will be packaged into the\n\
\ application image.\n\
\ --app-content <additional content>[,<additional content>...]\n\
\ A comma separated list of paths to files and/or directories\n\
\ to add to the application payload.\n\
\ This option can be used more than once.\n\
\n\
\Options for creating the application launcher(s):\n\
\ --add-launcher <launcher name>=<file path>\n\
@@ -128,6 +128,10 @@ Generic Options:\n\
\ (absolute path or relative to the current directory)\n\
\ All files in the input directory will be packaged into the\n\
\ application image.\n\
\ --app-content <additional content>[,<additional content>...]\n\
\ A comma separated list of paths to files and/or directories\n\
\ to add to the application payload.\n\
\ This option can be used more than once.\n\
\n\
\Options for creating the application launcher(s):\n\
\ --add-launcher <launcher name>=<file path>\n\
@@ -0,0 +1,105 @@
/*
* 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
* 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.nio.file.Files;
import jdk.jpackage.internal.ApplicationLayout;
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.Annotations.Parameter;
import jdk.jpackage.test.Annotations.Parameters;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;


/**
* Tests generation of packages with input folder containing empty folders.
*/

/*
* @test
* @summary jpackage with --app-content option
* @library ../helpers
* @library /test/lib
* @key jpackagePlatformPackage
* @build jdk.jpackage.test.*
* @build AppContentTest
* @modules jdk.jpackage/jdk.jpackage.internal
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
* --jpt-run=AppContentTest
*/
public class AppContentTest {

private static final String TEST_JAVA = TKit.TEST_SRC_ROOT.resolve(
"apps/PrintEnv.java").toString();
private static final String TEST_DUKE = TKit.TEST_SRC_ROOT.resolve(
"apps/dukeplug.png").toString();
private static final String TEST_DIR = TKit.TEST_SRC_ROOT.resolve(
"apps").toString();
private static final String TEST_BAD = TKit.TEST_SRC_ROOT.resolve(
"non-existant").toString();

private final List<String> testPathArgs;

@Parameters
public static Collection data() {
return List.of(new String[][]{
{TEST_JAVA, TEST_DUKE}, // include two files in two options
{TEST_JAVA, TEST_BAD}, // try to include non-existant content
{TEST_JAVA + "," + TEST_DUKE, TEST_DIR}, // two files in one option,
// and a dir tree in another option.
});
}

public AppContentTest(String... testPathArgs) {
this.testPathArgs = List.of(testPathArgs);
}

@Test
public void test() throws Exception {

new PackageTest().configureHelloApp()
.addInitializer(cmd -> {
for (String arg : testPathArgs) {
cmd.addArguments("--app-content", arg);
}
})
.addInstallVerifier(cmd -> {
ApplicationLayout appLayout = cmd.appLayout();
Path contentDir = appLayout.contentDirectory();
for (String arg : testPathArgs) {
List<String> paths = Arrays.asList(arg.split(","));
for (String p : paths) {
Path name = Path.of(p).getFileName();
TKit.assertPathExists(contentDir.resolve(name), true);
}
}

})
.setExpectedExitCode(testPathArgs.contains(TEST_BAD) ? 1 : 0)
.run();
}
}

1 comment on commit d548f2f

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on d548f2f Oct 18, 2021

Please sign in to comment.