Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8347300: Don't exclude the "PATH" var from the environment when running app launchers in jpackage tests #22983

Closed
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
19 changes: 10 additions & 9 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,7 +53,6 @@ public static Executor of(String... cmdline) {

public Executor() {
saveOutputType = new HashSet<>(Set.of(SaveOutputType.NONE));
removePathEnvVar = false;
winEnglishOutput = false;
}

Expand Down Expand Up @@ -86,8 +85,8 @@ public Executor setExecutable(JavaTool v) {
return setExecutable(v.getPath());
}

public Executor setRemovePathEnvVar(boolean value) {
removePathEnvVar = value;
public Executor removeEnvVar(String envVarName) {
removeEnvVars.add(Objects.requireNonNull(envVarName));
return this;
}

Expand Down Expand Up @@ -372,10 +371,12 @@ private Result runExecutable() throws IOException, InterruptedException {
builder.directory(directory.toFile());
sb.append(String.format("; in directory [%s]", directory));
}
if (removePathEnvVar) {
// run this with cleared Path in Environment
TKit.trace("Clearing PATH in environment");
builder.environment().remove("PATH");
if (!removeEnvVars.isEmpty()) {
final var envComm = Comm.compare(builder.environment().keySet(), removeEnvVars);
builder.environment().keySet().removeAll(envComm.common());
envComm.common().forEach(envVar -> {
TKit.trace(String.format("Clearing %s in environment", envVar));
});
}

trace("Execute " + sb.toString() + "...");
Expand Down Expand Up @@ -504,7 +505,7 @@ private static void trace(String msg) {
private Path executable;
private Set<SaveOutputType> saveOutputType;
private Path directory;
private boolean removePathEnvVar;
private Set<String> removeEnvVars = new HashSet<>();
private boolean winEnglishOutput;
private String winTmpDir = null;

Expand Down
21 changes: 16 additions & 5 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -472,14 +472,14 @@ private Executor getExecutor(String...args) {
}
}

final List<String> launcherArgs = List.of(args);
return new Executor()
final var executor = new Executor()
.setDirectory(outputFile.getParent())
.saveOutput(saveOutput)
.dumpOutput()
.setRemovePathEnvVar(removePathEnvVar)
.setExecutable(executablePath)
.addArguments(launcherArgs);
.addArguments(List.of(args));

return configureEnvironment(executor);
}

private boolean launcherNoExit;
Expand All @@ -496,6 +496,14 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) {
return new AppOutputVerifier(helloAppLauncher);
}

public static Executor configureEnvironment(Executor executor) {
if (CLEAR_JAVA_ENV_VARS) {
executor.removeEnvVar("JAVA_TOOL_OPTIONS");
executor.removeEnvVar("_JAVA_OPTIONS");
}
return executor;
}

static final String OUTPUT_FILENAME = "appOutput.txt";

private final JavaAppDesc appDesc;
Expand All @@ -505,4 +513,7 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) {

private static final String CLASS_NAME = HELLO_JAVA.getFileName().toString().split(
"\\.", 2)[0];

private static final boolean CLEAR_JAVA_ENV_VARS = Optional.ofNullable(
TKit.getConfigProperty("clear-app-launcher-java-env-vars")).map(Boolean::parseBoolean).orElse(false);
}
6 changes: 4 additions & 2 deletions test/jdk/tools/jpackage/share/AppLauncherEnvTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,7 @@
import jdk.jpackage.test.JPackageCommand;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Executor;
import static jdk.jpackage.test.HelloApp.configureEnvironment;
import jdk.jpackage.test.TKit;

/**
Expand All @@ -53,6 +54,7 @@ public static void test() throws Exception {

JPackageCommand cmd = JPackageCommand
.helloAppImage(TEST_APP_JAVA + "*Hello")
.ignoreFakeRuntime()
.addArguments("--java-options", "-D" + testAddDirProp
+ "=$APPDIR");

Expand All @@ -62,7 +64,7 @@ public static void test() throws Exception {

final int attempts = 3;
final int waitBetweenAttemptsSeconds = 5;
List<String> output = new Executor()
List<String> output = configureEnvironment(new Executor())
.saveOutput()
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
.addArguments("--print-env-var=" + envVarName)
Expand Down
8 changes: 5 additions & 3 deletions test/jdk/tools/jpackage/windows/WinChildProcessTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,6 +40,7 @@
import java.nio.file.Path;

import jdk.jpackage.test.JPackageCommand;
import static jdk.jpackage.test.HelloApp.configureEnvironment;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.Executor;
import jdk.jpackage.test.TKit;
Expand All @@ -54,14 +55,15 @@ public static void test() {
long childPid = 0;
try {
JPackageCommand cmd = JPackageCommand
.helloAppImage(TEST_APP_JAVA + "*Hello");
.helloAppImage(TEST_APP_JAVA + "*Hello")
.ignoreFakeRuntime();

// Create the image of the third party application launcher
cmd.executeAndAssertImageCreated();

// Start the third party application launcher and dump and save the
// output of the application
List<String> output = new Executor().saveOutput().dumpOutput()
List<String> output = configureEnvironment(new Executor()).saveOutput().dumpOutput()
.setExecutable(cmd.appLauncherPath().toAbsolutePath())
.execute(0).getOutput();
String pidStr = output.get(0);
Expand Down