Skip to content

Commit 0755118

Browse files
Initial commit
1 parent 642504b commit 0755118

File tree

2 files changed

+53
-146
lines changed

2 files changed

+53
-146
lines changed

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,20 @@
2525

2626
package jdk.jpackage.internal;
2727

28-
import jdk.jpackage.internal.model.ConfigException;
29-
import java.io.IOException;
28+
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
29+
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;
30+
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE_FILE;
31+
import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE;
32+
3033
import java.nio.file.Files;
3134
import java.nio.file.Path;
3235
import java.text.MessageFormat;
3336
import java.util.Map;
3437
import java.util.Optional;
35-
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
36-
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
37-
import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR;
38-
import static jdk.jpackage.internal.StandardBundlerParam.OUTPUT_DIR;
39-
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;
40-
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE_FILE;
41-
import static jdk.jpackage.internal.StandardBundlerParam.VERSION;
42-
import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE;
43-
import jdk.jpackage.internal.util.FileUtils;
38+
import jdk.jpackage.internal.model.ConfigException;
4439

4540
public abstract class MacBaseInstallerBundler extends AbstractBundler {
4641

47-
static final BundlerParamInfo<Path> IMAGES_ROOT =
48-
new BundlerParamInfo<>(
49-
"imagesRoot",
50-
Path.class,
51-
params -> {
52-
final var env = BuildEnvFromParams.BUILD_ENV.fetchFrom(params);
53-
return env.buildRoot().resolve("images");
54-
},
55-
(s, p) -> null);
56-
57-
private final BundlerParamInfo<Path> APP_IMAGE_TEMP_ROOT =
58-
new BundlerParamInfo<>(
59-
"mac.app.imageRoot",
60-
Path.class,
61-
params -> {
62-
Path imageDir = IMAGES_ROOT.fetchFrom(params);
63-
try {
64-
if (!IOUtils.exists(imageDir)) {
65-
Files.createDirectories(imageDir);
66-
}
67-
return Files.createTempDirectory(
68-
imageDir, "image-");
69-
} catch (IOException e) {
70-
return imageDir.resolve(getID()+ ".image");
71-
}
72-
},
73-
(s, p) -> Path.of(s));
74-
7542
public static final BundlerParamInfo<String> SIGNING_KEY_USER =
7643
new BundlerParamInfo<>(
7744
Arguments.CLIOptions.MAC_SIGNING_KEY_NAME.getId(),
@@ -86,48 +53,6 @@ public abstract class MacBaseInstallerBundler extends AbstractBundler {
8653
params -> "",
8754
null);
8855

89-
public static final BundlerParamInfo<String> INSTALLER_SIGN_IDENTITY =
90-
new BundlerParamInfo<>(
91-
Arguments.CLIOptions.MAC_INSTALLER_SIGN_IDENTITY.getId(),
92-
String.class,
93-
params -> "",
94-
null);
95-
96-
public static final BundlerParamInfo<String> MAC_INSTALLER_NAME =
97-
new BundlerParamInfo<> (
98-
"mac.installerName",
99-
String.class,
100-
params -> {
101-
String nm = INSTALLER_NAME.fetchFrom(params);
102-
if (nm == null) return null;
103-
104-
String version = VERSION.fetchFrom(params);
105-
if (version == null) {
106-
return nm;
107-
} else {
108-
return nm + "-" + version;
109-
}
110-
},
111-
(s, p) -> s);
112-
113-
// Returns full path to installation directory
114-
static String getInstallDir(
115-
Map<String, ? super Object> params, boolean defaultOnly) {
116-
String returnValue = INSTALL_DIR.fetchFrom(params);
117-
if (defaultOnly && returnValue != null) {
118-
Log.info(I18N.getString("message.install-dir-ignored"));
119-
returnValue = null;
120-
}
121-
if (returnValue == null) {
122-
if (StandardBundlerParam.isRuntimeInstaller(params)) {
123-
returnValue = "/Library/Java/JavaVirtualMachines";
124-
} else {
125-
returnValue = "/Applications";
126-
}
127-
}
128-
return returnValue;
129-
}
130-
13156
public MacBaseInstallerBundler() {
13257
appImageBundler = new MacAppBundler();
13358
}

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java

Lines changed: 47 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import static jdk.jpackage.internal.MacApplicationBuilder.isValidBundleIdentifier;
3131
import static jdk.jpackage.internal.StandardBundlerParam.SIGN_BUNDLE;
3232

33-
import java.io.ByteArrayOutputStream;
3433
import java.io.IOException;
35-
import java.io.PrintStream;
3634
import java.io.PrintWriter;
3735
import java.net.URI;
3836
import java.net.URISyntaxException;
@@ -51,8 +49,11 @@
5149
import javax.xml.stream.XMLStreamWriter;
5250
import jdk.internal.util.Architecture;
5351
import jdk.internal.util.OSVersion;
52+
import jdk.jpackage.internal.PackagingPipeline.PackageBuildEnv;
53+
import jdk.jpackage.internal.model.AppImageLayout;
5454
import jdk.jpackage.internal.model.ConfigException;
5555
import jdk.jpackage.internal.model.MacApplication;
56+
import jdk.jpackage.internal.model.MacDmgPackage;
5657
import jdk.jpackage.internal.model.MacPkgPackage;
5758
import jdk.jpackage.internal.model.PackagerException;
5859
import jdk.jpackage.internal.util.FileUtils;
@@ -100,6 +101,10 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
100101
},
101102
(s, p) -> s);
102103

104+
private static Path installLocation(MacPkgPackage pkg) {
105+
return Path.of("/").resolve(pkg.relativeInstallDir()).getParent();
106+
}
107+
103108
public Path bundle(Map<String, ? super Object> params,
104109
Path outdir) throws PackagerException {
105110

@@ -111,20 +116,25 @@ public Path bundle(Map<String, ? super Object> params,
111116

112117
IOUtils.writableOutputDir(outdir);
113118

114-
try {
115-
env = BuildEnv.withAppImageDir(env, prepareAppBundle(params));
119+
MacPackagingPipeline.build(Optional.of(pkg))
120+
.excludeDirFromCopying(outdir)
121+
.excludeDirFromCopying(StandardBundlerParam.OUTPUT_DIR.fetchFrom(params))
122+
.task(PackagingPipeline.PrimaryTaskID.PACKAGE)
123+
.packageAction(this::buildPackage)
124+
.add()
125+
.create().execute(env, pkg, outdir);
116126

117-
prepareConfigFiles(pkg, env);
118-
Path configScript = getConfig_Script(pkg, env);
119-
if (IOUtils.exists(configScript)) {
120-
IOUtils.run("bash", configScript);
121-
}
127+
return outdir.resolve(pkg.packageFileNameWithSuffix()).toAbsolutePath();
128+
}
122129

123-
return createPKG(pkg, env, outdir);
124-
} catch (IOException | PackagerException ex) {
125-
Log.verbose(ex);
126-
throw new PackagerException(ex);
130+
private void buildPackage(PackageBuildEnv<MacPkgPackage, AppImageLayout> env) throws PackagerException, IOException {
131+
prepareConfigFiles(env.pkg(), env.env());
132+
Path configScript = getConfig_Script(env.pkg(), env.env());
133+
if (IOUtils.exists(configScript)) {
134+
IOUtils.run("bash", configScript);
127135
}
136+
137+
createPKG(env.pkg(), env.env(), env.outputDir());
128138
}
129139

130140
private Path packagesRoot(BuildEnv env) {
@@ -366,49 +376,36 @@ private void patchCPLFile(Path cpl) throws IOException {
366376
// based on doc "any .svn or CVS directories, and any .DS_Store files".
367377
// So easy approach will be to copy user provided app-image into temp folder
368378
// if root path contains other files.
369-
private Path getRoot(MacPkgPackage pkg, BuildEnv env) throws IOException {
370-
Path rootDir = env.appImageDir().getParent();
371-
372-
// Not needed for runtime installer and it might break runtime installer
379+
private BuildEnv prepareAppImage(MacPkgPackage pkg, BuildEnv env) throws IOException {
380+
// Not needed for runtime installer and it might break runtime installer
373381
// if parent does not have any other files
374382
if (!pkg.isRuntimeInstaller()) {
383+
final Path rootDir = env.appImageDir().getParent();
375384
try (var fileList = Files.list(rootDir)) {
376385
Path[] list = fileList.toArray(Path[]::new);
377386
// We should only have app image and/or .DS_Store
378387
if (list.length == 1) {
379-
return rootDir;
388+
return env;
380389
} else if (list.length == 2) {
381390
// Check case with app image and .DS_Store
382391
if (list[0].toString().toLowerCase().endsWith(".ds_store") ||
383392
list[1].toString().toLowerCase().endsWith(".ds_store")) {
384-
return rootDir; // Only app image and .DS_Store
393+
return env; // Only app image and .DS_Store
385394
}
386395
}
387396
}
388-
}
389-
390-
// Copy to new root
391-
Path newRoot = Files.createTempDirectory(
392-
env.buildRoot(), "root-");
393397

394-
Path source, dest;
398+
// Copy to new root
399+
Path newRoot = Files.createTempDirectory(env.buildRoot(), "root-");
400+
Path source = env.appImageDir();
401+
Path dest = newRoot.resolve(source.getFileName());
395402

396-
if (pkg.isRuntimeInstaller()) {
397-
// firs, is this already a runtime with
398-
// <runtime>/Contents/Home - if so we need the Home dir
399-
Path original = env.appImageDir();
400-
Path home = original.resolve("Contents/Home");
401-
source = (Files.exists(home)) ? home : original;
403+
FileUtils.copyRecursive(source, dest);
402404

403-
// Then we need to put back the <NAME>/Content/Home
404-
dest = newRoot.resolve(((MacApplication)pkg.app()).bundleIdentifier() + "/Contents/Home");
405-
} else {
406-
source = env.appImageDir();
407-
dest = newRoot.resolve(source.getFileName());
405+
return BuildEnv.withAppImageDir(env, dest);
408406
}
409-
FileUtils.copyRecursive(source, dest);
410407

411-
return newRoot;
408+
return env;
412409
}
413410

414411
private boolean withServicesPkg(MacPkgPackage pkg, BuildEnv env) {
@@ -486,21 +483,21 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
486483

487484
Files.createDirectories(packagesRoot(env));
488485

489-
Path root = getRoot(pkg, env);
486+
env = prepareAppImage(pkg, env);
490487

491488
if (withServicesPkg(pkg, env)) {
492489
createServicesPkg(pkg, env);
493490
}
494491

495-
final var installDir = Path.of("/").resolve(pkg.relativeInstallDir()).toString();
492+
final var installLocation = installLocation(pkg).toString();
496493

497494
// Generate default CPL file
498495
Path cpl = env.configDir().resolve("cpl.plist");
499496
ProcessBuilder pb = new ProcessBuilder("/usr/bin/pkgbuild",
500497
"--root",
501-
root.toString(),
498+
env.appImageDir().toString(),
502499
"--install-location",
503-
installDir,
500+
installLocation,
504501
"--analyze",
505502
cpl.toAbsolutePath().toString());
506503

@@ -512,31 +509,30 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
512509
if (((MacApplication)pkg.app()).appStore()) {
513510
pb = new ProcessBuilder("/usr/bin/pkgbuild",
514511
"--root",
515-
root.toString(),
512+
env.appImageDir().toString(),
516513
"--install-location",
517-
installDir,
514+
installLocation,
518515
"--component-plist",
519516
cpl.toAbsolutePath().toString(),
520517
"--identifier",
521518
((MacApplication)pkg.app()).bundleIdentifier(),
522519
appPKG.toAbsolutePath().toString());
523-
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
524520
} else {
525521
preparePackageScripts(pkg, env);
526522
pb = new ProcessBuilder("/usr/bin/pkgbuild",
527523
"--root",
528-
root.toString(),
524+
env.appImageDir().toString(),
529525
"--install-location",
530-
installDir,
526+
installLocation,
531527
"--component-plist",
532528
cpl.toAbsolutePath().toString(),
533529
"--scripts",
534530
scriptsRoot(env).toAbsolutePath().toString(),
535531
"--identifier",
536532
((MacApplication)pkg.app()).bundleIdentifier(),
537533
appPKG.toAbsolutePath().toString());
538-
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
539534
}
535+
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
540536

541537
// build final package
542538
Path finalPKG = outdir.resolve(pkg.packageFileNameWithSuffix());
@@ -571,9 +567,9 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
571567
commandLine.add(getConfig_PDF(pkg, env)
572568
.toAbsolutePath().toString());
573569
commandLine.add("--component");
574-
Path p = root.resolve(pkg.app().appImageDirName());
570+
Path p = env.appImageDir().resolve(pkg.app().appImageDirName());
575571
commandLine.add(p.toAbsolutePath().toString());
576-
commandLine.add(installDir);
572+
commandLine.add(installLocation);
577573
} else {
578574
commandLine.add("--distribution");
579575
commandLine.add(getConfig_DistributionXMLFile(pkg, env)
@@ -584,21 +580,7 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
584580
commandLine.add(finalPKG.toAbsolutePath().toString());
585581

586582
pb = new ProcessBuilder(commandLine);
587-
588-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
589-
PrintStream ps = new PrintStream(baos)) {
590-
try {
591-
IOUtils.exec(pb, false, ps, true, Executor.INFINITE_TIMEOUT);
592-
} catch (IOException ioe) {
593-
// Log output of "productbuild" in case of
594-
// error. It should help user to diagnose
595-
// issue when using --mac-installer-sign-identity
596-
Log.info(MessageFormat.format(I18N.getString(
597-
"error.tool.failed.with.output"), "productbuild"));
598-
Log.info(baos.toString().strip());
599-
throw ioe;
600-
}
601-
}
583+
IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT);
602584

603585
return finalPKG;
604586
} catch (Exception ignored) {

0 commit comments

Comments
 (0)