From f2decc7771cdb7a34fcfd150ec4354f9d0a9aa6f Mon Sep 17 00:00:00 2001 From: "robert.patrick" Date: Tue, 6 Sep 2016 17:35:07 -0500 Subject: [PATCH 1/2] MNG-5889 - adding logic that looks for the file argument and starts the search for the .mvn directory at the location of the specified POM when present --- apache-maven/src/bin/mvn | 24 ++++++++++++++++-- apache-maven/src/bin/mvn.cmd | 48 +++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn index 2a88df23eae2..30fd15db7f2f 100755 --- a/apache-maven/src/bin/mvn +++ b/apache-maven/src/bin/mvn @@ -121,7 +121,7 @@ fi # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { ( - basedir="`pwd`" + basedir=`find_file_argument_basedir "$@"` wdir="`pwd`" while [ "$wdir" != '/' ] ; do if [ -d "$wdir"/.mvn ] ; then @@ -134,6 +134,26 @@ find_maven_basedir() { ) } +find_file_argument_basedir() { +( + basedir="`pwd`" + + found_file_switch=0 + for arg in "$@"; do + if [ ${found_file_switch} -eq 1 ]; then + if [ -f ${arg} ]; then + basedir=$(dirname $(readlink -f "${arg}")) + fi + break + fi + if [ "$arg" == "-f" -o "$arg" == "--file" ]; then + found_file_switch=1 + fi + done + echo "${basedir}" +) +} + # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then @@ -141,7 +161,7 @@ concat_lines() { fi } -MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir`}" +MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir "$@"`}" MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"` $MAVEN_OPTS" # For Cygwin, switch project base directory path to Windows format before diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index c8ad237ef614..8f416d8cb453 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -84,12 +84,52 @@ set MAVEN_CMD_LINE_ARGS=%* @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -if not "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% + +@REM Look for the --file switch and start the search for the .mvn directory from the specified +@REM POM location, if supplied. + +set FILE_ARG= +:arg_loop +if "%1" == "-f" ( + set "FILE_ARG=%2" + shift + goto process_file_arg +) +if "%1" == "--file" ( + set "FILE_ARG=%2" + shift + goto process_file_arg +) +@REM If none of the above, skip the argument +shift +if not "%~1" == "" ( + goto arg_loop +) else ( + goto findBaseDir +) + +:process_file_arg +if "%FILE_ARG%" == "" ( + goto findBaseDir +) +call :get_directory_from_file %FILE_ARG% +if not exist "%POM_DIR%" ( + echo Directory %POM_DIR% extracted from the -f/--file command-line argument does not exist + goto error +) +set WDIR=%POM_DIR% +goto findBaseDir -set "EXEC_DIR=%CD%" -set "WDIR=%EXEC_DIR%" +:get_directory_from_file +set "POM_DIR=%~dp1" +exit /b :findBaseDir +cd /d %WDIR% if exist "%WDIR%\.mvn" goto baseDirFound cd .. if "%WDIR%"=="%CD%" goto baseDirNotFound @@ -98,7 +138,7 @@ goto findBaseDir :baseDirFound set "MAVEN_PROJECTBASEDIR=%WDIR%" -cd "%EXEC_DIR%" +cd /d "%EXEC_DIR%" goto endDetectBaseDir :baseDirNotFound From ef1fec23a2d600e5151212a00523e2abe27bacfb Mon Sep 17 00:00:00 2001 From: "robert.patrick" Date: Tue, 6 Sep 2016 18:25:47 -0500 Subject: [PATCH 2/2] fixing findBaseDir loop to not include the initial cd /d --- apache-maven/src/bin/mvn.cmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apache-maven/src/bin/mvn.cmd b/apache-maven/src/bin/mvn.cmd index 8f416d8cb453..d77960ad2a0d 100644 --- a/apache-maven/src/bin/mvn.cmd +++ b/apache-maven/src/bin/mvn.cmd @@ -84,7 +84,7 @@ set MAVEN_CMD_LINE_ARGS=%* @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir +if not "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir set EXEC_DIR=%CD% set WDIR=%EXEC_DIR% @@ -130,11 +130,12 @@ exit /b :findBaseDir cd /d %WDIR% +:findBaseDirLoop if exist "%WDIR%\.mvn" goto baseDirFound cd .. if "%WDIR%"=="%CD%" goto baseDirNotFound set "WDIR=%CD%" -goto findBaseDir +goto findBaseDirLoop :baseDirFound set "MAVEN_PROJECTBASEDIR=%WDIR%"