Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit 58048e2

Browse files
committed
[MWRAPPER-16] PoC call mvn(.cmd) script from mvnw(.cmd)
1 parent be6308f commit 58048e2

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

maven-wrapper-distribution/src/assembly/maven/run

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if $cygwin || $mingw ; then
88
MAVEN_PROJECTBASEDIR=`cygpath --windows "$MAVEN_PROJECTBASEDIR"`
99
fi
1010

11-
exec "$JAVACMD" \
11+
"$JAVACMD" \
1212
$MAVEN_OPTS \
1313
$MAVEN_DEBUG_OPTS \
1414
-classpath "$LAUNCHER_JAR" \
@@ -17,3 +17,17 @@ exec "$JAVACMD" \
1717
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
1818
"-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR" \
1919
$LAUNCHER_CLASS "$@"
20+
21+
# read distributionUrl from $MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties
22+
while IFS="=" read key value; do
23+
case "$key" in (distributionUrl) distributionUrl="$value"; break ;;
24+
esac
25+
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
26+
27+
# local distribution dir is distributionUrl basename without extension
28+
distribution=`basename $distributionUrl .zip`
29+
30+
mvn=~/.m2/wrapper/dists/$distribution/*/bin/mvn
31+
echo "mvnw will call $mvn"
32+
33+
exec $mvn "$@"

maven-wrapper-distribution/src/assembly/maven/run.cmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
1010
%LAUNCHER_CLASS% %*
1111
if ERRORLEVEL 1 goto error
12+
13+
@REM read distributionUrl from $MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties
14+
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
15+
IF "%%A"=="distributionUrl" SET DISTRIBUTION_URL=%%B
16+
)
17+
18+
for /F %i in (%DISTRIBUTION_URL%) do SET DISTRIBUTION=%~ni
19+
20+
SET MVN=%USERPROFILE%\.m2\wrapper\dists\%DISTRIBUTION%/*/bin/mvn.cmd
21+
22+
%MVN% %*
23+
1224
goto end
1325

1426
:error

maven-wrapper-plugin/src/main/java/org/apache/maven/plugins/wrapper/WrapperMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private void replaceProperties( Path targetFolder ) throws IOException
218218
try ( BufferedWriter out = Files.newBufferedWriter( wrapperPropertiesFile ) )
219219
{
220220
out.append( license );
221-
out.append( "distributionUrl=" + distributionUrl );
221+
out.append( "distributionUrl=" + distributionUrl + "\n" );
222222
}
223223
}
224224

maven-wrapper/src/main/java/org/apache/maven/wrapper/BootstrapMainStarter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* Maven starter, from a provided Maven home directory.
3232
*
3333
* @author Hans Dockter
34+
* @deprecated will be removed once launching Maven is not done here but in mvnw script by calling mvn
3435
*/
3536
public class BootstrapMainStarter
3637
{
@@ -47,7 +48,8 @@ public void start( String[] args, Path mavenHome )
4748
System.setProperty( "classworlds.conf", mavenHome.resolve( "bin/m2.conf" ).toAbsolutePath().toString() );
4849

4950
Method mainMethod = mainClass.getMethod( "main", String[].class );
50-
mainMethod.invoke( null, new Object[] { args } );
51+
//mainMethod.invoke( null, new Object[] { args } );
52+
System.out.println( "Now, mvnw script should call " + mavenHome.toAbsolutePath().toString() + "/bin/mvn" );
5153
}
5254

5355
private Path findLauncherJar( Path mavenHome ) throws RuntimeException, IOException

0 commit comments

Comments
 (0)