From 3fdea4ad8db805570ca90accba03b9997407ecf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Mon, 23 Sep 2024 11:47:32 +0200 Subject: [PATCH] Use Maven wrapper Use it when it is available and a tool path is not specifically configured. --- .../BuildToolCommandLineScenarioDefinition.java | 10 ++++++++-- .../gradle/profiler/bazel/BazelScenarioInvoker.java | 2 +- .../profiler/maven/MavenScenarioDefinition.java | 13 +++++++++++++ .../gradle/profiler/maven/MavenScenarioInvoker.java | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gradle/profiler/BuildToolCommandLineScenarioDefinition.java b/src/main/java/org/gradle/profiler/BuildToolCommandLineScenarioDefinition.java index 07cf74fa..a77fd86c 100644 --- a/src/main/java/org/gradle/profiler/BuildToolCommandLineScenarioDefinition.java +++ b/src/main/java/org/gradle/profiler/BuildToolCommandLineScenarioDefinition.java @@ -1,6 +1,7 @@ package org.gradle.profiler; import javax.annotation.Nullable; +import javax.annotation.OverridingMethodsMustInvokeSuper; import java.io.File; import java.io.PrintStream; import java.util.List; @@ -33,9 +34,14 @@ protected void printDetail(PrintStream out) { out.println(" Targets: " + getTargets()); } - public String getExecutablePath() { + public String getExecutablePath(File projectDir) { String toolHomePath = getToolHome() == null ? System.getenv(getToolHomeEnvName()) : getToolHome().getAbsolutePath(); - return toolHomePath == null ? getExecutableName() : toolHomePath + "/bin/" + getExecutableName(); + return toolHomePath == null ? getExecutablePathWithoutToolHome(projectDir) : toolHomePath + "/bin/" + getExecutableName(); + } + + @OverridingMethodsMustInvokeSuper + protected String getExecutablePathWithoutToolHome(File projectDir) { + return getExecutableName(); } @Override diff --git a/src/main/java/org/gradle/profiler/bazel/BazelScenarioInvoker.java b/src/main/java/org/gradle/profiler/bazel/BazelScenarioInvoker.java index ee50848e..bb959eb4 100644 --- a/src/main/java/org/gradle/profiler/bazel/BazelScenarioInvoker.java +++ b/src/main/java/org/gradle/profiler/bazel/BazelScenarioInvoker.java @@ -14,7 +14,7 @@ public void run(BazelScenarioDefinition scenario, InvocationSettings settings, C List targets = scenario.getTargets(); List commandLine = new ArrayList<>(); - commandLine.add(scenario.getExecutablePath()); + commandLine.add(scenario.getExecutablePath(settings.getProjectDir())); commandLine.addAll(targets); doRun(scenario, settings, resultConsumer, commandLine); diff --git a/src/main/java/org/gradle/profiler/maven/MavenScenarioDefinition.java b/src/main/java/org/gradle/profiler/maven/MavenScenarioDefinition.java index 1619e6f5..f266cc15 100644 --- a/src/main/java/org/gradle/profiler/maven/MavenScenarioDefinition.java +++ b/src/main/java/org/gradle/profiler/maven/MavenScenarioDefinition.java @@ -58,6 +58,19 @@ protected String getExecutableName() { } } + @Override + protected String getExecutablePathWithoutToolHome(File projectDir) { + String wrapperName = OperatingSystem.isWindows() + ? "mvnw.cmd" + : "mvnw"; + File wrapper = new File(projectDir, wrapperName); + if (wrapper.isFile()) { + return wrapper.getAbsolutePath(); + } else { + return super.getExecutablePathWithoutToolHome(projectDir); + } + } + @Override protected String getToolHomeEnvName() { return "MAVEN_HOME"; diff --git a/src/main/java/org/gradle/profiler/maven/MavenScenarioInvoker.java b/src/main/java/org/gradle/profiler/maven/MavenScenarioInvoker.java index e0e92133..32c17817 100644 --- a/src/main/java/org/gradle/profiler/maven/MavenScenarioInvoker.java +++ b/src/main/java/org/gradle/profiler/maven/MavenScenarioInvoker.java @@ -15,7 +15,7 @@ public class MavenScenarioInvoker extends BuildToolCommandLineInvoker resultConsumer) { List commandLine = new ArrayList<>(); - commandLine.add(scenario.getExecutablePath()); + commandLine.add(scenario.getExecutablePath(settings.getProjectDir())); commandLine.addAll(scenario.getTargets()); scenario.getSystemProperties().forEach((key, value) -> commandLine.add(String.format("-D%s=%s", key, value)));