Skip to content

Commit 5bcf780

Browse files
author
duke
committedOct 22, 2021
Automatic merge of jdk:master into master
2 parents 18c2333 + b2128a9 commit 5bcf780

File tree

8 files changed

+170
-17
lines changed

8 files changed

+170
-17
lines changed
 

‎src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.text.MessageFormat;
3535
import java.util.Base64;
3636
import java.util.HashMap;
37+
import java.util.List;
3738
import java.util.Map;
3839
import java.util.Objects;
3940
import java.util.ResourceBundle;
@@ -46,6 +47,7 @@
4647
import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE;
4748
import static jdk.jpackage.internal.StandardBundlerParam.TEMP_ROOT;
4849
import static jdk.jpackage.internal.StandardBundlerParam.VERBOSE;
50+
import static jdk.jpackage.internal.StandardBundlerParam.DMG_CONTENT;
4951

5052
public class MacDmgBundler extends MacBaseInstallerBundler {
5153

@@ -79,7 +81,7 @@ public Path bundle(Map<String, ? super Object> params,
7981
try {
8082
Path appLocation = prepareAppBundle(params);
8183

82-
if (appLocation != null && prepareConfigFiles(params)) {
84+
if (appLocation != null && prepareConfigFiles(appLocation,params)) {
8385
Path configScript = getConfig_Script(params);
8486
if (IOUtils.exists(configScript)) {
8587
IOUtils.run("bash", configScript);
@@ -96,8 +98,8 @@ public Path bundle(Map<String, ? super Object> params,
9698

9799
private static final String hdiutil = "/usr/bin/hdiutil";
98100

99-
private void prepareDMGSetupScript(Map<String, ? super Object> params)
100-
throws IOException {
101+
private void prepareDMGSetupScript(Path appLocation,
102+
Map<String, ? super Object> params) throws IOException {
101103
Path dmgSetup = getConfig_VolumeScript(params);
102104
Log.verbose(MessageFormat.format(
103105
I18N.getString("message.preparing-dmg-setup"),
@@ -125,7 +127,9 @@ private void prepareDMGSetupScript(Map<String, ? super Object> params)
125127
data.put("DEPLOY_BG_FILE", bgFile.toString());
126128
data.put("DEPLOY_VOLUME_PATH", volumePath.toString());
127129
data.put("DEPLOY_APPLICATION_NAME", APP_NAME.fetchFrom(params));
128-
130+
String targetItem = (StandardBundlerParam.isRuntimeInstaller(params)) ?
131+
APP_NAME.fetchFrom(params) : appLocation.getFileName().toString();
132+
data.put("DEPLOY_TARGET", targetItem);
129133
data.put("DEPLOY_INSTALL_LOCATION", getInstallDir(params, true));
130134

131135
createResource(DEFAULT_DMG_SETUP_SCRIPT, params)
@@ -181,8 +185,8 @@ private void prepareLicense(Map<String, ? super Object> params) {
181185
}
182186
}
183187

184-
private boolean prepareConfigFiles(Map<String, ? super Object> params)
185-
throws IOException {
188+
private boolean prepareConfigFiles(Path appLocation,
189+
Map<String, ? super Object> params) throws IOException {
186190

187191
createResource(DEFAULT_BACKGROUND_IMAGE, params)
188192
.setCategory(I18N.getString("resource.dmg-background"))
@@ -199,7 +203,7 @@ private boolean prepareConfigFiles(Map<String, ? super Object> params)
199203

200204
prepareLicense(params);
201205

202-
prepareDMGSetupScript(params);
206+
prepareDMGSetupScript(appLocation, params);
203207

204208
return true;
205209
}
@@ -313,7 +317,11 @@ private Path buildDMG( Map<String, ? super Object> params,
313317

314318
String hdiUtilVerbosityFlag = VERBOSE.fetchFrom(params) ?
315319
"-verbose" : "-quiet";
316-
320+
List <String> dmgContent = DMG_CONTENT.fetchFrom(params);
321+
for (String content : dmgContent) {
322+
Path path = Path.of(content);
323+
IOUtils.copyRecursive(path, srcFolder.resolve(path.getFileName()));
324+
}
317325
// create temp image
318326
ProcessBuilder pb = new ProcessBuilder(
319327
hdiutil,

‎src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/DMGsetup.scpt

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@ tell application "Finder"
2020
make new alias file at POSIX file "DEPLOY_VOLUME_PATH" to POSIX file "DEPLOY_INSTALL_LOCATION" with properties {name:"DEPLOY_INSTALL_LOCATION"}
2121

2222
set allTheFiles to the name of every item of theWindow
23+
set xpos to 120
2324
repeat with theFile in allTheFiles
2425
set theFilePath to POSIX path of theFile
26+
set appFilePath to POSIX path of "/DEPLOY_TARGET"
2527
if theFilePath is "DEPLOY_INSTALL_LOCATION" then
2628
-- Position install location
2729
set position of item theFile of theWindow to {390, 130}
28-
else
30+
else if theFilePath ends with appFilePath then
2931
-- Position application or runtime
3032
set position of item theFile of theWindow to {120, 130}
33+
else
34+
-- Position all other items in a second row.
35+
set position of item theFile of theWindow to {xpos, 290}
36+
set xpos to xpos + 150
3137
end if
3238
end repeat
3339

40+
3441
update theDisk without registering applications
3542
delay 5
3643
close (get window of theDisk)

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

+10
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ public enum CLIOptions {
179179
setOptionValue("resource-dir", resourceDir);
180180
}),
181181

182+
DMG_CONTENT ("mac-dmg-content", OptionCategories.PROPERTY, () -> {
183+
List<String> content = getArgumentList(popArg());
184+
content.forEach(a -> setOptionValue("mac-dmg-content", a));
185+
}),
186+
182187
ARGUMENTS ("arguments", OptionCategories.PROPERTY, () -> {
183188
List<String> arguments = getArgumentList(popArg());
184189
setOptionValue("arguments", arguments);
@@ -625,6 +630,11 @@ private void validateArguments() throws PackagerException {
625630
CLIOptions.JLINK_OPTIONS.getIdWithPrefix());
626631
}
627632
}
633+
if (allOptions.contains(CLIOptions.DMG_CONTENT)
634+
&& !("dmg".equals(type))) {
635+
throw new PackagerException("ERR_InvalidTypeOption",
636+
CLIOptions.DMG_CONTENT.getIdWithPrefix(), ptype);
637+
}
628638
if (hasMainJar && hasMainModule) {
629639
throw new PackagerException("ERR_BothMainJarAndModule");
630640
}

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

+5-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.DMG_CONTENT.getID(),
297298
StandardBundlerParam.APP_CONTENT.getID(),
298299
StandardBundlerParam.JLINK_OPTIONS.getID()
299300
));
@@ -307,8 +308,10 @@ public void addBundleArgument(String key, Object value) {
307308
String delim = "\n\n";
308309
if (key.equals(StandardBundlerParam.MODULE_PATH.getID())) {
309310
delim = File.pathSeparator;
310-
} else if (key.equals(StandardBundlerParam.ADD_MODULES.getID()) ||
311-
key.equals(StandardBundlerParam.APP_CONTENT.getID())) {
311+
} else if (
312+
key.equals(StandardBundlerParam.DMG_CONTENT.getID()) ||
313+
key.equals(StandardBundlerParam.APP_CONTENT.getID()) ||
314+
key.equals(StandardBundlerParam.ADD_MODULES.getID())) {
312315
delim = ",";
313316
}
314317
bundlerArguments.put(key, existingValue + delim + value);

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

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

407+
@SuppressWarnings("unchecked")
408+
static final BundlerParamInfo<List<String>> DMG_CONTENT =
409+
new StandardBundlerParam<>(
410+
Arguments.CLIOptions.DMG_CONTENT.getId(),
411+
(Class<List<String>>) (Object)List.class,
412+
p -> Collections.emptyList(),
413+
(s, p) -> Arrays.asList(s.split(","))
414+
);
415+
407416
@SuppressWarnings("unchecked")
408417
static final StandardBundlerParam<List<String>> APP_CONTENT =
409418
new StandardBundlerParam<>(
410419
Arguments.CLIOptions.APP_CONTENT.getId(),
411420
(Class<List<String>>) (Object)List.class,
412421
p->Collections.emptyList(),
413422
(s, p) -> Arrays.asList(s.split(","))
414-
415423
);
416424

417425
@SuppressWarnings("unchecked")

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

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ enum USE {
119119
options.put(CLIOptions.MAC_APP_STORE.getId(), USE.ALL);
120120
options.put(CLIOptions.MAC_CATEGORY.getId(), USE.ALL);
121121
options.put(CLIOptions.MAC_ENTITLEMENTS.getId(), USE.ALL);
122+
options.put(CLIOptions.DMG_CONTENT.getId(), USE.INSTALL);
122123
}
123124

124125
if (Platform.getPlatform() == Platform.LINUX) {

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/MacHelper.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ public static void withExplodedDmg(JPackageCommand cmd,
6262

6363
final Path mountPoint = Path.of(plist.queryValue("mount-point"));
6464
try {
65-
Path dmgImage = mountPoint.resolve(cmd.name() +
66-
(cmd.isRuntime() ? "" : ".app"));
67-
TKit.trace(String.format("Exploded [%s] in [%s] directory",
68-
cmd.outputBundle(), dmgImage));
69-
ThrowingConsumer.toConsumer(consumer).accept(dmgImage);
65+
// code here used to copy just <runtime name> or <app name>.app
66+
// We now have option to include arbitrary content, so we copy
67+
// everything in the mounted image.
68+
String[] children = mountPoint.toFile().list();
69+
for (String child : children) {
70+
Path childPath = mountPoint.resolve(child);
71+
TKit.trace(String.format("Exploded [%s] in [%s] directory",
72+
cmd.outputBundle(), childPath));
73+
ThrowingConsumer.toConsumer(consumer).accept(childPath);
74+
}
7075
} finally {
7176
String cmdline[] = {
7277
"/usr/bin/hdiutil",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2019, 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 jdk.jpackage.test.JPackageCommand;
26+
import jdk.jpackage.test.PackageTest;
27+
import jdk.jpackage.test.PackageType;
28+
import jdk.jpackage.test.MacHelper;
29+
import jdk.jpackage.test.TKit;
30+
31+
import jdk.jpackage.test.Annotations.Parameter;
32+
import jdk.jpackage.test.Annotations.Parameters;
33+
import jdk.jpackage.test.Annotations.Test;
34+
35+
import java.util.Collection;
36+
import java.util.Arrays;
37+
import java.util.ArrayList;
38+
import java.util.List;
39+
40+
/*
41+
* @test
42+
* @summary jpackage with --type dmg --mac-dmg-content
43+
* @library ../helpers
44+
* @library /test/lib
45+
* @library base
46+
* @key jpackagePlatformPackage
47+
* @build jdk.jpackage.test.*
48+
* @build DmgContentTest
49+
* @modules jdk.jpackage/jdk.jpackage.internal
50+
* @requires (os.family == "mac")
51+
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
52+
* --jpt-run=DmgContentTest
53+
*/
54+
public class DmgContentTest {
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+
@Parameters
66+
public static Collection input() {
67+
List<Object[]> data = new ArrayList<>();
68+
data.addAll(List.of(new Object[][] {
69+
{"0", PackageType.MAC_DMG, new String[] {TEST_JAVA, TEST_DUKE}},
70+
{"1", PackageType.MAC_PKG, new String[] {TEST_JAVA, TEST_DUKE}},
71+
{"1", PackageType.MAC_DMG, new String[] {TEST_JAVA, TEST_BAD}},
72+
{"0", PackageType.MAC_DMG,
73+
new String[] {TEST_JAVA + "," + TEST_DUKE, TEST_DIR}}}));
74+
return data;
75+
}
76+
77+
public DmgContentTest(String expected, PackageType type, String[] content) {
78+
this.expected = Integer.parseInt(expected);
79+
this.type = type;
80+
this.content = content;
81+
}
82+
83+
@Test
84+
public void test() {
85+
new PackageTest()
86+
.forTypes(type)
87+
.configureHelloApp()
88+
.addInitializer(cmd -> {
89+
for (String arg : content) {
90+
cmd.addArguments("--mac-dmg-content", arg);
91+
}
92+
})
93+
.addInstallVerifier(DmgContentTest::verifyDMG)
94+
.setExpectedExitCode(expected)
95+
.run(PackageTest.Action.CREATE_AND_UNPACK);
96+
}
97+
98+
private static void verifyDMG(JPackageCommand cmd) {
99+
if (cmd.isPackageUnpacked()) {
100+
Path installDir = cmd.appInstallationDirectory();
101+
Path dmgRoot = cmd.pathToUnpackedPackageFile(installDir)
102+
.toAbsolutePath().getParent();
103+
TKit.assertFileExists(dmgRoot.resolve("PrintEnv.java"));
104+
}
105+
}
106+
107+
private final int expected;
108+
private final PackageType type;
109+
private final String[] content;
110+
111+
}

0 commit comments

Comments
 (0)
Please sign in to comment.