1919#  ----------------------------------------------------------------------------
2020
2121#  ----------------------------------------------------------------------------
22- #  Apache Maven Wrapper startup batch script, version 3.3.0 
22+ #  Apache Maven Wrapper startup batch script, version 3.3.4 
2323# 
2424#  Optional ENV vars
2525#  -----------------
@@ -97,14 +97,25 @@ die() {
9797  exit  1
9898}
9999
100+ trim () {
101+   #  MWRAPPER-139:
102+   #    Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
103+   #    Needed for removing poorly interpreted newline sequences when running in more
104+   #    exotic environments such as mingw bash on Windows.
105+   printf  " %s" " ${1} " |  tr -d ' [:space:]' 
106+ }
107+ 
108+ scriptDir=" $( dirname " $0 " ) " 
109+ scriptName=" $( basename " $0 " ) " 
110+ 
100111#  parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
101112while  IFS=" =" read  -r key value;  do 
102113  case  " ${key-} " in 
103-   distributionUrl) distributionUrl=" ${value-} " 
104-   distributionSha256Sum) distributionSha256Sum=" ${value-} " 
114+   distributionUrl) distributionUrl=$( trim  " ${value-} " ) 
115+   distributionSha256Sum) distributionSha256Sum=$( trim  " ${value-} " ) 
105116  esac 
106- done  < " ${0 %/* }  /.mvn/wrapper/maven-wrapper.properties" 
107- [ -n  " ${distributionUrl-} " ||  die " cannot read distributionUrl property in ${0 %/* }  /.mvn/wrapper/maven-wrapper.properties" 
117+ done  < " $scriptDir  /.mvn/wrapper/maven-wrapper.properties" 
118+ [ -n  " ${distributionUrl-} " ||  die " cannot read distributionUrl property in $scriptDir  /.mvn/wrapper/maven-wrapper.properties" 
108119
109120case  " ${distributionUrl##*/ } " in 
110121maven-mvnd-* bin.* )
@@ -122,7 +133,7 @@ maven-mvnd-*bin.*)
122133  distributionUrl=" ${distributionUrl% -bin.* } -$distributionPlatform .zip" 
123134  ;;
124135maven-mvnd-* ) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
125- * ) MVN_CMD=" mvn${0 ##*/ mvnw} " 
136+ * ) MVN_CMD=" mvn${scriptName # mvnw} " 
126137esac 
127138
128139#  apply MVNW_REPOURL and calculate MAVEN_HOME
131142distributionUrlName=" ${distributionUrl##*/ } " 
132143distributionUrlNameMain=" ${distributionUrlName% .* } " 
133144distributionUrlNameMain=" ${distributionUrlNameMain% -bin} " 
134- MAVEN_HOME=" $HOME /.m2/wrapper/dists/${distributionUrlNameMain-} /$( hash_string " $distributionUrl " ) " 
145+ MAVEN_USER_HOME=" ${MAVEN_USER_HOME:- ${HOME} / .m2} " 
146+ MAVEN_HOME=" ${MAVEN_USER_HOME} /wrapper/dists/${distributionUrlNameMain-} /$( hash_string " $distributionUrl " ) " 
135147
136148exec_maven () {
137149  unset  MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL ||  : 
@@ -199,7 +211,7 @@ elif set_java_home; then
199211	  public static void main( String[] args ) throws Exception 
200212	  { 
201213	    setDefault( new Downloader() ); 
202- 	    java.nio.file.Files.copy( new  java.net.URL ( args[0] ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 
214+ 	    java.nio.file.Files.copy( java.net.URI.create ( args[0] ).toURL( ).openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 
203215	  } 
204216	} 
205217	END  
@@ -218,7 +230,7 @@ if [ -n "${distributionSha256Sum-}" ]; then
218230    echo  " Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 
219231    exit  1
220232  elif  command  -v sha256sum > /dev/null;  then 
221-     if  echo  " $distributionSha256Sum   $TMP_DOWNLOAD_DIR /$distributionUrlName " |  sha256sum -c > /dev/null 2>&1 ;  then 
233+     if  echo  " $distributionSha256Sum   $TMP_DOWNLOAD_DIR /$distributionUrlName " |  sha256sum -c -  > /dev/null 2>&1 ;  then 
222234      distributionSha256Result=true
223235    fi 
224236  elif  command  -v shasum > /dev/null;  then 
@@ -243,8 +255,41 @@ if command -v unzip >/dev/null; then
243255else 
244256  tar xzf${__MVNW_QUIET_TAR: +" $__MVNW_QUIET_TAR "   " $TMP_DOWNLOAD_DIR /$distributionUrlName " " $TMP_DOWNLOAD_DIR " ||  die " failed to untar" 
245257fi 
246- printf  %s\\ n " $distributionUrl " > " $TMP_DOWNLOAD_DIR /$distributionUrlNameMain /mvnw.url" 
247- mv -- " $TMP_DOWNLOAD_DIR /$distributionUrlNameMain " " $MAVEN_HOME " ||  [ -d  " $MAVEN_HOME " ||  die " fail to move MAVEN_HOME" 
258+ 
259+ #  Find the actual extracted directory name (handles snapshots where filename != directory name)
260+ actualDistributionDir=" " 
261+ 
262+ #  First try the expected directory name (for regular distributions)
263+ if  [ -d  " $TMP_DOWNLOAD_DIR /$distributionUrlNameMain " ;  then 
264+   if  [ -f  " $TMP_DOWNLOAD_DIR /$distributionUrlNameMain /bin/$MVN_CMD " ;  then 
265+     actualDistributionDir=" $distributionUrlNameMain " 
266+   fi 
267+ fi 
268+ 
269+ #  If not found, search for any directory with the Maven executable (for snapshots)
270+ if  [ -z  " $actualDistributionDir " ;  then 
271+   #  enable globbing to iterate over items
272+   set  +f
273+   for  dir  in  " $TMP_DOWNLOAD_DIR " * ;  do 
274+     if  [ -d  " $dir " ;  then 
275+       if  [ -f  " $dir /bin/$MVN_CMD " ;  then 
276+         actualDistributionDir=" $( basename " $dir " ) " 
277+         break 
278+       fi 
279+     fi 
280+   done 
281+   set  -f
282+ fi 
283+ 
284+ if  [ -z  " $actualDistributionDir " ;  then 
285+   verbose " Contents of $TMP_DOWNLOAD_DIR :" 
286+   verbose " $( ls -la " $TMP_DOWNLOAD_DIR " ) " 
287+   die " Could not find Maven distribution directory in extracted archive" 
288+ fi 
289+ 
290+ verbose " Found extracted Maven distribution directory: $actualDistributionDir " 
291+ printf  %s\\ n " $distributionUrl " > " $TMP_DOWNLOAD_DIR /$actualDistributionDir /mvnw.url" 
292+ mv -- " $TMP_DOWNLOAD_DIR /$actualDistributionDir " " $MAVEN_HOME " ||  [ -d  " $MAVEN_HOME " ||  die " fail to move MAVEN_HOME" 
248293
249294clean ||  : 
250295exec_maven " $@ " 
0 commit comments