-
Couldn't load subscription status.
- Fork 2.8k
[MNG-8018] Fix MSYS/Git-Bash path mis-detection on Windows #10906
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
8545e2c
9031538
d5c6ad7
1633462
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,25 @@ public class MavenCli { | |
|
|
||
| private static final Pattern NEXT_LINE = Pattern.compile("\r?\n"); | ||
|
|
||
| /** Matches “/d/whatever” or “/C/…”. */ | ||
| private static final Pattern MSYS_PATH = Pattern.compile("^/([a-zA-Z])/(.*)$"); | ||
|
|
||
| /** | ||
| * Turns “/d/projects/foo” into “D:\\projects\\foo”. | ||
| * Returns the original string if it isn't an MSYS-style path. | ||
| */ | ||
| static String msysToWindowsPath(final String p) { | ||
|
||
| if (p == null) { | ||
| return null; | ||
| } | ||
| final Matcher m = MSYS_PATH.matcher(p); | ||
|
||
| if (m.matches()) { | ||
| return Character.toUpperCase(m.group(1).charAt(0)) + ":\\" | ||
| + m.group(2).replace('/', '\\'); | ||
| } | ||
| return p; | ||
| } | ||
|
|
||
| public MavenCli() { | ||
| this(null); | ||
| } | ||
|
|
@@ -363,6 +382,22 @@ void initialize(CliRequest cliRequest) throws ExitException { | |
| // | ||
| String mavenHome = System.getProperty(Constants.MAVEN_HOME); | ||
|
|
||
| if (org.codehaus.plexus.util.Os.isFamily("windows")) { | ||
| System.setProperty("user.home", msysToWindowsPath(System.getProperty("user.home"))); | ||
|
|
||
| for (final String k : new String[] { | ||
|
||
| Constants.MAVEN_REPO_LOCAL, // -Dmaven.repo.local | ||
| "user.settings", // -s / --settings | ||
| "alternateSettings", | ||
| "user.toolchains" | ||
| }) { | ||
| final String v = System.getProperty(k); | ||
|
||
| if (v != null) { | ||
| System.setProperty(k, msysToWindowsPath(v)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (mavenHome != null) { | ||
| System.setProperty( | ||
| Constants.MAVEN_HOME, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's MSYS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimal System, is a software distribution and build platform for Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MSYS2?
Might need to spell this out. Is MSYS really the style of string here, or is this just a Windows path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POSIX-style Windows paths produced by MSYS2/Git Bash (and Cygwin), e.g. /c/Users/... or /cygdrive/c/.... The method converts those to native C:... and returns the input if it’s already a native Windows path.