Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
WIP Refactoring and cleanup
Browse files Browse the repository at this point in the history
- Avoid relying the standard output as much as possible, use JDK
  logging.
- Reformat the code to reflect standards
- Refactor download checksum integration
- Use NIO for maven archive downloads
  • Loading branch information
yveszoundi committed Jun 5, 2016
1 parent 83a99f2 commit 5b5af23
Show file tree
Hide file tree
Showing 35 changed files with 2,648 additions and 2,744 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: java
install: ./mvnw clean
jdk:
- openjdk6
script: ./mvnw test
notifications:
email: false
Expand Down
32 changes: 19 additions & 13 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@
[[https://travis-ci.org/rimerosolutions/maven-wrapper/][file:https://travis-ci.org/rimerosolutions/maven-wrapper.png]]
[[http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22wrapper-maven-plugin%22][file:https://img.shields.io/maven-central/v/com.rimerosolutions.maven.plugins/wrapper-maven-plugin.svg]]

* Introduction
This is a copy of the [[http://www.gradle.org/docs/current/userguide/gradle_wrapper.html][Gradle wrapper]] ported for use with [[http://maven.apache.org][Apache Maven]].
=maven-wrapper= is now available from [[http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.rimerosolutions.maven.plugins%22][Maven Central]].
* Overview
This is a copy of the [[http://www.gradle.org/docs/current/userguide/gradle_wrapper.html][Gradle wrapper]] ported for use with [[http://maven.apache.org][Apache Maven]]. =maven-wrapper= is available from [[http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.rimerosolutions.maven.plugins%22][Maven Central]].

The Maven Command Line Wrapper will auto-download and install Apache Maven from the Internet and then run your Maven goals.
=maven-wrapper= ships as Maven plugin that generates wrapper scripts and a configuration file to bootstrap Maven download and installation.

This is a fork of [[https://github.com/bdemers/maven-wrapper][bdemers' maven-wrapper]] in order to provide the Maven Wrapper as a Maven plugin, for more flexible reuse/integration. Once you have a Maven project that you want to distribute, you can generate a wrapper so that
** Rationale
This is a fork of [[https://github.com/bdemers/maven-wrapper][bdemers' maven-wrapper]] in order to provide the Maven Wrapper as a Maven plugin, for more flexible reuse/integration. Once you have a Maven project that you want to distribute, you can generate a wrapper so that:

- The target audience can easily execute Maven goals without an existing Maven application as a pre-requisite.
- You can control the version of Maven that is to be used to build the project in case there are Maven versions compatibility concerns.
- You can control the version of Maven that is to be used to build the project, if are versions compatibility concerns.

For example if used to run
** Integration example

For a full and small practical integration example, checkout the [[https://github.com/rimerosolutions/maven-wrapper-example][Maven Command Line Wrapper Example]] project.

If you used to run

: mvn clean install

Then you would now run (without a leading =./= for MS Windows)
: ./mvnw clean install

A wrapper created with Maven 3.0.4 will request Maven 3.0.4 if it's not already installed on the user's machine.
However, you can still request a specific Maven version by overriding the default behaviour.
A wrapper created with Maven 3.0.4 will request Maven 3.0.4, if it's not already installed on the user's machine.
However, you can still request a specific Maven version by overriding the default behaviour (Maven plugin configuration).

Notes: You need a valid JDK at least 1.6. The plugin was tested with Maven 3.0.2 and above.

For a small practical integration example, checkout the [[https://github.com/rimerosolutions/maven-wrapper-example][Maven Command Line Wrapper Example]] project.

* Maven Goals and Usage

For the list of goals and a usage guide, please consult the [[https://github.com/rimerosolutions/maven-wrapper/wiki][Wiki]].

* Generating the Maven wrapper
After integrating the wrapper in another Maven project, run the following command to generate the wrapper.
After integrating the wrapper into your Maven project (plugin section), run the following command to generate the wrapper.

: mvn wrapper:wrapper

Expand All @@ -45,5 +47,9 @@ The =maven= folder is generated with the relevant jar and properties file in the
You can now start using either the =mvnw= or =mvnw.bat= commands on any project without an existing maven installation!

* Articles

[[http://jakub.marchwicki.pl/posts/2015/06/04/maven-wrapper/]]

* Contributing
Pull requests, issues creation, suggestions, documentation improvements are welcome.

Big thank you to all of you who contributed to this project so far.
Binary file modified maven/maven-wrapper.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions maven/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Maven download properties
#Sat Jul 06 06:28:19 EDT 2013
distributionUrl=https\://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.0.3/apache-maven-3.0.3-bin.zip
#Sun Jun 05 16:36:09 EDT 2016
checksumAlgorithm=MD5
verifyDownload=true
distributionUrl=https\://repository.apache.org/content/repositories/releases/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
126 changes: 111 additions & 15 deletions mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------

Expand All @@ -52,12 +53,37 @@ mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
if [ -z "$JAVA_VERSION" ] ; then
JAVA_VERSION="CurrentJDK"
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home

if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi

if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi

if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
Expand All @@ -68,8 +94,36 @@ if [ -z "$JAVA_HOME" ] ; then
fi
fi

if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"

# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done

saveddir=`pwd`

M2_HOME=`dirname "$PRG"`/..

# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`

cd "$saveddir"
# echo Using m2 at $M2_HOME
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
Expand All @@ -78,18 +132,25 @@ fi

# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi

if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" -a ! "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
javaExecutable="`readlink -f \"$javaExecutable\"`"
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
Expand All @@ -112,27 +173,62 @@ if [ -z "$JAVACMD" ] ; then
fi

if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
echo " We cannot execute $JAVACMD"
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi

if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi

WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi

# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
wdir=$(cd "$wdir/.."; pwd)
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
done
echo "${basedir}"
}

# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}

export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"

# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS

WRAPPER_LAUNCHER="org.apache.maven.wrapper.MavenWrapperMain"

exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "\
./maven/maven-wrapper.jar" \
$MAVEN_OPTS \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
-classpath \
"$MAVEN_PROJECTBASEDIR/maven/maven-wrapper.jar" \
${WRAPPER_LAUNCHER} "$@"
Loading

0 comments on commit 5b5af23

Please sign in to comment.