Skip to content

Commit 6a700c2

Browse files
Support async test execution in jpackage test lib
1 parent bd9a9d6 commit 6a700c2

File tree

5 files changed

+233
-131
lines changed

5 files changed

+233
-131
lines changed

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

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.security.SecureRandom;
4040
import java.util.ArrayList;
4141
import java.util.Collection;
42-
import java.util.HashMap;
4342
import java.util.Iterator;
4443
import java.util.List;
4544
import java.util.ListIterator;
@@ -668,15 +667,15 @@ public boolean isPackageUnpacked() {
668667
}
669668

670669
public static void useToolProviderByDefault(ToolProvider jpackageToolProvider) {
671-
defaultToolProvider = Optional.of(jpackageToolProvider);
670+
defaultToolProvider.set(Optional.of(jpackageToolProvider));
672671
}
673672

674673
public static void useToolProviderByDefault() {
675674
useToolProviderByDefault(JavaTool.JPACKAGE.asToolProvider());
676675
}
677676

678677
public static void useExecutableByDefault() {
679-
defaultToolProvider = Optional.empty();
678+
defaultToolProvider.set(Optional.empty());
680679
}
681680

682681
public JPackageCommand useToolProvider(boolean v) {
@@ -785,7 +784,9 @@ public JPackageCommand validateOutput(CannedFormattedString... str) {
785784
}
786785

787786
public boolean isWithToolProvider() {
788-
return Optional.ofNullable(withToolProvider).orElseGet(defaultToolProvider::isPresent);
787+
return Optional.ofNullable(withToolProvider).orElseGet(() -> {
788+
return defaultToolProvider.get().isPresent();
789+
});
789790
}
790791

791792
public JPackageCommand executePrerequisiteActions() {
@@ -801,7 +802,7 @@ private Executor createExecutor() {
801802
.addArguments(args);
802803

803804
if (isWithToolProvider()) {
804-
exec.setToolProvider(defaultToolProvider.orElseGet(JavaTool.JPACKAGE::asToolProvider));
805+
exec.setToolProvider(defaultToolProvider.get().orElseGet(JavaTool.JPACKAGE::asToolProvider));
805806
} else {
806807
exec.setExecutable(JavaTool.JPACKAGE);
807808
if (TKit.isWindows()) {
@@ -1233,10 +1234,7 @@ public void assertFileNotInAppImage(Path filename) {
12331234

12341235
private void assertFileInAppImage(Path filename, Path expectedPath) {
12351236
if (expectedPath != null) {
1236-
if (expectedPath.isAbsolute()) {
1237-
throw new IllegalArgumentException();
1238-
}
1239-
if (!expectedPath.getFileName().equals(filename.getFileName())) {
1237+
if (expectedPath.isAbsolute() || !expectedPath.getFileName().equals(filename.getFileName())) {
12401238
throw new IllegalArgumentException();
12411239
}
12421240
}
@@ -1322,7 +1320,7 @@ private JPackageCommand adjustArgumentsBeforeExecution() {
13221320
addArguments("--runtime-image", DEFAULT_RUNTIME_IMAGE);
13231321
}
13241322

1325-
if (!hasArgument("--verbose") && TKit.VERBOSE_JPACKAGE && !ignoreDefaultVerbose) {
1323+
if (!hasArgument("--verbose") && TKit.verboseJPackage() && !ignoreDefaultVerbose) {
13261324
addArgument("--verbose");
13271325
}
13281326

@@ -1346,11 +1344,7 @@ public void verifyIsOfType(PackageType ... types) {
13461344
final var typesSet = Stream.of(types).collect(Collectors.toSet());
13471345
if (!hasArgument("--type")) {
13481346
if (!isImagePackageType()) {
1349-
if (TKit.isLinux() && typesSet.equals(PackageType.LINUX)) {
1350-
return;
1351-
}
1352-
1353-
if (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS)) {
1347+
if ((TKit.isLinux() && typesSet.equals(PackageType.LINUX)) || (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS))) {
13541348
return;
13551349
}
13561350

@@ -1500,29 +1494,16 @@ public void run() {
15001494
private Set<ReadOnlyPathAssert> readOnlyPathAsserts = Set.of(ReadOnlyPathAssert.values());
15011495
private Set<AppLayoutAssert> appLayoutAsserts = Set.of(AppLayoutAssert.values());
15021496
private List<Consumer<Iterator<String>>> outputValidators = new ArrayList<>();
1503-
private static Optional<ToolProvider> defaultToolProvider = Optional.empty();
1497+
private static ThreadLocal<Optional<ToolProvider>> defaultToolProvider = InheritableThreadLocal.withInitial(Optional::empty);
15041498

1505-
private static final Map<String, PackageType> PACKAGE_TYPES = Functional.identity(
1506-
() -> {
1507-
Map<String, PackageType> reply = new HashMap<>();
1508-
for (PackageType type : PackageType.values()) {
1509-
reply.put(type.getType(), type);
1510-
}
1511-
return reply;
1512-
}).get();
1513-
1514-
public static final Path DEFAULT_RUNTIME_IMAGE = Functional.identity(() -> {
1515-
// Set the property to the path of run-time image to speed up
1516-
// building app images and platform bundles by avoiding running jlink
1517-
// The value of the property will be automativcally appended to
1518-
// jpackage command line if the command line doesn't have
1519-
// `--runtime-image` parameter set.
1520-
String val = TKit.getConfigProperty("runtime-image");
1521-
if (val != null) {
1522-
return Path.of(val);
1523-
}
1524-
return null;
1525-
}).get();
1499+
private static final Map<String, PackageType> PACKAGE_TYPES = Stream.of(PackageType.values()).collect(toMap(PackageType::getType, x -> x));
1500+
1501+
// Set the property to the path of run-time image to speed up
1502+
// building app images and platform bundles by avoiding running jlink.
1503+
// The value of the property will be automatically appended to
1504+
// jpackage command line if the command line doesn't have
1505+
// `--runtime-image` parameter set.
1506+
public static final Path DEFAULT_RUNTIME_IMAGE = Optional.ofNullable(TKit.getConfigProperty("runtime-image")).map(Path::of).orElse(null);
15261507

15271508
// [HH:mm:ss.SSS]
15281509
private static final Pattern TIMESTAMP_REGEXP = Pattern.compile(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141

4242
public final class Main {
4343

44-
public static void main(String args[]) throws Throwable {
44+
public static void main(String... args) throws Throwable {
4545
main(TestBuilder.build(), args);
4646
}
4747

48-
public static void main(TestBuilder.Builder builder, String args[]) throws Throwable {
48+
public static void main(TestBuilder.Builder builder, String... args) throws Throwable {
4949
boolean listTests = false;
5050
List<TestInstance> tests = new ArrayList<>();
5151
try (TestBuilder testBuilder = builder.testConsumer(tests::add).create()) {

0 commit comments

Comments
 (0)