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