From 8f0e783990d2c3caea74893ecec43508b4cca847 Mon Sep 17 00:00:00 2001 From: John Patrick <142304+nhojpatrick@users.noreply.github.com> Date: Sun, 17 Jan 2021 19:20:51 +0000 Subject: [PATCH] Maven Wrapper detection --- .../plugin/gitflow/AbstractGitFlowMojo.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java index 7bae026a..50977dcc 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -205,13 +205,44 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { * */ private void initExecutables() { + + boolean mainClassIsMavenWrapper = false; + for (final Map.Entry p : this.mavenSession.getSystemProperties() + .entrySet()) { + mainClassIsMavenWrapper |= (String.valueOf(p.getKey()).startsWith("env.JAVA_MAIN_CLASS") + && "org.apache.maven.wrapper.MavenWrapperMain".equals(p.getValue())); + } + // TechDebt Java 1.8+ version +// final boolean mainClassIsMavenWrapper = this.mavenSession.getSystemProperties().entrySet().stream() +// .filter(p -> String.valueOf(p.getKey()).startsWith("env.JAVA_MAIN_CLASS")) +// .filter(p -> "org.apache.maven.wrapper.MavenWrapperMain".equals(p.getValue())) +// .findAny() +// .isPresent(); + + boolean mavenHomeIsWrapperDists = false; + for (final Map.Entry p : this.mavenSession.getSystemProperties() + .entrySet()) { + mavenHomeIsWrapperDists |= ("maven.home".equals(p.getKey()) + && String.valueOf(p.getValue()).contains("/wrapper/dists/")); + } + // TechDebt Java 1.8+ version +// final boolean mavenHomeIsWrapperDists = this.mavenSession.getSystemProperties().entrySet().stream() +// .filter(p -> "maven.home".equals(p.getKey())) +// .filter(p -> String.valueOf(p.getValue()).contains("/wrapper/dists/")) +// .findAny() +// .isPresent(); + + final boolean runningWithinMavenWrapper = mainClassIsMavenWrapper && mavenHomeIsWrapperDists; + if (StringUtils.isBlank(cmdMvn.getExecutable())) { if (StringUtils.isBlank(mvnExecutable)) { if (SystemUtils.IS_OS_UNIX - && new File(".", "mvnw").isFile()) { + && new File(".", "mvnw").isFile() + && runningWithinMavenWrapper) { mvnExecutable = "./mvnw"; } else if (SystemUtils.IS_OS_WINDOWS - && new File(".", "mvnw.cmd").isFile()) { + && new File(".", "mvnw.cmd").isFile() + && runningWithinMavenWrapper) { mvnExecutable = "mvnw.cmd"; } else { mvnExecutable = "mvn";