Skip to content

Commit d548f2f

Browse files
author
Andy Herrick
committedOct 18, 2021
8274346: Support for additional content in an app-image.
Reviewed-by: asemenyuk, almatvee
1 parent a619f89 commit d548f2f

10 files changed

+167
-10
lines changed
 

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractAppImageBuilder.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,10 +29,12 @@
2929
import java.io.InputStream;
3030
import java.nio.file.Path;
3131
import java.util.Map;
32+
import java.util.List;
3233
import static jdk.jpackage.internal.OverridableResource.createResource;
3334
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
3435
import static jdk.jpackage.internal.StandardBundlerParam.ICON;
3536
import static jdk.jpackage.internal.StandardBundlerParam.SOURCE_DIR;
37+
import static jdk.jpackage.internal.StandardBundlerParam.APP_CONTENT;
3638
import jdk.jpackage.internal.resources.ResourceLocator;
3739

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

8087
public static OverridableResource createIconResource(String defaultIconName,

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/ApplicationLayout.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -66,7 +66,12 @@ enum PathRole {
6666
/**
6767
* Linux app launcher shared library.
6868
*/
69-
LINUX_APPLAUNCHER_LIB
69+
LINUX_APPLAUNCHER_LIB,
70+
71+
/**
72+
* Location of additional application content
73+
*/
74+
CONTENT
7075
}
7176

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

137+
/**
138+
* Path to directory with additional application content.
139+
*/
140+
public Path contentDirectory() {
141+
return pathGroup().getPath(PathRole.CONTENT);
142+
}
143+
132144
static ApplicationLayout linuxAppImage() {
133145
return new ApplicationLayout(Map.of(
134146
PathRole.LAUNCHERS, Path.of("bin"),
@@ -137,7 +149,8 @@ static ApplicationLayout linuxAppImage() {
137149
PathRole.RUNTIME_HOME, Path.of("lib/runtime"),
138150
PathRole.DESKTOP, Path.of("lib"),
139151
PathRole.MODULES, Path.of("lib/app/mods"),
140-
PathRole.LINUX_APPLAUNCHER_LIB, Path.of("lib/libapplauncher.so")
152+
PathRole.LINUX_APPLAUNCHER_LIB, Path.of("lib/libapplauncher.so"),
153+
PathRole.CONTENT, Path.of("lib")
141154
));
142155
}
143156

@@ -148,7 +161,8 @@ static ApplicationLayout windowsAppImage() {
148161
PathRole.RUNTIME, Path.of("runtime"),
149162
PathRole.RUNTIME_HOME, Path.of("runtime"),
150163
PathRole.DESKTOP, Path.of(""),
151-
PathRole.MODULES, Path.of("app/mods")
164+
PathRole.MODULES, Path.of("app/mods"),
165+
PathRole.CONTENT, Path.of("")
152166
));
153167
}
154168

@@ -159,7 +173,8 @@ static ApplicationLayout macAppImage() {
159173
PathRole.RUNTIME, Path.of("Contents/runtime"),
160174
PathRole.RUNTIME_HOME, Path.of("Contents/runtime/Contents/Home"),
161175
PathRole.DESKTOP, Path.of("Contents/Resources"),
162-
PathRole.MODULES, Path.of("Contents/app/mods")
176+
PathRole.MODULES, Path.of("Contents/app/mods"),
177+
PathRole.CONTENT, Path.of("Contents")
163178
));
164179
}
165180

@@ -194,7 +209,8 @@ public static ApplicationLayout linuxUsrTreePackageImage(Path prefix,
194209
PathRole.DESKTOP, lib,
195210
PathRole.MODULES, lib.resolve("app/mods"),
196211
PathRole.LINUX_APPLAUNCHER_LIB, lib.resolve(
197-
"lib/libapplauncher.so")
212+
"lib/libapplauncher.so"),
213+
PathRole.CONTENT, lib
198214
));
199215
}
200216

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -206,6 +206,11 @@ public enum CLIOptions {
206206
args.forEach(a -> setOptionValue("java-options", a));
207207
}),
208208

209+
APP_CONTENT ("app-content", OptionCategories.PROPERTY, () -> {
210+
getArgumentList(popArg()).forEach(
211+
a -> setOptionValue("app-content", a));
212+
}),
213+
209214
FILE_ASSOCIATIONS ("file-associations",
210215
OptionCategories.PROPERTY, () -> {
211216
Map<String, ? super Object> args = new HashMap<>();

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/DeployParams.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ boolean isTargetAppImage() {
294294
StandardBundlerParam.ADD_MODULES.getID(),
295295
StandardBundlerParam.LIMIT_MODULES.getID(),
296296
StandardBundlerParam.FILE_ASSOCIATIONS.getID(),
297+
StandardBundlerParam.APP_CONTENT.getID(),
297298
StandardBundlerParam.JLINK_OPTIONS.getID()
298299
));
299300

@@ -306,8 +307,8 @@ public void addBundleArgument(String key, Object value) {
306307
String delim = "\n\n";
307308
if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
308309
delim = File.pathSeparator;
309-
} else if (key.equals(
310-
StandardBundlerParam.ADD_MODULES.getID())) {
310+
} else if (key.equals(StandardBundlerParam.ADD_MODULES.getID()) ||
311+
key.equals(StandardBundlerParam.APP_CONTENT.getID())) {
311312
delim = ",";
312313
}
313314
bundlerArguments.put(key, existingValue + delim + value);

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java

+10
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,16 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
404404
(s, p) -> Path.of(s)
405405
);
406406

407+
@SuppressWarnings("unchecked")
408+
static final StandardBundlerParam<List<String>> APP_CONTENT =
409+
new StandardBundlerParam<>(
410+
Arguments.CLIOptions.APP_CONTENT.getId(),
411+
(Class<List<String>>) (Object)List.class,
412+
p->Collections.emptyList(),
413+
(s, p) -> Arrays.asList(s.split(","))
414+
415+
);
416+
407417
@SuppressWarnings("unchecked")
408418
static final BundlerParamInfo<List<Path>> MODULE_PATH =
409419
new StandardBundlerParam<>(

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/ValidOptions.java

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ enum USE {
8282
options.put(CLIOptions.JAVA_OPTIONS.getId(), USE.LAUNCHER);
8383
options.put(CLIOptions.ADD_LAUNCHER.getId(), USE.LAUNCHER);
8484
options.put(CLIOptions.JLINK_OPTIONS.getId(), USE.LAUNCHER);
85+
options.put(CLIOptions.APP_CONTENT.getId(), USE.LAUNCHER);
8586

8687
options.put(CLIOptions.LICENSE_FILE.getId(), USE.INSTALL);
8788
options.put(CLIOptions.INSTALL_DIR.getId(), USE.INSTALL);

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources.properties

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Generic Options:\n\
128128
\ (absolute path or relative to the current directory)\n\
129129
\ All files in the input directory will be packaged into the\n\
130130
\ application image.\n\
131+
\ --app-content <additional content>[,<additional content>...]\n\
132+
\ A comma separated list of paths to files and/or directories\n\
133+
\ to add to the application payload.\n\
134+
\ This option can be used more than once.\n\
131135
\n\
132136
\Options for creating the application launcher(s):\n\
133137
\ --add-launcher <launcher name>=<file path>\n\

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_ja.properties

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Generic Options:\n\
128128
\ (absolute path or relative to the current directory)\n\
129129
\ All files in the input directory will be packaged into the\n\
130130
\ application image.\n\
131+
\ --app-content <additional content>[,<additional content>...]\n\
132+
\ A comma separated list of paths to files and/or directories\n\
133+
\ to add to the application payload.\n\
134+
\ This option can be used more than once.\n\
131135
\n\
132136
\Options for creating the application launcher(s):\n\
133137
\ --add-launcher <launcher name>=<file path>\n\

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/HelpResources_zh_CN.properties

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Generic Options:\n\
128128
\ (absolute path or relative to the current directory)\n\
129129
\ All files in the input directory will be packaged into the\n\
130130
\ application image.\n\
131+
\ --app-content <additional content>[,<additional content>...]\n\
132+
\ A comma separated list of paths to files and/or directories\n\
133+
\ to add to the application payload.\n\
134+
\ This option can be used more than once.\n\
131135
\n\
132136
\Options for creating the application launcher(s):\n\
133137
\ --add-launcher <launcher name>=<file path>\n\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.nio.file.Path;
25+
import java.nio.file.Files;
26+
import jdk.jpackage.internal.ApplicationLayout;
27+
import jdk.jpackage.test.PackageTest;
28+
import jdk.jpackage.test.PackageType;
29+
import jdk.jpackage.test.TKit;
30+
import jdk.jpackage.test.Annotations.Test;
31+
import jdk.jpackage.test.Annotations.Parameter;
32+
import jdk.jpackage.test.Annotations.Parameters;
33+
import java.util.Arrays;
34+
import java.util.Collection;
35+
import java.util.List;
36+
37+
38+
/**
39+
* Tests generation of packages with input folder containing empty folders.
40+
*/
41+
42+
/*
43+
* @test
44+
* @summary jpackage with --app-content option
45+
* @library ../helpers
46+
* @library /test/lib
47+
* @key jpackagePlatformPackage
48+
* @build jdk.jpackage.test.*
49+
* @build AppContentTest
50+
* @modules jdk.jpackage/jdk.jpackage.internal
51+
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
52+
* --jpt-run=AppContentTest
53+
*/
54+
public class AppContentTest {
55+
56+
private static final String TEST_JAVA = TKit.TEST_SRC_ROOT.resolve(
57+
"apps/PrintEnv.java").toString();
58+
private static final String TEST_DUKE = TKit.TEST_SRC_ROOT.resolve(
59+
"apps/dukeplug.png").toString();
60+
private static final String TEST_DIR = TKit.TEST_SRC_ROOT.resolve(
61+
"apps").toString();
62+
private static final String TEST_BAD = TKit.TEST_SRC_ROOT.resolve(
63+
"non-existant").toString();
64+
65+
private final List<String> testPathArgs;
66+
67+
@Parameters
68+
public static Collection data() {
69+
return List.of(new String[][]{
70+
{TEST_JAVA, TEST_DUKE}, // include two files in two options
71+
{TEST_JAVA, TEST_BAD}, // try to include non-existant content
72+
{TEST_JAVA + "," + TEST_DUKE, TEST_DIR}, // two files in one option,
73+
// and a dir tree in another option.
74+
});
75+
}
76+
77+
public AppContentTest(String... testPathArgs) {
78+
this.testPathArgs = List.of(testPathArgs);
79+
}
80+
81+
@Test
82+
public void test() throws Exception {
83+
84+
new PackageTest().configureHelloApp()
85+
.addInitializer(cmd -> {
86+
for (String arg : testPathArgs) {
87+
cmd.addArguments("--app-content", arg);
88+
}
89+
})
90+
.addInstallVerifier(cmd -> {
91+
ApplicationLayout appLayout = cmd.appLayout();
92+
Path contentDir = appLayout.contentDirectory();
93+
for (String arg : testPathArgs) {
94+
List<String> paths = Arrays.asList(arg.split(","));
95+
for (String p : paths) {
96+
Path name = Path.of(p).getFileName();
97+
TKit.assertPathExists(contentDir.resolve(name), true);
98+
}
99+
}
100+
101+
})
102+
.setExpectedExitCode(testPathArgs.contains(TEST_BAD) ? 1 : 0)
103+
.run();
104+
}
105+
}

0 commit comments

Comments
 (0)
Please sign in to comment.