maven-wrapper icon indicating copy to clipboard operation
maven-wrapper copied to clipboard

Workaround: Windows Junction Link handling issue in mvnw.cmd

Open fp024 opened this issue 8 months ago • 2 comments

hello.

I applied to join Apache JIRA, but I wasn't sure if I would be approved as a member, so I submitted a PR for issue reporting purposes.

Issue

Move-Item fails when the .m2 path is in the following state:

  • Junction link reference status of m2 directory on my system image-20240530210414913
    • G:\Maven\.m2 is the actual path.

The argument value of -Destnation in PowerShell's Move-Item command must be an actual path, but in my environment, it is a junction link and is bound to fail.

Workaround

So I modified the code to get $MAVEN_HOME_PARENT as follows.

# ...
$MAVEN_M2_PATH = "$HOME/.m2"
if ($env:MAVEN_USER_HOME) {
  $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
}

if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
    New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
}

$MAVEN_WRAPPER_DISTS = $null
if ((Get-Item $MAVEN_M2_PATH).Target -eq $null) {
  $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
} else {
  $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
}

$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
# ...
  • The actual path could be obtained by obtaining Target[0] on the Item obtained with Get-Item -Path {Path}.

    • If the path passed as an argument is an actual path rather than a junction link path, it is $null.

This PR commit was posted for issue reporting purposes only, so it may require expert editing.

Please confirm. thank you have a good day. 👍


Following this checklist to help us incorporate your contribution quickly and easily:

  • [x] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MWRAPPER) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • [x] Each commit in the pull request should have a meaningful subject line and body.
  • [ ] Format the pull request title like [MWRAPPER-XXX] - Fixes bug in ApproximateQuantiles, where you replace MWRAPPER-XXX with the appropriate JIRA issue. Best practice is to use the JIRA issue title in the pull request title and in the first line of the commit message.
  • [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x] Run mvn clean verify to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • [ ] You have run the integration tests successfully (mvn -Prun-its clean verify).

If your pull request is about ~20 lines of code you don't need to sign an [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure please ask on the developers list.

To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0) you have to acknowledge this by using the following check-box.

fp024 avatar May 31 '24 12:05 fp024