@@ -374,7 +374,7 @@ public Path outputBundle() {
374374 String dirName ;
375375 if (!TKit .isOSX ()) {
376376 dirName = name ();
377- } else if (hasArgument ( "--app-image" ) && hasArgument ( "--mac-sign" )) {
377+ } else if (MacHelper . signPredefinedAppImage ( this )) {
378378 // Request to sign external app image, not to build a new one
379379 dirName = getArgumentValue ("--app-image" );
380380 } else {
@@ -936,38 +936,54 @@ JPackageCommand assertAppLayout() {
936936 return this ;
937937 }
938938
939+ private boolean expectAppImageFile () {
940+ if (isRuntime ()) {
941+ return false ;
942+ }
943+
944+ if (TKit .isOSX ()) {
945+ if (MacHelper .signPredefinedAppImage (this )) {
946+ // Request to sign external app image, ".jpackage.xml" file should exist.
947+ return true ;
948+ }
949+
950+ if (!isImagePackageType () && hasArgument ("--app-image" )) {
951+ // Build native macOS package from an external app image.
952+ // If the external app image is signed, ".jpackage.xml" file should be kept, otherwise removed.
953+ return AppImageFile .load (Path .of (getArgumentValue ("--app-image" ))).macSigned ();
954+ }
955+ }
956+
957+ return isImagePackageType ();
958+ }
959+
939960 private void assertAppImageFile () {
940961 Path appImageDir = Path .of ("" );
941962 if (isImagePackageType () && hasArgument ("--app-image" )) {
942963 appImageDir = Path .of (getArgumentValue ("--app-image" ));
943964 }
944965
945966 final Path lookupPath = AppImageFile .getPathInAppImage (appImageDir );
946- if (isRuntime () || (! isImagePackageType () && ! TKit . isOSX () )) {
967+ if (! expectAppImageFile ( )) {
947968 assertFileInAppImage (lookupPath , null );
948- } else if (!TKit .isOSX ()) {
949- assertFileInAppImage (lookupPath , lookupPath );
950969 } else {
951970 assertFileInAppImage (lookupPath , lookupPath );
952971
953- // If file exist validated important values based on arguments
954- // Exclude validation when we generating packages from predefined
955- // app images, since we do not know if image is signed or not.
956- if (isImagePackageType () || !hasArgument ("--app-image" )) {
972+ if (TKit .isOSX ()) {
957973 final Path rootDir = isImagePackageType () ? outputBundle () :
958974 pathToUnpackedPackageFile (appInstallationDirectory ());
959975
960976 AppImageFile aif = AppImageFile .load (rootDir );
961977
962- boolean expectedValue = hasArgument ( "--mac-sign" );
978+ boolean expectedValue = MacHelper . appImageSigned ( this );
963979 boolean actualValue = aif .macSigned ();
964- TKit .assertEquals (Boolean . toString ( expectedValue ), Boolean . toString ( actualValue ) ,
965- "Check for unexptected value in app image file for <signed> " );
980+ TKit .assertEquals (expectedValue , actualValue ,
981+ "Check for unexpected value of <signed> property in app image file" );
966982
967983 expectedValue = hasArgument ("--mac-app-store" );
968984 actualValue = aif .macAppStore ();
969- TKit .assertEquals (Boolean . toString ( expectedValue ), Boolean . toString ( actualValue ) ,
970- "Check for unexptected value in app image file for <app-store> " );
985+ TKit .assertEquals (expectedValue , actualValue ,
986+ "Check for unexpected value of <app-store> property in app image file" );
971987 }
972988 }
973989 }
@@ -1037,11 +1053,17 @@ JPackageCommand setUnpackedPackageLocation(Path path) {
10371053 }
10381054
10391055 JPackageCommand winMsiLogFile (Path v ) {
1056+ if (!TKit .isWindows ()) {
1057+ throw new UnsupportedOperationException ();
1058+ }
10401059 this .winMsiLogFile = v ;
10411060 return this ;
10421061 }
10431062
10441063 public Optional <Path > winMsiLogFile () {
1064+ if (!TKit .isWindows ()) {
1065+ throw new UnsupportedOperationException ();
1066+ }
10451067 return Optional .ofNullable (winMsiLogFile );
10461068 }
10471069
0 commit comments