diff --git a/pom.xml b/pom.xml index f65fb2f3..59271fc8 100644 --- a/pom.xml +++ b/pom.xml @@ -63,8 +63,13 @@ - 1.7 - UTF-8 + UTF-8 + 1.7 + ${project.custom.java.version} + ${project.custom.java.version} + ${project.custom.encoding} + ${project.custom.encoding} + ${project.custom.encoding} 3.6.0 @@ -100,11 +105,6 @@ org.apache.maven.plugins maven-compiler-plugin 3.8.1 - - ${java.version} - ${java.version} - ${project.build.sourceEncoding} - org.apache.maven.plugins 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 c668086a..50977dcc 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -15,6 +15,7 @@ */ package com.amashchenko.maven.plugin.gitflow; +import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -25,6 +26,7 @@ import java.util.TimeZone; import java.util.regex.Pattern; +import org.apache.commons.lang3.SystemUtils; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; @@ -203,9 +205,48 @@ 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)) { - mvnExecutable = "mvn"; + if (SystemUtils.IS_OS_UNIX + && new File(".", "mvnw").isFile() + && runningWithinMavenWrapper) { + mvnExecutable = "./mvnw"; + } else if (SystemUtils.IS_OS_WINDOWS + && new File(".", "mvnw.cmd").isFile() + && runningWithinMavenWrapper) { + mvnExecutable = "mvnw.cmd"; + } else { + mvnExecutable = "mvn"; + } } cmdMvn.setExecutable(mvnExecutable); }