30
30
import static jdk .jpackage .internal .MacApplicationBuilder .isValidBundleIdentifier ;
31
31
import static jdk .jpackage .internal .StandardBundlerParam .SIGN_BUNDLE ;
32
32
33
- import java .io .ByteArrayOutputStream ;
34
33
import java .io .IOException ;
35
- import java .io .PrintStream ;
36
34
import java .io .PrintWriter ;
37
35
import java .net .URI ;
38
36
import java .net .URISyntaxException ;
51
49
import javax .xml .stream .XMLStreamWriter ;
52
50
import jdk .internal .util .Architecture ;
53
51
import jdk .internal .util .OSVersion ;
52
+ import jdk .jpackage .internal .PackagingPipeline .PackageBuildEnv ;
53
+ import jdk .jpackage .internal .model .AppImageLayout ;
54
54
import jdk .jpackage .internal .model .ConfigException ;
55
55
import jdk .jpackage .internal .model .MacApplication ;
56
+ import jdk .jpackage .internal .model .MacDmgPackage ;
56
57
import jdk .jpackage .internal .model .MacPkgPackage ;
57
58
import jdk .jpackage .internal .model .PackagerException ;
58
59
import jdk .jpackage .internal .util .FileUtils ;
@@ -100,6 +101,10 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
100
101
},
101
102
(s , p ) -> s );
102
103
104
+ private static Path installLocation (MacPkgPackage pkg ) {
105
+ return Path .of ("/" ).resolve (pkg .relativeInstallDir ()).getParent ();
106
+ }
107
+
103
108
public Path bundle (Map <String , ? super Object > params ,
104
109
Path outdir ) throws PackagerException {
105
110
@@ -111,20 +116,25 @@ public Path bundle(Map<String, ? super Object> params,
111
116
112
117
IOUtils .writableOutputDir (outdir );
113
118
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 );
116
126
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
+ }
122
129
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 );
127
135
}
136
+
137
+ createPKG (env .pkg (), env .env (), env .outputDir ());
128
138
}
129
139
130
140
private Path packagesRoot (BuildEnv env ) {
@@ -366,49 +376,36 @@ private void patchCPLFile(Path cpl) throws IOException {
366
376
// based on doc "any .svn or CVS directories, and any .DS_Store files".
367
377
// So easy approach will be to copy user provided app-image into temp folder
368
378
// 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
373
381
// if parent does not have any other files
374
382
if (!pkg .isRuntimeInstaller ()) {
383
+ final Path rootDir = env .appImageDir ().getParent ();
375
384
try (var fileList = Files .list (rootDir )) {
376
385
Path [] list = fileList .toArray (Path []::new );
377
386
// We should only have app image and/or .DS_Store
378
387
if (list .length == 1 ) {
379
- return rootDir ;
388
+ return env ;
380
389
} else if (list .length == 2 ) {
381
390
// Check case with app image and .DS_Store
382
391
if (list [0 ].toString ().toLowerCase ().endsWith (".ds_store" ) ||
383
392
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
385
394
}
386
395
}
387
396
}
388
- }
389
-
390
- // Copy to new root
391
- Path newRoot = Files .createTempDirectory (
392
- env .buildRoot (), "root-" );
393
397
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 ());
395
402
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 );
402
404
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 );
408
406
}
409
- FileUtils .copyRecursive (source , dest );
410
407
411
- return newRoot ;
408
+ return env ;
412
409
}
413
410
414
411
private boolean withServicesPkg (MacPkgPackage pkg , BuildEnv env ) {
@@ -486,21 +483,21 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
486
483
487
484
Files .createDirectories (packagesRoot (env ));
488
485
489
- Path root = getRoot (pkg , env );
486
+ env = prepareAppImage (pkg , env );
490
487
491
488
if (withServicesPkg (pkg , env )) {
492
489
createServicesPkg (pkg , env );
493
490
}
494
491
495
- final var installDir = Path . of ( "/" ). resolve ( pkg . relativeInstallDir () ).toString ();
492
+ final var installLocation = installLocation ( pkg ).toString ();
496
493
497
494
// Generate default CPL file
498
495
Path cpl = env .configDir ().resolve ("cpl.plist" );
499
496
ProcessBuilder pb = new ProcessBuilder ("/usr/bin/pkgbuild" ,
500
497
"--root" ,
501
- root .toString (),
498
+ env . appImageDir () .toString (),
502
499
"--install-location" ,
503
- installDir ,
500
+ installLocation ,
504
501
"--analyze" ,
505
502
cpl .toAbsolutePath ().toString ());
506
503
@@ -512,31 +509,30 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
512
509
if (((MacApplication )pkg .app ()).appStore ()) {
513
510
pb = new ProcessBuilder ("/usr/bin/pkgbuild" ,
514
511
"--root" ,
515
- root .toString (),
512
+ env . appImageDir () .toString (),
516
513
"--install-location" ,
517
- installDir ,
514
+ installLocation ,
518
515
"--component-plist" ,
519
516
cpl .toAbsolutePath ().toString (),
520
517
"--identifier" ,
521
518
((MacApplication )pkg .app ()).bundleIdentifier (),
522
519
appPKG .toAbsolutePath ().toString ());
523
- IOUtils .exec (pb , false , null , true , Executor .INFINITE_TIMEOUT );
524
520
} else {
525
521
preparePackageScripts (pkg , env );
526
522
pb = new ProcessBuilder ("/usr/bin/pkgbuild" ,
527
523
"--root" ,
528
- root .toString (),
524
+ env . appImageDir () .toString (),
529
525
"--install-location" ,
530
- installDir ,
526
+ installLocation ,
531
527
"--component-plist" ,
532
528
cpl .toAbsolutePath ().toString (),
533
529
"--scripts" ,
534
530
scriptsRoot (env ).toAbsolutePath ().toString (),
535
531
"--identifier" ,
536
532
((MacApplication )pkg .app ()).bundleIdentifier (),
537
533
appPKG .toAbsolutePath ().toString ());
538
- IOUtils .exec (pb , false , null , true , Executor .INFINITE_TIMEOUT );
539
534
}
535
+ IOUtils .exec (pb , false , null , true , Executor .INFINITE_TIMEOUT );
540
536
541
537
// build final package
542
538
Path finalPKG = outdir .resolve (pkg .packageFileNameWithSuffix ());
@@ -571,9 +567,9 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
571
567
commandLine .add (getConfig_PDF (pkg , env )
572
568
.toAbsolutePath ().toString ());
573
569
commandLine .add ("--component" );
574
- Path p = root .resolve (pkg .app ().appImageDirName ());
570
+ Path p = env . appImageDir () .resolve (pkg .app ().appImageDirName ());
575
571
commandLine .add (p .toAbsolutePath ().toString ());
576
- commandLine .add (installDir );
572
+ commandLine .add (installLocation );
577
573
} else {
578
574
commandLine .add ("--distribution" );
579
575
commandLine .add (getConfig_DistributionXMLFile (pkg , env )
@@ -584,21 +580,7 @@ private Path createPKG(MacPkgPackage pkg, BuildEnv env, Path outdir) {
584
580
commandLine .add (finalPKG .toAbsolutePath ().toString ());
585
581
586
582
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 );
602
584
603
585
return finalPKG ;
604
586
} catch (Exception ignored ) {
0 commit comments