Skip to content

Commit

Permalink
Choose right executable on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 28, 2024
1 parent 4ca5bfd commit 7a4ee8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ dependencies {
implementation(libs.groovy4) {
because("it provides convenience methods to handle process output")
}
implementation(libs.opentest4j) {
because("it throws TestAbortedException to abort tests")
implementation(projects.junitJupiterApi) {
because("it throws TestAbortedException to abort tests and uses the OS enum")
}

testImplementation(libs.archunit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.nio.file.Path;
import java.util.Optional;

import org.junit.jupiter.api.condition.OS;
import org.opentest4j.TestAbortedException;

import platform.tooling.support.Helper;
Expand Down Expand Up @@ -45,17 +46,22 @@ public static ProcessStarter javaCommand(Path javaHome, String commandName) {

public static ProcessStarter gradlew() {
var starter = new ProcessStarter() //
.executable(Path.of("..").resolve("gradlew")) //
.executable(Path.of("..").resolve(windowsOrOtherExecutable("gradlew.bat", "gradlew"))) //
.putEnvironment("JAVA_HOME", getGradleJavaHome().orElseThrow(TestAbortedException::new));
return withCommonEnvironmentVariables(starter);
}

public static ProcessStarter maven() {
var starter = new ProcessStarter() //
.executable(Path.of(System.getProperty("mavenDistribution")).resolve("bin/mvn"));
.executable(Path.of(System.getProperty("mavenDistribution")).resolve("bin").resolve(
windowsOrOtherExecutable("mvn.cmd", "mvn")));
return withCommonEnvironmentVariables(starter);
}

private static String windowsOrOtherExecutable(String cmdOrExe, String other) {
return OS.current() == OS.WINDOWS ? cmdOrExe : other;
}

private static ProcessStarter withCommonEnvironmentVariables(ProcessStarter starter) {
starter.putEnvironment("JUNIT_JUPITER_VERSION", Helper.version("junit-jupiter"));
starter.putEnvironment("JUNIT_VINTAGE_VERSION", Helper.version("junit-vintage"));
Expand Down

0 comments on commit 7a4ee8e

Please sign in to comment.