Skip to content

Commit 40ba4da

Browse files
Adjust JPackageCommand.assertAppImageFile()
1 parent 58ef401 commit 40ba4da

File tree

1 file changed

+59
-13
lines changed

1 file changed

+59
-13
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (macSignPredefinedAppImage()) {
378378
// Request to sign external app image, not to build a new one
379379
dirName = getArgumentValue("--app-image");
380380
} else {
@@ -936,38 +936,78 @@ 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 (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+
939984
private void assertAppImageFile() {
940985
Path appImageDir = Path.of("");
941986
if (isImagePackageType() && hasArgument("--app-image")) {
942987
appImageDir = Path.of(getArgumentValue("--app-image"));
943988
}
944989

945990
final Path lookupPath = AppImageFile.getPathInAppImage(appImageDir);
946-
if (isRuntime() || (!isImagePackageType() && !TKit.isOSX())) {
991+
if (!expectAppImageFile()) {
947992
assertFileInAppImage(lookupPath, null);
948-
} else if (!TKit.isOSX()) {
949-
assertFileInAppImage(lookupPath, lookupPath);
950993
} else {
951994
assertFileInAppImage(lookupPath, lookupPath);
952995

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()) {
957997
final Path rootDir = isImagePackageType() ? outputBundle() :
958998
pathToUnpackedPackageFile(appInstallationDirectory());
959999

9601000
AppImageFile aif = AppImageFile.load(rootDir);
9611001

962-
boolean expectedValue = hasArgument("--mac-sign");
1002+
boolean expectedValue = macAppImageSigned();
9631003
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");
9661006

9671007
expectedValue = hasArgument("--mac-app-store");
9681008
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");
9711011
}
9721012
}
9731013
}
@@ -1037,11 +1077,17 @@ JPackageCommand setUnpackedPackageLocation(Path path) {
10371077
}
10381078

10391079
JPackageCommand winMsiLogFile(Path v) {
1080+
if (!TKit.isWindows()) {
1081+
throw new UnsupportedOperationException();
1082+
}
10401083
this.winMsiLogFile = v;
10411084
return this;
10421085
}
10431086

10441087
public Optional<Path> winMsiLogFile() {
1088+
if (!TKit.isWindows()) {
1089+
throw new UnsupportedOperationException();
1090+
}
10451091
return Optional.ofNullable(winMsiLogFile);
10461092
}
10471093

0 commit comments

Comments
 (0)