Skip to content

Commit 402a6f4

Browse files
Merge branch 'JDK-8353196-full' into JDK-8333664+JDK-8353196-full
2 parents c179c54 + 31fff85 commit 402a6f4

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

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

Lines changed: 35 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 (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

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.file.Files;
3333
import java.nio.file.Path;
3434
import java.util.List;
35+
import java.util.Objects;
3536
import java.util.Optional;
3637
import java.util.Set;
3738
import java.util.regex.Pattern;
@@ -144,6 +145,32 @@ public static PListReader readPList(Stream<String> lines) {
144145
.collect(Collectors.joining()).getBytes(StandardCharsets.UTF_8))).get();
145146
}
146147

148+
public static boolean signPredefinedAppImage(JPackageCommand cmd) {
149+
Objects.requireNonNull(cmd);
150+
if (!TKit.isOSX()) {
151+
throw new UnsupportedOperationException();
152+
}
153+
return cmd.hasArgument("--mac-sign") && cmd.hasArgument("--app-image");
154+
}
155+
156+
public static boolean appImageSigned(JPackageCommand cmd) {
157+
Objects.requireNonNull(cmd);
158+
if (!TKit.isOSX()) {
159+
throw new UnsupportedOperationException();
160+
}
161+
162+
if (Optional.ofNullable(cmd.getArgumentValue("--app-image")).map(Path::of).map(AppImageFile::load).map(AppImageFile::macSigned).orElse(false)) {
163+
// The external app image is signed, so the app image is signed too.
164+
return true;
165+
}
166+
167+
if (!cmd.hasArgument("--mac-sign")) {
168+
return false;
169+
}
170+
171+
return (cmd.hasArgument("--mac-signing-key-user-name") || cmd.hasArgument("--mac-app-image-sign-identity"));
172+
}
173+
147174
static PackageHandlers createDmgPackageHandlers() {
148175
return new PackageHandlers(MacHelper::installDmg, MacHelper::uninstallDmg, MacHelper::unpackDmg);
149176
}

0 commit comments

Comments
 (0)