[MNG-5607] Don't use M2_HOME in mvn shell/command scripts anymore

* Variable has been removed and replaced with an internal one which
  cannot be overriden from outside. From now on, it is an
  implementation detail which it should have been from the beginning.
* Cleaned up license header and style of the variable description
  section graciously borrowed from the Tomcat start scripts.
This commit is contained in:
Michael Osipov 2016-04-14 22:41:07 +02:00
parent 4337d18af6
commit 065281c43d
6 changed files with 90 additions and 134 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file # or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information # distributed with this work for additional information
@ -16,23 +16,16 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
# ----------------------------------------------------------------------------
# ---------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Maven2 Start Up Batch script # Apache Maven Startup Script
# #
# Required ENV vars: # Environment Variable Prerequisites
# ------------------
# JAVA_HOME - location of a JDK home dir
# #
# Optional ENV vars # JAVA_HOME Must point at your Java Development Kit installation.
# ----------------- # MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# M2_HOME - location of maven2's installed home dir # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# MAVEN_OPTS - parameters passed to the Java VM when running Maven # -----------------------------------------------------------------------------
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then if [ -z "$MAVEN_SKIP_RC" ] ; then
@ -49,9 +42,9 @@ fi
# OS specific support. $var _must_ be set to either true or false. # OS specific support. $var _must_ be set to either true or false.
cygwin=false; cygwin=false;
darwin=false; darwin=false;
mingw=false mingw=false;
case "`uname`" in case "`uname`" in
CYGWIN*) cygwin=true ;; CYGWIN*) cygwin=true;;
MINGW*) mingw=true;; MINGW*) mingw=true;;
Darwin*) darwin=true Darwin*) darwin=true
# #
@ -94,12 +87,11 @@ if [ -z "$JAVA_HOME" ] ; then
fi fi
fi fi
if [ -z "$M2_HOME" ] ; then ## resolve links - $0 may be a link to Maven's home
## resolve links - $0 may be a link to maven's home PRG="$0"
PRG="$0"
# need this for relative symlinks # need this for relative symlinks
while [ -h "$PRG" ] ; do while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"` ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'` link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then if expr "$link" : '/.*' > /dev/null; then
@ -107,33 +99,31 @@ if [ -z "$M2_HOME" ] ; then
else else
PRG="`dirname "$PRG"`/$link" PRG="`dirname "$PRG"`/$link"
fi fi
done done
saveddir=`pwd` saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/.. MAVEN_HOME=`dirname "$PRG"`/..
# make it fully qualified # make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd` MAVEN_HOME=`cd "$MAVEN_HOME" && pwd`
cd "$saveddir" cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched # For Cygwin, ensure paths are in Unix format before anything is touched
if $cygwin ; then if $cygwin ; then
[ -n "$M2_HOME" ] && [ -n "$MAVEN_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"` MAVEN_HOME=`cygpath --unix "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"` JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && [ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"` CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi fi
# For Migwn, ensure paths are in UNIX format before anything is touched # For MinGW, ensure paths are in Unix format before anything is touched
if $mingw ; then if $mingw ; then
[ -n "$M2_HOME" ] && [ -n "$MAVEN_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`" MAVEN_HOME="`(cd "$MAVEN_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath? # TODO classpath?
@ -182,13 +172,13 @@ if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set." echo "Warning: JAVA_HOME environment variable is not set."
fi fi
CLASSWORLDS_JAR=`echo "${M2_HOME}"/boot/plexus-classworlds-*.jar` CLASSWORLDS_JAR=`echo "${MAVEN_HOME}"/boot/plexus-classworlds-*.jar`
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# For Cygwin, switch paths to Windows format before running java # For Cygwin, switch paths to Windows format before running java
if $cygwin; then if $cygwin ; then
[ -n "$M2_HOME" ] && [ -n "$MAVEN_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"` MAVEN_HOME=`cygpath --path --windows "$MAVEN_HOME"`
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] && [ -n "$CLASSPATH" ] &&
@ -225,8 +215,8 @@ MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-$(find_maven_basedir)}"
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch project base directory path to Windows format before # For Cygwin, switch project base directory path to Windows format before
# executing Maven. Otherwise this will cause Maven not to consider it. # executing Maven otherwise this will cause Maven not to consider it.
if $cygwin; then if $cygwin ; then
[ -n "$MAVEN_PROJECTBASEDIR" ] && [ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi fi
@ -242,7 +232,7 @@ exec "$JAVACMD" \
$MAVEN_OPTS \ $MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \ $MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \ -classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \ "-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ "-Dmaven.home=${MAVEN_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/ext" \ "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/ext" \
${CLASSWORLDS_LAUNCHER} "$@" ${CLASSWORLDS_LAUNCHER} "$@"

View File

@ -1,4 +1,3 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one @REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file @REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information @REM distributed with this work for additional information
@ -15,23 +14,18 @@
@REM KIND, either express or implied. See the License for the @REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations @REM specific language governing permissions and limitations
@REM under the License. @REM under the License.
@REM ----------------------------------------------------------------------------
@REM ---------------------------------------------------------------------------- @REM -----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script @REM Apache Maven Startup Script
@REM @REM
@REM Required ENV vars: @REM Environment Variable Prerequisites
@REM JAVA_HOME - location of a JDK home dir
@REM @REM
@REM Optional ENV vars @REM JAVA_HOME Must point at your Java Development Kit installation.
@REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending @REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
@REM e.g. to debug Maven itself, use @REM -----------------------------------------------------------------------------
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off @echo off
@ -77,34 +71,19 @@ echo.
goto error goto error
:chkMHome :chkMHome
if not "%M2_HOME%"=="" goto valMHome set "MAVEN_HOME=%~dp0.."
if not "%MAVEN_HOME%"=="" goto valMHome
SET "M2_HOME=%~dp0.."
if not "%M2_HOME%"=="" goto valMHome
echo.
echo Error: M2_HOME not found in your environment. >&2
echo Please set the M2_HOME variable in your environment to match the >&2
echo location of the Maven installation. >&2
echo.
goto error goto error
:valMHome :valMHome
:stripMHome :stripMHome
if not "_%M2_HOME:~-1%"=="_\" goto checkMCmd if not "_%MAVEN_HOME:~-1%"=="_\" goto checkMCmd
set "M2_HOME=%M2_HOME:~0,-1%" set "MAVEN_HOME=%MAVEN_HOME:~0,-1%"
goto stripMHome goto stripMHome
:checkMCmd :checkMCmd
if exist "%M2_HOME%\bin\mvn.cmd" goto init if exist "%MAVEN_HOME%\bin\mvn.cmd" goto init
echo.
echo Error: M2_HOME is set to an invalid directory. >&2
echo M2_HOME = "%M2_HOME%" >&2
echo Please set the M2_HOME variable in your environment to match the >&2
echo location of the Maven installation >&2
echo.
goto error goto error
@REM ==== END VALIDATION ==== @REM ==== END VALIDATION ====
@ -112,16 +91,16 @@ goto error
set MAVEN_CMD_LINE_ARGS=%* set MAVEN_CMD_LINE_ARGS=%*
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". @REM Find the project basedir, i.e., the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found. @REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir if not "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD% set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR% set WDIR=%EXEC_DIR%
:findBaseDir :findBaseDir
IF EXIST "%WDIR%\.mvn" goto baseDirFound if exist "%WDIR%\.mvn" goto baseDirFound
cd .. cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD% set WDIR=%CD%
@ -140,7 +119,7 @@ cd "%EXEC_DIR%"
:endDetectBaseDir :endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig if not exist "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion @setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@ -148,13 +127,13 @@ for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do s
:endReadAdditionalConfig :endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
for %%i in ("%M2_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i" for %%i in ("%MAVEN_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf" "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\ext" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS% %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %CLASSWORLDS_JAR% "-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" "-Dmaven.home=%MAVEN_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\ext" %CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error if ERRORLEVEL 1 goto error
goto end goto end

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file # or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information # distributed with this work for additional information
@ -16,26 +16,19 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
# ----------------------------------------------------------------------------
# ---------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Maven2 Start Up Batch script # Apache Maven Debug Script
# #
# Required ENV vars: # Environment Variable Prerequisites
# ------------------
# JAVA_HOME - location of a JDK home dir
# #
# Optional ENV vars # JAVA_HOME Must point at your Java Development Kit installation.
# ----------------- # MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# M2_HOME - location of maven2's installed home dir # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# MAVEN_OPTS - parameters passed to the Java VM when running Maven # -----------------------------------------------------------------------------
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
MAVEN_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" MAVEN_DEBUG_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
echo Preparing to Execute Maven in Debug Mode echo Preparing to execute Maven in debug mode
env MAVEN_OPTS="$MAVEN_OPTS" MAVEN_DEBUG_OPTS="$MAVEN_DEBUG_OPTS" $(dirname $0)/mvn "$@" env MAVEN_OPTS="$MAVEN_OPTS" MAVEN_DEBUG_OPTS="$MAVEN_DEBUG_OPTS" $(dirname $0)/mvn "$@"

View File

@ -1,4 +1,3 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one @REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file @REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information @REM distributed with this work for additional information
@ -15,15 +14,18 @@
@REM KIND, either express or implied. See the License for the @REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations @REM specific language governing permissions and limitations
@REM under the License. @REM under the License.
@REM ----------------------------------------------------------------------------
@REM ---------------------------------------------------------------------------- @REM -----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script to run mvn.cmd with the following additional @REM Apache Maven Debug Script
@REM Java VM settings:
@REM @REM
@REM -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @REM Environment Variable Prerequisites
@REM @REM
@REM ---------------------------------------------------------------------------- @REM JAVA_HOME Must point at your Java Development Kit installation.
@REM MAVEN_BATCH_ECHO (Optional) Set to 'on' to enable the echoing of the batch commands.
@REM MAVEN_BATCH_PAUSE (Optional) set to 'on' to wait for a key stroke before ending.
@REM MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
@REM MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
@REM -----------------------------------------------------------------------------
@setlocal @setlocal
@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file # or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information # distributed with this work for additional information
@ -16,23 +16,16 @@
# KIND, either express or implied. See the License for the # KIND, either express or implied. See the License for the
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
# ----------------------------------------------------------------------------
# ---------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Maven2 Start Up Batch script # Apache Maven YourKit Profiler Startup Script
# #
# Required ENV vars: # Environment Variable Prerequisites
# ------------------
# JAVA_HOME - location of a JDK home dir
# #
# Optional ENV vars # JAVA_HOME Must point at your Java Development Kit installation.
# ----------------- # MAVEN_OPTS (Optional) Java runtime options used when Maven is executed.
# M2_HOME - location of maven2's installed home dir # MAVEN_SKIP_RC (Optional) Flag to disable loading of mavenrc files.
# MAVEN_OPTS - parameters passed to the Java VM when running Maven # -----------------------------------------------------------------------------
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ ! -f "$YJPLIB" ]; then if [ ! -f "$YJPLIB" ]; then
echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2 echo "Error: Unable to autodetect the YJP library location. Please set YJPLIB variable" >&2

View File

@ -346,8 +346,7 @@ public class MavenCli
if ( basedirProperty == null ) if ( basedirProperty == null )
{ {
System.err.format( System.err.format(
"-D%s system property is not set." + " Check $M2_HOME environment variable and mvn script match.", "-D%s system property is not set.", MULTIMODULE_PROJECT_DIRECTORY );
MULTIMODULE_PROJECT_DIRECTORY );
throw new ExitException( 1 ); throw new ExitException( 1 );
} }
File basedir = basedirProperty != null ? new File( basedirProperty ) : new File( "" ); File basedir = basedirProperty != null ? new File( basedirProperty ) : new File( "" );