|
18 | 18 | @REM ---------------------------------------------------------------------------- |
19 | 19 |
|
20 | 20 | @REM ---------------------------------------------------------------------------- |
21 | | -@REM Apache Maven Wrapper startup batch script, version 3.3.2 |
| 21 | +@REM Apache Maven Wrapper startup batch script, version 3.3.4 |
22 | 22 | @REM |
23 | 23 | @REM Optional ENV vars |
24 | 24 | @REM MVNW_REPOURL - repo url base for downloading maven distribution |
|
39 | 39 | @SET __MVNW_ARG0_NAME__= |
40 | 40 | @SET MVNW_USERNAME= |
41 | 41 | @SET MVNW_PASSWORD= |
42 | | -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) |
| 42 | +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) |
43 | 43 | @echo Cannot start maven from wrapper >&2 && exit /b 1 |
44 | 44 | @GOTO :EOF |
45 | 45 | : end batch / begin powershell #> |
@@ -72,16 +72,30 @@ switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { |
72 | 72 | # apply MVNW_REPOURL and calculate MAVEN_HOME |
73 | 73 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash> |
74 | 74 | if ($env:MVNW_REPOURL) { |
75 | | - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } |
76 | | - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" |
| 75 | + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } |
| 76 | + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" |
77 | 77 | } |
78 | 78 | $distributionUrlName = $distributionUrl -replace '^.*/','' |
79 | 79 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' |
80 | | -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" |
| 80 | + |
| 81 | +$MAVEN_M2_PATH = "$HOME/.m2" |
81 | 82 | if ($env:MAVEN_USER_HOME) { |
82 | | - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" |
| 83 | + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" |
| 84 | +} |
| 85 | + |
| 86 | +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { |
| 87 | + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null |
| 88 | +} |
| 89 | + |
| 90 | +$MAVEN_WRAPPER_DISTS = $null |
| 91 | +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { |
| 92 | + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" |
| 93 | +} else { |
| 94 | + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" |
83 | 95 | } |
84 | | -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' |
| 96 | + |
| 97 | +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" |
| 98 | +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' |
85 | 99 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" |
86 | 100 |
|
87 | 101 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { |
@@ -133,7 +147,33 @@ if ($distributionSha256Sum) { |
133 | 147 |
|
134 | 148 | # unzip and move |
135 | 149 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null |
136 | | -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null |
| 150 | + |
| 151 | +# Find the actual extracted directory name (handles snapshots where filename != directory name) |
| 152 | +$actualDistributionDir = "" |
| 153 | + |
| 154 | +# First try the expected directory name (for regular distributions) |
| 155 | +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" |
| 156 | +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" |
| 157 | +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { |
| 158 | + $actualDistributionDir = $distributionUrlNameMain |
| 159 | +} |
| 160 | + |
| 161 | +# If not found, search for any directory with the Maven executable (for snapshots) |
| 162 | +if (!$actualDistributionDir) { |
| 163 | + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { |
| 164 | + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" |
| 165 | + if (Test-Path -Path $testPath -PathType Leaf) { |
| 166 | + $actualDistributionDir = $_.Name |
| 167 | + } |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +if (!$actualDistributionDir) { |
| 172 | + Write-Error "Could not find Maven distribution directory in extracted archive" |
| 173 | +} |
| 174 | + |
| 175 | +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" |
| 176 | +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null |
137 | 177 | try { |
138 | 178 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null |
139 | 179 | } catch { |
|
0 commit comments