diff --git a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java index a4df3654..e5f79753 100644 --- a/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java +++ b/common/src/main/java/org/jboss/fuse/mvnd/common/Environment.java @@ -20,6 +20,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -139,7 +140,7 @@ public enum Environment { return MVND_PROPERTIES_PATH .environmentVariable() .orSystemProperty() - .orDefault(() -> System.getProperty("user.home") + "/.m2/mvnd.properties") + .orDefault(() -> Paths.get(System.getProperty("user.home"), ".m2", "mvnd.properties").toString()) .asPath() .toAbsolutePath().normalize(); } @@ -325,10 +326,22 @@ public enum Environment { } public Path asPath() { - final String result = get(); + String result = get(); + if (result != null && Os.current().isCygwin()) { + result = cygpath(result); + } return result == null ? null : Paths.get(result); } + static String cygpath(String result) { + String path = result.replace('/', '\\'); + if (path.matches("\\\\cygdrive\\\\[a-z]\\\\.*")) { + String s = path.substring("\\cygdrive\\".length()); + result = s.substring(0, 1).toUpperCase(Locale.ENGLISH) + ":" + s.substring(1); + } + return result; + } + public boolean asBoolean() { return Boolean.parseBoolean(get()); } diff --git a/common/src/main/java/org/jboss/fuse/mvnd/common/Os.java b/common/src/main/java/org/jboss/fuse/mvnd/common/Os.java index bd12f272..ff1f5d09 100644 --- a/common/src/main/java/org/jboss/fuse/mvnd/common/Os.java +++ b/common/src/main/java/org/jboss/fuse/mvnd/common/Os.java @@ -20,7 +20,18 @@ import java.util.Locale; public enum Os { LINUX(true), MAC(true), - WINDOWS(false), + WINDOWS(false) { + private boolean cygwin; + { + String pwd = System.getenv("PWD"); + cygwin = pwd != null && pwd.startsWith("/"); + } + + @Override + public boolean isCygwin() { + return cygwin; + } + }, UNKNOWN(false) { @Override @@ -58,4 +69,8 @@ public enum Os { return unixLike; } + public boolean isCygwin() { + return false; + } + } diff --git a/common/src/test/java/org/jboss/fuse/mvnd/common/EnvironmentTest.java b/common/src/test/java/org/jboss/fuse/mvnd/common/EnvironmentTest.java index 0fe66850..beee9cd5 100644 --- a/common/src/test/java/org/jboss/fuse/mvnd/common/EnvironmentTest.java +++ b/common/src/test/java/org/jboss/fuse/mvnd/common/EnvironmentTest.java @@ -87,6 +87,11 @@ public class EnvironmentTest { } } + @Test + void cygwin() { + Assertions.assertEquals("C:\\jdk-11.0.2\\", Environment.EnvValue.cygpath("/cygdrive/c/jdk-11.0.2/")); + } + static class EnvironmentResource implements AutoCloseable { private final Properties props = new Properties();