@@ -374,7 +374,7 @@ public Path outputBundle() {
374
374
String dirName ;
375
375
if (!TKit .isOSX ()) {
376
376
dirName = name ();
377
- } else if (hasArgument ( "--app-image" ) && hasArgument ( "--mac-sign" )) {
377
+ } else if (macSignPredefinedAppImage ( )) {
378
378
// Request to sign external app image, not to build a new one
379
379
dirName = getArgumentValue ("--app-image" );
380
380
} else {
@@ -936,38 +936,78 @@ JPackageCommand assertAppLayout() {
936
936
return this ;
937
937
}
938
938
939
+ private boolean expectAppImageFile () {
940
+ if (isRuntime ()) {
941
+ return false ;
942
+ }
943
+
944
+ if (TKit .isOSX ()) {
945
+ if (macSignPredefinedAppImage ()) {
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
+
960
+ boolean macSignPredefinedAppImage () {
961
+ if (!TKit .isOSX ()) {
962
+ throw new UnsupportedOperationException ();
963
+ }
964
+ return hasArgument ("--mac-sign" ) && hasArgument ("--app-image" );
965
+ }
966
+
967
+ boolean macAppImageSigned () {
968
+ if (!TKit .isOSX ()) {
969
+ throw new UnsupportedOperationException ();
970
+ }
971
+
972
+ if (!hasArgument ("--mac-sign" )) {
973
+ return false ;
974
+ }
975
+
976
+ if (Optional .ofNullable (getArgumentValue ("--app-image" )).map (Path ::of ).map (AppImageFile ::load ).map (AppImageFile ::macSigned ).orElse (false )) {
977
+ // The external app image is signed, so the app image is signed too.
978
+ return true ;
979
+ }
980
+
981
+ return (hasArgument ("--mac-signing-key-user-name" ) || hasArgument ("--mac-app-image-sign-identity" ));
982
+ }
983
+
939
984
private void assertAppImageFile () {
940
985
Path appImageDir = Path .of ("" );
941
986
if (isImagePackageType () && hasArgument ("--app-image" )) {
942
987
appImageDir = Path .of (getArgumentValue ("--app-image" ));
943
988
}
944
989
945
990
final Path lookupPath = AppImageFile .getPathInAppImage (appImageDir );
946
- if (isRuntime () || (! isImagePackageType () && ! TKit . isOSX () )) {
991
+ if (! expectAppImageFile ( )) {
947
992
assertFileInAppImage (lookupPath , null );
948
- } else if (!TKit .isOSX ()) {
949
- assertFileInAppImage (lookupPath , lookupPath );
950
993
} else {
951
994
assertFileInAppImage (lookupPath , lookupPath );
952
995
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" )) {
996
+ if (TKit .isOSX ()) {
957
997
final Path rootDir = isImagePackageType () ? outputBundle () :
958
998
pathToUnpackedPackageFile (appInstallationDirectory ());
959
999
960
1000
AppImageFile aif = AppImageFile .load (rootDir );
961
1001
962
- boolean expectedValue = hasArgument ( "--mac-sign" );
1002
+ boolean expectedValue = macAppImageSigned ( );
963
1003
boolean actualValue = aif .macSigned ();
964
- TKit .assertEquals (Boolean . toString ( expectedValue ), Boolean . toString ( actualValue ) ,
965
- "Check for unexptected value in app image file for <signed> " );
1004
+ TKit .assertEquals (expectedValue , actualValue ,
1005
+ "Check for unexpected value of <signed> property in app image file" );
966
1006
967
1007
expectedValue = hasArgument ("--mac-app-store" );
968
1008
actualValue = aif .macAppStore ();
969
- TKit .assertEquals (Boolean . toString ( expectedValue ), Boolean . toString ( actualValue ) ,
970
- "Check for unexptected value in app image file for <app-store> " );
1009
+ TKit .assertEquals (expectedValue , actualValue ,
1010
+ "Check for unexpected value of <app-store> property in app image file" );
971
1011
}
972
1012
}
973
1013
}
@@ -1037,11 +1077,17 @@ JPackageCommand setUnpackedPackageLocation(Path path) {
1037
1077
}
1038
1078
1039
1079
JPackageCommand winMsiLogFile (Path v ) {
1080
+ if (!TKit .isWindows ()) {
1081
+ throw new UnsupportedOperationException ();
1082
+ }
1040
1083
this .winMsiLogFile = v ;
1041
1084
return this ;
1042
1085
}
1043
1086
1044
1087
public Optional <Path > winMsiLogFile () {
1088
+ if (!TKit .isWindows ()) {
1089
+ throw new UnsupportedOperationException ();
1090
+ }
1045
1091
return Optional .ofNullable (winMsiLogFile );
1046
1092
}
1047
1093
0 commit comments