Skip to content

Commit c781a2f

Browse files
author
Alexey Semenyuk
committed
8370136: Support async execution of jpackage tests
Reviewed-by: almatvee
1 parent a1302e5 commit c781a2f

File tree

7 files changed

+299
-147
lines changed

7 files changed

+299
-147
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,14 @@ private boolean isPathEmpty() {
374374

375375
private static Path setupDirectory(JPackageCommand cmd, String argName) {
376376
if (!cmd.hasArgument(argName)) {
377-
// Use absolute path as jpackage can be executed in another directory
378-
cmd.setArgumentValue(argName, TKit.createTempDirectory("stash-script-resource-dir").toAbsolutePath());
377+
// Use absolute path as jpackage can be executed in another directory.
378+
// Some tests expect a specific last argument, don't interfere with them
379+
// and insert the argument at the beginning of the command line.
380+
List<String> args = new ArrayList<>();
381+
args.add(argName);
382+
args.add(TKit.createTempDirectory("stash-script-resource-dir").toAbsolutePath().toString());
383+
args.addAll(cmd.getAllArguments());
384+
cmd.clearArguments().addArguments(args);
379385
}
380386

381387
return Path.of(cmd.getArgumentValue(argName));

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

Lines changed: 23 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;
@@ -691,15 +690,15 @@ public boolean isPackageUnpacked() {
691690
}
692691

693692
public static void useToolProviderByDefault(ToolProvider jpackageToolProvider) {
694-
defaultToolProvider = Optional.of(jpackageToolProvider);
693+
defaultToolProvider.set(Optional.of(jpackageToolProvider));
695694
}
696695

697696
public static void useToolProviderByDefault() {
698697
useToolProviderByDefault(JavaTool.JPACKAGE.asToolProvider());
699698
}
700699

701700
public static void useExecutableByDefault() {
702-
defaultToolProvider = Optional.empty();
701+
defaultToolProvider.set(Optional.empty());
703702
}
704703

705704
public JPackageCommand useToolProvider(boolean v) {
@@ -808,7 +807,9 @@ public JPackageCommand validateOutput(CannedFormattedString... str) {
808807
}
809808

810809
public boolean isWithToolProvider() {
811-
return Optional.ofNullable(withToolProvider).orElseGet(defaultToolProvider::isPresent);
810+
return Optional.ofNullable(withToolProvider).orElseGet(() -> {
811+
return defaultToolProvider.get().isPresent();
812+
});
812813
}
813814

814815
public JPackageCommand executePrerequisiteActions() {
@@ -824,7 +825,7 @@ private Executor createExecutor() {
824825
.addArguments(args);
825826

826827
if (isWithToolProvider()) {
827-
exec.setToolProvider(defaultToolProvider.orElseGet(JavaTool.JPACKAGE::asToolProvider));
828+
exec.setToolProvider(defaultToolProvider.get().orElseGet(JavaTool.JPACKAGE::asToolProvider));
828829
} else {
829830
exec.setExecutable(JavaTool.JPACKAGE);
830831
if (TKit.isWindows()) {
@@ -1256,10 +1257,7 @@ public void assertFileNotInAppImage(Path filename) {
12561257

12571258
private void assertFileInAppImage(Path filename, Path expectedPath) {
12581259
if (expectedPath != null) {
1259-
if (expectedPath.isAbsolute()) {
1260-
throw new IllegalArgumentException();
1261-
}
1262-
if (!expectedPath.getFileName().equals(filename.getFileName())) {
1260+
if (expectedPath.isAbsolute() || !expectedPath.getFileName().equals(filename.getFileName())) {
12631261
throw new IllegalArgumentException();
12641262
}
12651263
}
@@ -1345,7 +1343,7 @@ private JPackageCommand adjustArgumentsBeforeExecution() {
13451343
addArguments("--runtime-image", DEFAULT_RUNTIME_IMAGE);
13461344
}
13471345

1348-
if (!hasArgument("--verbose") && TKit.VERBOSE_JPACKAGE && !ignoreDefaultVerbose) {
1346+
if (!hasArgument("--verbose") && TKit.verboseJPackage() && !ignoreDefaultVerbose) {
13491347
addArgument("--verbose");
13501348
}
13511349

@@ -1369,11 +1367,7 @@ public void verifyIsOfType(PackageType ... types) {
13691367
final var typesSet = Stream.of(types).collect(Collectors.toSet());
13701368
if (!hasArgument("--type")) {
13711369
if (!isImagePackageType()) {
1372-
if (TKit.isLinux() && typesSet.equals(PackageType.LINUX)) {
1373-
return;
1374-
}
1375-
1376-
if (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS)) {
1370+
if ((TKit.isLinux() && typesSet.equals(PackageType.LINUX)) || (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS))) {
13771371
return;
13781372
}
13791373

@@ -1523,29 +1517,21 @@ public void run() {
15231517
private Set<ReadOnlyPathAssert> readOnlyPathAsserts = Set.of(ReadOnlyPathAssert.values());
15241518
private Set<AppLayoutAssert> appLayoutAsserts = Set.of(AppLayoutAssert.values());
15251519
private List<Consumer<Iterator<String>>> outputValidators = new ArrayList<>();
1526-
private static Optional<ToolProvider> defaultToolProvider = Optional.empty();
1527-
1528-
private static final Map<String, PackageType> PACKAGE_TYPES = Functional.identity(
1529-
() -> {
1530-
Map<String, PackageType> reply = new HashMap<>();
1531-
for (PackageType type : PackageType.values()) {
1532-
reply.put(type.getType(), type);
1533-
}
1534-
return reply;
1535-
}).get();
1536-
1537-
public static final Path DEFAULT_RUNTIME_IMAGE = Functional.identity(() -> {
1538-
// Set the property to the path of run-time image to speed up
1539-
// building app images and platform bundles by avoiding running jlink
1540-
// The value of the property will be automativcally appended to
1541-
// jpackage command line if the command line doesn't have
1542-
// `--runtime-image` parameter set.
1543-
String val = TKit.getConfigProperty("runtime-image");
1544-
if (val != null) {
1545-
return Path.of(val);
1520+
private static InheritableThreadLocal<Optional<ToolProvider>> defaultToolProvider = new InheritableThreadLocal<>() {
1521+
@Override
1522+
protected Optional<ToolProvider> initialValue() {
1523+
return Optional.empty();
15461524
}
1547-
return null;
1548-
}).get();
1525+
};
1526+
1527+
private static final Map<String, PackageType> PACKAGE_TYPES = Stream.of(PackageType.values()).collect(toMap(PackageType::getType, x -> x));
1528+
1529+
// Set the property to the path of run-time image to speed up
1530+
// building app images and platform bundles by avoiding running jlink.
1531+
// The value of the property will be automatically appended to
1532+
// jpackage command line if the command line doesn't have
1533+
// `--runtime-image` parameter set.
1534+
public static final Path DEFAULT_RUNTIME_IMAGE = Optional.ofNullable(TKit.getConfigProperty("runtime-image")).map(Path::of).orElse(null);
15491535

15501536
// [HH:mm:ss.SSS]
15511537
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)