Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven Wrapper mvnw and mvnw.cmd built-in support #246

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@
</distributionManagement>

<properties>
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.custom.encoding>UTF-8</project.custom.encoding>
<project.custom.java.version>1.7</project.custom.java.version>
<maven.compiler.source>${project.custom.java.version}</maven.compiler.source>
<maven.compiler.target>${project.custom.java.version}</maven.compiler.target>
<project.build.outputEncoding>${project.custom.encoding}</project.build.outputEncoding>
<project.build.sourceEncoding>${project.custom.encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.custom.encoding}</project.reporting.outputEncoding>
<maven-plugin-plugin.version>3.6.0</maven-plugin-plugin.version>
</properties>

Expand Down Expand Up @@ -100,11 +105,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -203,9 +205,48 @@ 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")
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
&& "org.apache.maven.wrapper.MavenWrapperMain".equals(p.getValue()));
}
// TechDebt Java 1.8+ version
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
// 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()
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
.entrySet()) {
mavenHomeIsWrapperDists |= ("maven.home".equals(p.getKey())
&& String.valueOf(p.getValue()).contains("/wrapper/dists/"));
}
// TechDebt Java 1.8+ version
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
// 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()
aleksandr-m marked this conversation as resolved.
Show resolved Hide resolved
&& runningWithinMavenWrapper) {
mvnExecutable = "./mvnw";
} else if (SystemUtils.IS_OS_WINDOWS
&& new File(".", "mvnw.cmd").isFile()
&& runningWithinMavenWrapper) {
mvnExecutable = "mvnw.cmd";
} else {
mvnExecutable = "mvn";
}
}
cmdMvn.setExecutable(mvnExecutable);
}
Expand Down