Skip to content

Commit b523c88

Browse files
author
Alexander Matveev
committed
8286122: [macos]: App bundle cannot upload to Mac App Store due to info.plist embedded in java exe
Reviewed-by: asemenyuk, kcr
1 parent 8323787 commit b523c88

File tree

7 files changed

+220
-5
lines changed

7 files changed

+220
-5
lines changed

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

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, 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
@@ -38,7 +38,6 @@
3838
import java.util.Set;
3939
import java.util.TreeMap;
4040
import java.util.TreeSet;
41-
import java.util.stream.Collectors;
4241
import java.util.stream.Stream;
4342

4443
/**
@@ -146,6 +145,7 @@ static void validateName(String s, boolean forApp)
146145
}
147146
}
148147

148+
@SuppressWarnings("unchecked")
149149
public void validate() throws PackagerException {
150150
boolean hasModule = (bundlerArguments.get(
151151
Arguments.CLIOptions.MODULE.getId()) != null);
@@ -161,6 +161,8 @@ public void validate() throws PackagerException {
161161
Arguments.CLIOptions.INPUT.getId()) != null);
162162
boolean hasModulePath = (bundlerArguments.get(
163163
Arguments.CLIOptions.MODULE_PATH.getId()) != null);
164+
boolean hasMacAppStore = (bundlerArguments.get(
165+
Arguments.CLIOptions.MAC_APP_STORE.getId()) != null);
164166
boolean runtimeInstaller = !isTargetAppImage() &&
165167
!hasAppImage && !hasModule && !hasMain && hasRuntimeImage;
166168

@@ -273,6 +275,45 @@ public void validate() throws PackagerException {
273275
Path.of(icon).toAbsolutePath().toString());
274276
}
275277
}
278+
279+
280+
if (hasMacAppStore) {
281+
// Validate jlink-options if mac-app-store is set
282+
Object jlinkOptions = bundlerArguments.get(
283+
Arguments.CLIOptions.JLINK_OPTIONS.getId());
284+
if (jlinkOptions instanceof List) {
285+
List<String> options = (List<String>) jlinkOptions;
286+
if (!options.contains("--strip-native-commands")) {
287+
throw new PackagerException(
288+
"ERR_MissingJLinkOptMacAppStore",
289+
"--strip-native-commands");
290+
}
291+
}
292+
293+
// Validate runtime if mac-app-store is set. Predefined runtime
294+
// should not contain "bin" folder.
295+
runtime = (String)bundlerArguments.get(
296+
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId());
297+
if (runtime != null) {
298+
// Should exist from check above if not null
299+
Path topImage = Path.of(runtime);
300+
301+
// On Mac topImage can be runtime root or runtime home.
302+
Path runtimeHome = topImage.resolve("Contents/Home");
303+
if (Files.isDirectory(runtimeHome)) {
304+
// topImage references runtime root, adjust it to pick data
305+
// from runtime home
306+
topImage = runtimeHome;
307+
}
308+
309+
Path runtimeBin = topImage.resolve("bin");
310+
if (Files.isDirectory(runtimeBin)) {
311+
throw new PackagerException(
312+
"ERR_MacAppStoreRuntimeBinExists",
313+
topImage.toAbsolutePath().toString());
314+
}
315+
}
316+
}
276317
}
277318

278319
void setTargetFormat(String t) {

src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ ERR_NoEntryPoint=Error: creating application image requires --main-jar or --modu
109109
ERR_InputNotDirectory=Error: Input directory specified is not a directory: {0}
110110
ERR_CannotReadInputDir=Error: No permission to read from input directory: {0}
111111
ERR_CannotParseOptions=Error: Processing @filename option: {0}
112+
ERR_MissingJLinkOptMacAppStore=Error: --mac-app-store argument requires a {0} option for --jlink-options argument
113+
ERR_MacAppStoreRuntimeBinExists=Error: Runtime image "{0}" should not contain "bin" folder. Use --strip-native-commands jlink option when generating runtime image used with --mac-app-store argument.

src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_de.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2017, 2022, 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
@@ -108,3 +108,5 @@ ERR_NoEntryPoint=Fehler: F\u00FCr das Erstellen des Anwendungsimages muss entwed
108108
ERR_InputNotDirectory=Fehler: Das angegebene Eingabeverzeichnis ist kein Verzeichnis: {0}
109109
ERR_CannotReadInputDir=Fehler: Keine Berechtigung zum Lesen aus Eingabeverzeichnis vorhanden: {0}
110110
ERR_CannotParseOptions=Fehler: Option @filename wird verarbeitet: {0}
111+
ERR_MissingJLinkOptMacAppStore=Error: --mac-app-store argument requires a {0} option for --jlink-options argument
112+
ERR_MacAppStoreRuntimeBinExists=Error: Runtime image "{0}" should not contain "bin" folder. Use --strip-native-commands jlink option when generating runtime image used with --mac-app-store argument.

src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2017, 2022, 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
@@ -108,3 +108,5 @@ ERR_NoEntryPoint=\u30A8\u30E9\u30FC: \u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\
108108
ERR_InputNotDirectory=\u30A8\u30E9\u30FC: \u6307\u5B9A\u3055\u308C\u305F\u5165\u529B\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306F\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u306F\u3042\u308A\u307E\u305B\u3093: {0}
109109
ERR_CannotReadInputDir=\u30A8\u30E9\u30FC: \u5165\u529B\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304B\u3089\u8AAD\u307F\u53D6\u308B\u6A29\u9650\u304C\u3042\u308A\u307E\u305B\u3093: {0}
110110
ERR_CannotParseOptions=\u30A8\u30E9\u30FC: @filename\u30AA\u30D7\u30B7\u30E7\u30F3\u306E\u51E6\u7406: {0}
111+
ERR_MissingJLinkOptMacAppStore=Error: --mac-app-store argument requires a {0} option for --jlink-options argument
112+
ERR_MacAppStoreRuntimeBinExists=Error: Runtime image "{0}" should not contain "bin" folder. Use --strip-native-commands jlink option when generating runtime image used with --mac-app-store argument.

src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2017, 2022, 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
@@ -108,3 +108,5 @@ ERR_NoEntryPoint=\u9519\u8BEF\uFF1A\u521B\u5EFA\u5E94\u7528\u7A0B\u5E8F\u6620\u5
108108
ERR_InputNotDirectory=\u9519\u8BEF\uFF1A\u6307\u5B9A\u7684\u8F93\u5165\u76EE\u5F55\u4E0D\u662F\u76EE\u5F55\uFF1A{0}
109109
ERR_CannotReadInputDir=\u9519\u8BEF\uFF1A\u65E0\u6743\u4ECE\u8F93\u5165\u76EE\u5F55\u8BFB\u53D6\uFF1A{0}
110110
ERR_CannotParseOptions=\u9519\u8BEF\uFF1A\u6B63\u5728\u5904\u7406 @filename \u9009\u9879\uFF1A{0}
111+
ERR_MissingJLinkOptMacAppStore=Error: --mac-app-store argument requires a {0} option for --jlink-options argument
112+
ERR_MacAppStoreRuntimeBinExists=Error: Runtime image "{0}" should not contain "bin" folder. Use --strip-native-commands jlink option when generating runtime image used with --mac-app-store argument.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2022, 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 jdk.jpackage.test.JPackageCommand;
25+
import jdk.jpackage.test.Annotations.Test;
26+
27+
/**
28+
* Tests generation of app image with --mac-app-store and --jlink-options. jpackage should able
29+
* to generate app image if "--strip-native-commands" is specified for --jlink-options and should
30+
* fail if it is not specified.
31+
*/
32+
33+
/*
34+
* @test
35+
* @summary jpackage with --mac-app-store and --jlink-options
36+
* @library ../helpers
37+
* @library /test/lib
38+
* @build jdk.jpackage.test.*
39+
* @build MacAppStoreJLinkOptionsTest
40+
* @modules jdk.jpackage/jdk.jpackage.internal
41+
* @requires (os.family == "mac")
42+
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
43+
* --jpt-run=MacAppStoreJLinkOptionsTest
44+
*/
45+
public class MacAppStoreJLinkOptionsTest {
46+
47+
@Test
48+
public static void testWithStripNativeCommands() throws Exception {
49+
JPackageCommand cmd = JPackageCommand.helloAppImage();
50+
cmd.addArguments("--mac-app-store", "--jlink-options",
51+
"--strip-debug --no-man-pages --no-header-files --strip-native-commands");
52+
53+
cmd.executeAndAssertHelloAppImageCreated();
54+
}
55+
56+
@Test
57+
public static void testWithoutStripNativeCommands() throws Exception {
58+
JPackageCommand cmd = JPackageCommand.helloAppImage();
59+
cmd.addArguments("--mac-app-store", "--jlink-options",
60+
"--strip-debug --no-man-pages --no-header-files");
61+
62+
cmd.execute(1);
63+
}
64+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2022, 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.Files;
25+
import java.nio.file.Path;
26+
import java.io.IOException;
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
30+
import jdk.jpackage.test.JPackageCommand;
31+
import jdk.jpackage.test.Executor;
32+
import jdk.jpackage.test.TKit;
33+
import jdk.jpackage.test.JavaTool;
34+
import jdk.jpackage.test.Annotations.Test;
35+
import jdk.jpackage.test.Annotations.Parameter;
36+
37+
38+
/**
39+
* Tests generation of app image with --mac-app-store and --runtime-image. jpackage should able
40+
* to generate app image if runtime image does not have "bin" folder and fail otherwise.
41+
*/
42+
43+
/*
44+
* @test
45+
* @summary jpackage with --mac-app-store and --runtime-image
46+
* @library ../helpers
47+
* @library /test/lib
48+
* @build jdk.jpackage.test.*
49+
* @build MacAppStoreRuntimeTest
50+
* @modules jdk.jpackage/jdk.jpackage.internal
51+
* @requires (os.family == "mac")
52+
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
53+
* --jpt-run=MacAppStoreRuntimeTest
54+
*/
55+
public class MacAppStoreRuntimeTest {
56+
57+
private static String getRuntimeImage(boolean stripNativeCommands) throws IOException {
58+
final Path workDir = TKit.createTempDirectory("runtime").resolve("data");
59+
final Path jlinkOutputDir = workDir.resolve("temp.runtime");
60+
Files.createDirectories(jlinkOutputDir.getParent());
61+
62+
// List of modules required for test app.
63+
final var modules = new String[] {
64+
"java.base",
65+
"java.desktop"
66+
};
67+
68+
List<String> jlinkArgs = new ArrayList<>();
69+
jlinkArgs.add("--output");
70+
jlinkArgs.add(jlinkOutputDir.toString());
71+
jlinkArgs.add("--add-modules");
72+
jlinkArgs.add(String.join(",", modules));
73+
jlinkArgs.add("--strip-debug");
74+
jlinkArgs.add("--no-header-files");
75+
jlinkArgs.add("--no-man-pages");
76+
if (stripNativeCommands) {
77+
jlinkArgs.add("--strip-native-commands");
78+
}
79+
80+
new Executor()
81+
.setToolProvider(JavaTool.JLINK)
82+
.dumpOutput()
83+
.addArguments(jlinkArgs)
84+
.execute();
85+
86+
return jlinkOutputDir.toString();
87+
}
88+
89+
@Test
90+
@Parameter("true")
91+
@Parameter("false")
92+
public static void test(boolean stripNativeCommands) throws Exception {
93+
JPackageCommand cmd = JPackageCommand.helloAppImage();
94+
cmd.addArguments("--mac-app-store", "--runtime-image", getRuntimeImage(stripNativeCommands));
95+
96+
if (stripNativeCommands) {
97+
cmd.executeAndAssertHelloAppImageCreated();
98+
} else {
99+
cmd.execute(1);
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)