waylog-marcus opened a new issue, #442:
URL: https://github.com/apache/maven-wrapper/issues/442
## Description
When the extracted archive directory name does not match the archive
filename, both wrapper scripts fall back to scanning the extraction directory
for a subdirectory containing `bin/$MVN_CMD`. The two implementations disagree
on which candidate wins.
`mvnw` stops at the **first** match:
```sh
set +f
for dir in "$TMP_DOWNLOAD_DIR"/*; do
if [ -d "$dir" ]; then
if [ -f "$dir/bin/$MVN_CMD" ]; then
actualDistributionDir="$(basename "$dir")"
break
fi
fi
done
set -f
```
`mvnw.cmd` has no early exit, so the **last** match in enumeration order
wins:
```powershell
if (!$actualDistributionDir) {
Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
$testPath = Join-Path $_.FullName "bin/$MVN_CMD"
if (Test-Path -Path $testPath -PathType Leaf) {
$actualDistributionDir = $_.Name
}
}
}
```
With more than one candidate directory, the two scripts can therefore select
different distributions on the same archive, and the Windows result depends on
`Get-ChildItem` enumeration order.
## Suggested fix
Give `mvnw.cmd` first-match semantics to match `mvnw` — for example a
`foreach` with `break`, or `Select-Object -First 1`:
```powershell
$actualDistributionDir = (Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory
|
Where-Object { Test-Path -Path (Join-Path $_.FullName "bin/$MVN_CMD")
-PathType Leaf } |
Select-Object -First 1).Name
```
Erroring when more than one candidate is found would also be reasonable,
provided both scripts agree.
## Environment
maven-wrapper 3.3.4, `distributionType=only-script`, Maven 3.9.16.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]