gnodet-bot commented on code in PR #10906:
URL: https://github.com/apache/maven/pull/10906#discussion_r4272134473
##########
compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -211,6 +211,26 @@ public class MavenCli {
private static final Pattern NEXT_LINE = Pattern.compile("\r?\n");
+ /** Matches a path starting with a drive letter, like /d/whatever or
/C/... */
+ private static final Pattern MSYS_PATH =
Pattern.compile("^/([a-zA-Z])/(.*)$");
+
+ /**
+ * Converts a POSIX-style Windows path as used by MSYS2 and Git Bash,
+ * e.g. "/c/Users/alice/file.txt", to a native Windows path
"C:\Users\alice\file.txt".
+ * Returns the original string if it is not such a path, a native Windows
path for instance.
+ */
+ static String msysToWindowsPath(final String path) {
+ if (path == null) {
+ return null;
+ }
+ final Matcher matcher = MSYS_PATH.matcher(path);
+ if (matcher.matches()) {
+ return Character.toUpperCase(matcher.group(1).charAt(0)) + ":\\"
+ + matcher.group(2).replace('/', '\\');
+ }
Review Comment:
🔁 **Duplicate logic: `msysToWindowsPath()` can delegate to
`MsysPaths.toNativePath()`**
`MavenCli.msysToWindowsPath()` (lines 215–230) reimplements the same regex +
backslash-replacement as `MsysPaths.toNativePath()` independently. Both use
`^/([a-zA-Z])/(.*)$` and the same character-uppercasing logic — two copies of
the same bug fix surface to maintain.
`compat/maven-embedder` already depends on `maven-cli`, so the fix is
straightforward: make `MsysPaths` and its `toNativePath(String)` method
`public`, then delegate:
```suggestion
public static String msysToWindowsPath(final String path) {
return org.apache.maven.cling.invoker.MsysPaths.toNativePath(path);
}
```
(Drop the `MSYS_PATH` field and the duplicated body once you delegate.)
--
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]