mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-16 16:23:15 +00:00
@@ -20,6 +20,7 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@@ -139,7 +140,7 @@ public enum Environment {
|
|||||||
return MVND_PROPERTIES_PATH
|
return MVND_PROPERTIES_PATH
|
||||||
.environmentVariable()
|
.environmentVariable()
|
||||||
.orSystemProperty()
|
.orSystemProperty()
|
||||||
.orDefault(() -> System.getProperty("user.home") + "/.m2/mvnd.properties")
|
.orDefault(() -> Paths.get(System.getProperty("user.home"), ".m2", "mvnd.properties").toString())
|
||||||
.asPath()
|
.asPath()
|
||||||
.toAbsolutePath().normalize();
|
.toAbsolutePath().normalize();
|
||||||
}
|
}
|
||||||
@@ -325,10 +326,22 @@ public enum Environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Path asPath() {
|
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);
|
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() {
|
public boolean asBoolean() {
|
||||||
return Boolean.parseBoolean(get());
|
return Boolean.parseBoolean(get());
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,18 @@ import java.util.Locale;
|
|||||||
public enum Os {
|
public enum Os {
|
||||||
LINUX(true),
|
LINUX(true),
|
||||||
MAC(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) {
|
UNKNOWN(false) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,4 +69,8 @@ public enum Os {
|
|||||||
return unixLike;
|
return unixLike;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCygwin() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
static class EnvironmentResource implements AutoCloseable {
|
||||||
|
|
||||||
private final Properties props = new Properties();
|
private final Properties props = new Properties();
|
||||||
|
Reference in New Issue
Block a user