Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,14 @@ private boolean isPathEmpty() {

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

return Path.of(cmd.getArgumentValue(argName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
Expand Down Expand Up @@ -691,15 +690,15 @@ public boolean isPackageUnpacked() {
}

public static void useToolProviderByDefault(ToolProvider jpackageToolProvider) {
defaultToolProvider = Optional.of(jpackageToolProvider);
defaultToolProvider.set(Optional.of(jpackageToolProvider));
}

public static void useToolProviderByDefault() {
useToolProviderByDefault(JavaTool.JPACKAGE.asToolProvider());
}

public static void useExecutableByDefault() {
defaultToolProvider = Optional.empty();
defaultToolProvider.set(Optional.empty());
}

public JPackageCommand useToolProvider(boolean v) {
Expand Down Expand Up @@ -808,7 +807,9 @@ public JPackageCommand validateOutput(CannedFormattedString... str) {
}

public boolean isWithToolProvider() {
return Optional.ofNullable(withToolProvider).orElseGet(defaultToolProvider::isPresent);
return Optional.ofNullable(withToolProvider).orElseGet(() -> {
return defaultToolProvider.get().isPresent();
});
}

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

if (isWithToolProvider()) {
exec.setToolProvider(defaultToolProvider.orElseGet(JavaTool.JPACKAGE::asToolProvider));
exec.setToolProvider(defaultToolProvider.get().orElseGet(JavaTool.JPACKAGE::asToolProvider));
} else {
exec.setExecutable(JavaTool.JPACKAGE);
if (TKit.isWindows()) {
Expand Down Expand Up @@ -1256,10 +1257,7 @@ public void assertFileNotInAppImage(Path filename) {

private void assertFileInAppImage(Path filename, Path expectedPath) {
if (expectedPath != null) {
if (expectedPath.isAbsolute()) {
throw new IllegalArgumentException();
}
if (!expectedPath.getFileName().equals(filename.getFileName())) {
if (expectedPath.isAbsolute() || !expectedPath.getFileName().equals(filename.getFileName())) {
throw new IllegalArgumentException();
}
}
Expand Down Expand Up @@ -1345,7 +1343,7 @@ private JPackageCommand adjustArgumentsBeforeExecution() {
addArguments("--runtime-image", DEFAULT_RUNTIME_IMAGE);
}

if (!hasArgument("--verbose") && TKit.VERBOSE_JPACKAGE && !ignoreDefaultVerbose) {
if (!hasArgument("--verbose") && TKit.verboseJPackage() && !ignoreDefaultVerbose) {
addArgument("--verbose");
}

Expand All @@ -1369,11 +1367,7 @@ public void verifyIsOfType(PackageType ... types) {
final var typesSet = Stream.of(types).collect(Collectors.toSet());
if (!hasArgument("--type")) {
if (!isImagePackageType()) {
if (TKit.isLinux() && typesSet.equals(PackageType.LINUX)) {
return;
}

if (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS)) {
if ((TKit.isLinux() && typesSet.equals(PackageType.LINUX)) || (TKit.isWindows() && typesSet.equals(PackageType.WINDOWS))) {
return;
}

Expand Down Expand Up @@ -1523,29 +1517,21 @@ public void run() {
private Set<ReadOnlyPathAssert> readOnlyPathAsserts = Set.of(ReadOnlyPathAssert.values());
private Set<AppLayoutAssert> appLayoutAsserts = Set.of(AppLayoutAssert.values());
private List<Consumer<Iterator<String>>> outputValidators = new ArrayList<>();
private static Optional<ToolProvider> defaultToolProvider = Optional.empty();

private static final Map<String, PackageType> PACKAGE_TYPES = Functional.identity(
() -> {
Map<String, PackageType> reply = new HashMap<>();
for (PackageType type : PackageType.values()) {
reply.put(type.getType(), type);
}
return reply;
}).get();

public static final Path DEFAULT_RUNTIME_IMAGE = Functional.identity(() -> {
// Set the property to the path of run-time image to speed up
// building app images and platform bundles by avoiding running jlink
// The value of the property will be automativcally appended to
// jpackage command line if the command line doesn't have
// `--runtime-image` parameter set.
String val = TKit.getConfigProperty("runtime-image");
if (val != null) {
return Path.of(val);
private static InheritableThreadLocal<Optional<ToolProvider>> defaultToolProvider = new InheritableThreadLocal<>() {
@Override
protected Optional<ToolProvider> initialValue() {
return Optional.empty();
}
return null;
}).get();
};

private static final Map<String, PackageType> PACKAGE_TYPES = Stream.of(PackageType.values()).collect(toMap(PackageType::getType, x -> x));

// Set the property to the path of run-time image to speed up
// building app images and platform bundles by avoiding running jlink.
// The value of the property will be automatically appended to
// jpackage command line if the command line doesn't have
// `--runtime-image` parameter set.
public static final Path DEFAULT_RUNTIME_IMAGE = Optional.ofNullable(TKit.getConfigProperty("runtime-image")).map(Path::of).orElse(null);

// [HH:mm:ss.SSS]
private static final Pattern TIMESTAMP_REGEXP = Pattern.compile(
Expand Down
4 changes: 2 additions & 2 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

public final class Main {

public static void main(String args[]) throws Throwable {
public static void main(String... args) throws Throwable {
main(TestBuilder.build(), args);
}

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