Skip to content

Commit b3c387b

Browse files
Fix JPackageCommand.macAppImageSigned() and move it together with JPackageCommand.signPredefinedAppImage() to MacHelper class
1 parent 336fe3a commit b3c387b

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

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

Lines changed: 3 additions & 27 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 (macSignPredefinedAppImage()) {
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 {
@@ -942,7 +942,7 @@ private boolean expectAppImageFile() {
942942
}
943943

944944
if (TKit.isOSX()) {
945-
if (macSignPredefinedAppImage()) {
945+
if (MacHelper.signPredefinedAppImage(this)) {
946946
// Request to sign external app image, ".jpackage.xml" file should exist.
947947
return true;
948948
}
@@ -957,30 +957,6 @@ private boolean expectAppImageFile() {
957957
return isImagePackageType();
958958
}
959959

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-
984960
private void assertAppImageFile() {
985961
Path appImageDir = Path.of("");
986962
if (isImagePackageType() && hasArgument("--app-image")) {
@@ -999,7 +975,7 @@ private void assertAppImageFile() {
999975

1000976
AppImageFile aif = AppImageFile.load(rootDir);
1001977

1002-
boolean expectedValue = macAppImageSigned();
978+
boolean expectedValue = MacHelper.appImageSigned(this);
1003979
boolean actualValue = aif.macSigned();
1004980
TKit.assertEquals(expectedValue, actualValue,
1005981
"Check for unexpected value of <signed> property in app image file");

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.nio.file.Path;
3434
import java.util.ArrayList;
3535
import java.util.List;
36+
import java.util.Objects;
3637
import java.util.Optional;
3738
import java.util.Set;
3839
import java.util.regex.Pattern;
@@ -149,6 +150,32 @@ public static PListWrapper readPList(Stream<String> lines) {
149150
.collect(Collectors.joining()))).get();
150151
}
151152

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

0 commit comments

Comments
 (0)