Skip to content

Commit

Permalink
Maven Wrapper detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nhojpatrick committed Sep 9, 2021
1 parent 9c3aa6e commit 8f0e783
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,44 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
*
*/
private void initExecutables() {

boolean mainClassIsMavenWrapper = false;
for (final Map.Entry<Object, Object> 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<Object, Object> 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";
Expand Down

0 comments on commit 8f0e783

Please sign in to comment.