Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround: Windows Junction Link handling issue in mvnw.cmd #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fp024
Copy link

@fp024 fp024 commented May 31, 2024

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:

  • 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.
  • 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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.

@cstamas
Copy link
Member

cstamas commented May 31, 2024

@michael-o ping

@fp024
Copy link
Author

fp024 commented May 31, 2024

hello.

I received a GitHub Action build failure email and checked the code again.

Here's what I saw in PowerShell ISE after separating that part:

# Set MAVEN_USER_HOME manually
# $env:MAVEN_USER_HOME="D:/MAVEN2/.m2"
$env:MAVEN_USER_HOME=$null

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

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[0] -eq $null) { # 💡Re-edited part
  Write-Output "is null: actual path"
  $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
  Write-Output "MAVEN_WRAPPER_DISTS: $MAVEN_WRAPPER_DISTS"
} else {
  $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
  Write-Output "not null: junction path -> actual path"
  Write-Output "MAVEN_WRAPPER_DISTS: $MAVEN_WRAPPER_DISTS"
}

When MAVEN_USER_HOME is not set as an environment variable

  • MAVEN_M2_PATH="HOME/.m2"

image-20240601082911919

  • C:\Users\{UserName}/.m2 is the junction path
    • G:\Maven\m2/wrapper/dists is the actual path
    • The actual path to the picture in the first comment is incorrect: my actual path environment is G:\Maven\m2, not G:\Maven\.m2.

When MAVEN_USER_HOME is set as an environment variable

  • MAVEN_M2_PATH="D:/MAVEN2/.m2"
    • D:/MAVEN2/.m2 is the actual path

image-20240601083148668

thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants