Skip to content

Commit b054a56

Browse files
author
Alexander Matveev
committed
8351095: [macos] Add more jpackage tests for --mac-app-store option
Reviewed-by: asemenyuk
1 parent 847fbab commit b054a56

File tree

5 files changed

+65
-25
lines changed

5 files changed

+65
-25
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public void applyTo(ConfigurationTarget target) {
149149
applyToAdditionalLauncher(target);
150150
}
151151
target.test().ifPresent(pkg -> {
152-
pkg.addInstallVerifier(this::verifyLauncherExecuted);
152+
pkg.addInstallVerifier(cmd -> {
153+
if (!MacHelper.isForAppStore(cmd)) {
154+
verifyLauncherExecuted(cmd);
155+
}
156+
});
153157
});
154158
}
155159

@@ -239,7 +243,9 @@ private static Map<Boolean, List<String>> partitionLaunchers(JPackageCommand cmd
239243
}
240244

241245
static boolean launcherAsService(JPackageCommand cmd, String launcherName) {
242-
if (cmd.isMainLauncher(launcherName)) {
246+
if (MacHelper.isForAppStore(cmd)) {
247+
return false;
248+
} else if (cmd.isMainLauncher(launcherName)) {
243249
return PropertyFinder.findLauncherProperty(cmd, null,
244250
PropertyFinder.cmdlineBooleanOption("--launcher-as-service"),
245251
PropertyFinder.nop(),

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,15 @@ private static String getPackageId(JPackageCommand cmd) {
797797
).orElseGet(cmd::name);
798798
}
799799

800+
public static boolean isForAppStore(JPackageCommand cmd) {
801+
return PropertyFinder.findAppProperty(cmd,
802+
PropertyFinder.cmdlineBooleanOption("--mac-app-store"),
803+
PropertyFinder.appImageFile(appImageFile -> {
804+
return Boolean.toString(appImageFile.macAppStore());
805+
})
806+
).map(Boolean::parseBoolean).orElse(false);
807+
}
808+
800809
public static boolean isXcodeDevToolsInstalled() {
801810
return Inner.XCODE_DEV_TOOLS_INSTALLED;
802811
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ static Finder<PropertyFile> launcherPropertyFile(String propertyName) {
106106

107107
static Finder<JPackageCommand> cmdlineBooleanOption(String optionName) {
108108
return target -> {
109-
return Optional.of(target.hasArgument(optionName)).map(Boolean::valueOf).map(Object::toString);
109+
if (target.hasArgument(optionName)) {
110+
return Optional.of(Boolean.TRUE.toString());
111+
} else {
112+
return Optional.empty();
113+
}
110114
};
111115
}
112116

test/jdk/tools/jpackage/macosx/PkgScriptsTest.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
import java.nio.file.Path;
25+
import java.util.ArrayList;
2526
import java.util.Collection;
2627
import java.util.HashSet;
2728
import java.util.List;
@@ -32,6 +33,7 @@
3233
import jdk.jpackage.test.Annotations.Test;
3334
import jdk.jpackage.test.JPackageCommand;
3435
import jdk.jpackage.test.JPackageStringBundle;
36+
import jdk.jpackage.test.MacHelper;
3537
import jdk.jpackage.test.PackageTest;
3638
import jdk.jpackage.test.PackageType;
3739
import jdk.jpackage.test.TKit;
@@ -50,24 +52,23 @@
5052
*/
5153
public class PkgScriptsTest {
5254

53-
public static Collection<?> input() {
54-
return List.of(new Object[][]{
55-
{ new PkgInstallScript[]{
56-
PkgInstallScript.PREINSTALL,
57-
PkgInstallScript.POSTINSTALL },
58-
},
59-
{ new PkgInstallScript[]{
60-
PkgInstallScript.PREINSTALL },
61-
},
62-
{ new PkgInstallScript[]{
63-
PkgInstallScript.POSTINSTALL },
64-
},
65-
});
55+
public static Collection<Object[]> input() {
56+
List<Object[]> data = new ArrayList<>();
57+
for (var appStore : List.of(true, false)) {
58+
for (var scriptRoles : List.of(
59+
List.of(PkgInstallScript.PREINSTALL, PkgInstallScript.POSTINSTALL),
60+
List.of(PkgInstallScript.PREINSTALL),
61+
List.of(PkgInstallScript.POSTINSTALL)
62+
)) {
63+
data.add(new Object[] {scriptRoles.toArray(PkgInstallScript[]::new), appStore});
64+
}
65+
}
66+
return data;
6667
}
6768

6869
@Test
6970
@ParameterSupplier("input")
70-
public void test(PkgInstallScript[] customScriptRoles) {
71+
public void test(PkgInstallScript[] customScriptRoles, boolean appStore) {
7172
var responseDir = TKit.createTempDirectory("response");
7273

7374
var customScripts = Stream.of(customScriptRoles).map(role -> {
@@ -80,6 +81,9 @@ public void test(PkgInstallScript[] customScriptRoles) {
8081
.forTypes(PackageType.MAC_PKG)
8182
.configureHelloApp()
8283
.addInitializer(cmd -> {
84+
if (appStore) {
85+
cmd.addArgument("--mac-app-store");
86+
}
8387
cmd.addArguments("--resource-dir", TKit.createTempDirectory("resources"));
8488
customScripts.forEach(customScript -> {
8589
customScript.createFor(cmd);
@@ -156,10 +160,13 @@ void createFor(JPackageCommand cmd) {
156160
}
157161

158162
void verify(JPackageCommand cmd) {
163+
var scriptsEnabled = !MacHelper.isForAppStore(cmd);
159164
if (cmd.isPackageUnpacked()) {
160-
role.verifyExists(cmd, true);
161-
} else {
165+
role.verifyExists(cmd, scriptsEnabled);
166+
} else if (scriptsEnabled) {
162167
TKit.assertFileExists(responseFilePath(cmd));
168+
} else {
169+
TKit.assertPathExists(responseFilePath(cmd), false);
163170
}
164171
}
165172

test/jdk/tools/jpackage/share/ServiceTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.function.Consumer;
3434
import java.util.stream.Stream;
3535
import jdk.jpackage.test.AdditionalLauncher;
36+
import jdk.internal.util.OperatingSystem;
3637
import jdk.jpackage.test.Annotations.Parameter;
3738
import jdk.jpackage.test.Annotations.Test;
3839
import jdk.jpackage.test.ConfigurationTarget;
@@ -155,14 +156,21 @@ public void testUpdate() throws Throwable {
155156
}
156157

157158
@Test
158-
@Parameter("true")
159-
@Parameter("false")
160-
public void testAddL(boolean mainLauncherAsService) {
159+
@Parameter(value = {"true", "false"})
160+
@Parameter(value = {"false", "false"})
161+
@Parameter(value = {"true", "true"}, ifOS = OperatingSystem.MACOS)
162+
@Parameter(value = {"false", "true"}, ifOS = OperatingSystem.MACOS)
163+
public void testAddL(boolean mainLauncherAsService, boolean isMacAppStore) {
161164

162165
final var uniqueOutputFile = uniqueOutputFile();
163166

164167
createPackageTest()
165168
.addHelloAppInitializer("com.buz.AddLaunchersServiceTest")
169+
.addInitializer(cmd -> {
170+
if (isMacAppStore) {
171+
cmd.addArgument("--mac-app-store");
172+
}
173+
})
166174
.mutate(test -> {
167175
if (mainLauncherAsService) {
168176
LauncherAsServiceVerifier.build()
@@ -199,9 +207,11 @@ public void testAddL(boolean mainLauncherAsService) {
199207
}
200208

201209
@Test
202-
@Parameter("true")
203-
@Parameter("false")
204-
public void testAddLFromAppImage(boolean mainLauncherAsService) {
210+
@Parameter(value = {"true", "false"})
211+
@Parameter(value = {"false", "false"})
212+
@Parameter(value = {"true", "true"}, ifOS = OperatingSystem.MACOS)
213+
@Parameter(value = {"false", "true"}, ifOS = OperatingSystem.MACOS)
214+
public void testAddLFromAppImage(boolean mainLauncherAsService, boolean isMacAppStore) {
205215

206216
var uniqueOutputFile = uniqueOutputFile();
207217

@@ -213,6 +223,10 @@ public void testAddLFromAppImage(boolean mainLauncherAsService) {
213223
appImageCmd.addInitializer(JPackageCommand::ignoreFakeRuntime);
214224
}
215225

226+
if (isMacAppStore) {
227+
appImageCmd.cmd().orElseThrow().addArgument("--mac-app-store");
228+
}
229+
216230
if (mainLauncherAsService) {
217231
LauncherAsServiceVerifier.build()
218232
.mutate(uniqueOutputFile).appendAppOutputFileNamePrefix("-")

0 commit comments

Comments
 (0)