Use the Maven 3.3.1 startup scripts to account for jvm.config and maven.config

This commit is contained in:
Jason van Zyl 2015-03-29 21:47:18 -04:00 committed by rfscholte
parent 7bd43645a0
commit 5d40b536e3
4 changed files with 141 additions and 90 deletions

Binary file not shown.

82
maven-wrapper/mvnw vendored
View File

@ -30,7 +30,7 @@
# M2_HOME - location of maven2's installed home dir # M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven # MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use # 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 # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@ -54,11 +54,36 @@ case "`uname`" in
CYGWIN*) cygwin=true ;; CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;; MINGW*) mingw=true;;
Darwin*) darwin=true Darwin*) darwin=true
if [ -z "$JAVA_VERSION" ] ; then #
JAVA_VERSION="CurrentJDK" # 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 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 fi
;; ;;
esac esac
@ -116,11 +141,16 @@ fi
if [ -z "$JAVA_HOME" ]; then if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`" 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(1) is not available as standard on Solaris 10.
readLink=`which readlink` readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`" javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`" javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'` javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome" JAVA_HOME="$javaHome"
@ -143,8 +173,8 @@ if [ -z "$JAVACMD" ] ; then
fi fi
if [ ! -x "$JAVACMD" ] ; then if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" echo " We cannot execute $JAVACMD" >&2
exit 1 exit 1
fi fi
@ -152,7 +182,7 @@ 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
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 # For Cygwin, switch paths to Windows format before running java
if $cygwin; then if $cygwin; then
@ -164,7 +194,41 @@ if $cygwin; then
CLASSPATH=`cygpath --path --windows "$CLASSPATH"` CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
fi 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" \ exec "$JAVACMD" \
$MAVEN_OPTS \ $MAVEN_OPTS \
-classpath "./.mvn/wrapper/maven-wrapper.jar" \ -classpath "./.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} "$@" ${WRAPPER_LAUNCHER} "$@"

View File

@ -29,7 +29,7 @@
@REM MAVEN_BATCH_PAUSE - 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 - parameters passed to the Java VM when running Maven @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use @REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @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 MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ---------------------------------------------------------------------------- @REM ----------------------------------------------------------------------------
@ -43,22 +43,25 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one @REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre :skipRcPre
@setlocal
set ERROR_CODE=0 set ERROR_CODE=0
@REM set local scope for the variables with windows NT shell @REM To isolate internal variables from possible post scripts, we use another setlocal
if "%OS%"=="Windows_NT" @setlocal @setlocal
if "%OS%"=="WINNT" @setlocal
@REM ==== START VALIDATION ==== @REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome if not "%JAVA_HOME%" == "" goto OkJHome
echo. echo.
echo ERROR: JAVA_HOME not found in your environment. echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation echo location of your Java installation. >&2
echo. echo.
goto error goto error
@ -66,124 +69,109 @@ goto error
if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome if exist "%JAVA_HOME%\bin\java.exe" goto chkMHome
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory. echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation echo location of your Java installation. >&2
echo. echo.
goto error goto error
:chkMHome :chkMHome
if not "%M2_HOME%"=="" goto valMHome if not "%M2_HOME%"=="" goto valMHome
if "%OS%"=="Windows_NT" SET "M2_HOME=%~dp0.." SET "M2_HOME=%~dp0.."
if "%OS%"=="WINNT" SET "M2_HOME=%~dp0.."
if not "%M2_HOME%"=="" goto valMHome if not "%M2_HOME%"=="" goto valMHome
echo. echo.
echo ERROR: M2_HOME not found in your environment. echo Error: M2_HOME not found in your environment. >&2
echo Please set the M2_HOME variable in your environment to match the echo Please set the M2_HOME variable in your environment to match the >&2
echo location of the Maven installation echo location of the Maven installation. >&2
echo. echo.
goto error goto error
:valMHome :valMHome
:stripMHome :stripMHome
if not "_%M2_HOME:~-1%"=="_\" goto checkMBat if not "_%M2_HOME:~-1%"=="_\" goto checkMCmd
set "M2_HOME=%M2_HOME:~0,-1%" set "M2_HOME=%M2_HOME:~0,-1%"
goto stripMHome goto stripMHome
:checkMBat :checkMCmd
if exist "%M2_HOME%\bin\mvn.bat" goto init if exist "%M2_HOME%\bin\mvn.cmd" goto init
echo. echo.
echo ERROR: M2_HOME is set to an invalid directory. echo Error: M2_HOME is set to an invalid directory. >&2
echo M2_HOME = "%M2_HOME%" echo M2_HOME = "%M2_HOME%" >&2
echo Please set the M2_HOME variable in your environment to match the echo Please set the M2_HOME variable in your environment to match the >&2
echo location of the Maven installation echo location of the Maven installation >&2
echo. echo.
goto error goto error
@REM ==== END VALIDATION ==== @REM ==== END VALIDATION ====
:init :init
@REM Decide how to startup depending on the version of windows
@REM -- Windows NT with Novell Login
if "%OS%"=="WINNT" goto WinNTNovell
@REM -- Win98ME
if NOT "%OS%"=="Windows_NT" goto Win9xArg
:WinNTNovell
@REM -- 4NT shell
if "%@eval[2+2]" == "4" goto 4NTArgs
@REM -- Regular WinNT shell
set MAVEN_CMD_LINE_ARGS=%* set MAVEN_CMD_LINE_ARGS=%*
goto endInit
@REM The 4NT Shell from jp software @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
:4NTArgs @REM Fallback to current working directory if not found.
set MAVEN_CMD_LINE_ARGS=%$
goto endInit
:Win9xArg set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
@REM Slurp the command line arguments. This loop allows for an unlimited number IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
@REM of agruments (up to the command line limit, anyway).
set MAVEN_CMD_LINE_ARGS= set EXEC_DIR=%CD%
:Win9xApp set WDIR=%EXEC_DIR%
if %1a==a goto endInit :findBaseDir
set MAVEN_CMD_LINE_ARGS=%MAVEN_CMD_LINE_ARGS% %1 IF EXIST "%WDIR%"\.mvn goto baseDirFound
shift cd ..
goto Win9xApp IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@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
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
@REM Reaching here means variables are defined and arguments have been captured
:endInit
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
@REM -- Regular WinNT shell for %%i in ("%M2_HOME%"\boot\plexus-classworlds-*) do set CLASSWORLDS_JAR="%%i"
set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
goto runm2
@REM Start MAVEN2 set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar""
:runm2
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
%MAVEN_JAVA_EXE% %MAVEN_OPTS% -classpath %WRAPPER_JAR% %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.home=%M2_HOME%" "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error if ERRORLEVEL 1 goto error
goto end goto end
:error :error
if "%OS%"=="Windows_NT" @endlocal
if "%OS%"=="WINNT" @endlocal
set ERROR_CODE=1 set ERROR_CODE=1
:end :end
@REM set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" goto endNT
if "%OS%"=="WINNT" goto endNT
@REM For old DOS remove the set variables from ENV - we assume they were not set
@REM before we started - at least we don't leave any baggage around
set MAVEN_JAVA_EXE=
set MAVEN_CMD_LINE_ARGS=
goto postExec
:endNT
@endlocal & set ERROR_CODE=%ERROR_CODE% @endlocal & set ERROR_CODE=%ERROR_CODE%
:postExec
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost :skipRcPost
@REM pause the batch file if MAVEN_BATCH_PAUSE is set to 'on' @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE% exit /B %ERROR_CODE%

View File

@ -32,7 +32,6 @@ public class BootstrapMainStarter {
Thread.currentThread().setContextClassLoader(contextClassLoader); Thread.currentThread().setContextClassLoader(contextClassLoader);
Class<?> mainClass = contextClassLoader.loadClass("org.codehaus.plexus.classworlds.launcher.Launcher"); Class<?> mainClass = contextClassLoader.loadClass("org.codehaus.plexus.classworlds.launcher.Launcher");
System.setProperty("maven.multiModuleProjectDirectory", System.getProperty("user.dir"));
System.setProperty("maven.home", mavenHome.getAbsolutePath()); System.setProperty("maven.home", mavenHome.getAbsolutePath());
System.setProperty("classworlds.conf", new File(mavenHome, "/bin/m2.conf").getAbsolutePath()); System.setProperty("classworlds.conf", new File(mavenHome, "/bin/m2.conf").getAbsolutePath());