Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
Open
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
16 changes: 15 additions & 1 deletion maven-wrapper-distribution/src/assembly/maven/run
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if $cygwin || $mingw ; then
MAVEN_PROJECTBASEDIR=`cygpath --windows "$MAVEN_PROJECTBASEDIR"`
fi

exec "$JAVACMD" \
"$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$LAUNCHER_JAR" \
Expand All @@ -17,3 +17,17 @@ exec "$JAVACMD" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
"-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR" \
$LAUNCHER_CLASS "$@"

# read distributionUrl from $MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties
while IFS="=" read key value; do
case "$key" in (distributionUrl) distributionUrl="$value"; break ;;
esac
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"

# local distribution dir is distributionUrl basename without extension
distribution=`basename $distributionUrl .zip`

mvn=~/.m2/wrapper/dists/$distribution/*/bin/mvn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here the glob wildcard * will expand to multiple files or select a wrong version or not expand at all in some posix shell. To invoke the main entrance script, u has to print the full path of the distribution or at least the hash of url.

The cons of this method is that java would be run twice. While the original way is the java way of exec invoking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove *, in Unix shell, I suppose we can derive directory name from with basename $distribution -bin
I'm not too much worried in POSIX shell: equivalent implementation in Windows cmd is harder to me

on running java twice, I suppose the script can check if the distribution is already installed to not run the installation java -jar maven-wrapper.jar if not really necessary

echo "mvnw will call $mvn"

exec $mvn "$@"
12 changes: 12 additions & 0 deletions maven-wrapper-distribution/src/assembly/maven/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%LAUNCHER_CLASS% %*
if ERRORLEVEL 1 goto error

@REM read distributionUrl from $MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="distributionUrl" SET DISTRIBUTION_URL=%%B
)

for /F %i in (%DISTRIBUTION_URL%) do SET DISTRIBUTION=%~ni

SET MVN=%USERPROFILE%\.m2\wrapper\dists\%DISTRIBUTION%/*/bin/mvn.cmd

%MVN% %*

goto end

:error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private void replaceProperties( Path targetFolder ) throws IOException
try ( BufferedWriter out = Files.newBufferedWriter( wrapperPropertiesFile ) )
{
out.append( license );
out.append( "distributionUrl=" + distributionUrl );
out.append( "distributionUrl=" + distributionUrl + "\n" );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Maven starter, from a provided Maven home directory.
*
* @author Hans Dockter
* @deprecated will be removed once launching Maven is not done here but in mvnw script by calling mvn
*/
public class BootstrapMainStarter
{
Expand All @@ -47,7 +48,8 @@ public void start( String[] args, Path mavenHome )
System.setProperty( "classworlds.conf", mavenHome.resolve( "bin/m2.conf" ).toAbsolutePath().toString() );

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

private Path findLauncherJar( Path mavenHome ) throws RuntimeException, IOException
Expand Down