8274346: Support for additional content in an app-image.

Reviewed-by: asemenyuk, almatvee
This commit is contained in:
Andy Herrick 2021-10-18 13:28:41 +00:00
parent a619f8909b
commit d548f2fc0d
10 changed files with 167 additions and 10 deletions

View File

@ -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.IOException;
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 @@ public abstract class AbstractAppImageBuilder {
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,

View File

@ -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 @@ public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
/**
* 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 final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
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 @@ public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
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 @@ public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
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 @@ public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
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 final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
PathRole.DESKTOP, lib,
PathRole.MODULES, lib.resolve("app/mods"),
PathRole.LINUX_APPLAUNCHER_LIB, lib.resolve(
"lib/libapplauncher.so")
"lib/libapplauncher.so"),
PathRole.CONTENT, lib
));
}

View File

@ -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 class Arguments {
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<>();

View File

@ -294,6 +294,7 @@ public class DeployParams {
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 class DeployParams {
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);

View File

@ -404,6 +404,16 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
(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<>(

View File

@ -82,6 +82,7 @@ class ValidOptions {
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);

View File

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

View File

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

View File

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

View File

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