mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-10 13:15:27 +00:00
Make Environment methods related to command line options more homogeneous
This commit is contained in:
@@ -327,12 +327,12 @@ public class DaemonConnector {
|
||||
args.add("-Xmx" + maxHeapSize);
|
||||
}
|
||||
|
||||
Environment.MVND_HOME.appendAsCommandLineOption(args, mvndHome.toString());
|
||||
Environment.MVND_HOME.addCommandLineOption(args, mvndHome.toString());
|
||||
Environment.LOGBACK_CONFIGURATION_FILE
|
||||
.appendAsCommandLineOption(args, parameters.logbackConfigurationPath().toString());
|
||||
Environment.MVND_UID.appendAsCommandLineOption(args, uid);
|
||||
Environment.MVND_DAEMON_STORAGE.appendAsCommandLineOption(args, parameters.daemonStorage().toString());
|
||||
Environment.MVND_REGISTRY.appendAsCommandLineOption(args, parameters.registry().toString());
|
||||
.addCommandLineOption(args, parameters.logbackConfigurationPath().toString());
|
||||
Environment.MVND_UID.addCommandLineOption(args, uid);
|
||||
Environment.MVND_DAEMON_STORAGE.addCommandLineOption(args, parameters.daemonStorage().toString());
|
||||
Environment.MVND_REGISTRY.addCommandLineOption(args, parameters.registry().toString());
|
||||
parameters.discriminatingCommandLineOptions(args);
|
||||
args.add(MavenDaemon.class.getName());
|
||||
command = String.join(" ", args);
|
||||
|
@@ -93,7 +93,7 @@ public class DaemonParameters {
|
||||
|
||||
public void discriminatingCommandLineOptions(List<String> args) {
|
||||
discriminatingValues()
|
||||
.forEach(envValue -> envValue.envKey.appendAsCommandLineOption(args, envValue.asString()));
|
||||
.forEach(envValue -> envValue.envKey.addCommandLineOption(args, envValue.asString()));
|
||||
}
|
||||
|
||||
public Path mvndHome() {
|
||||
|
@@ -78,7 +78,7 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
|
||||
// Batch mode
|
||||
boolean batchMode = Environment.MAVEN_BATCH_MODE.hasCommandOption(args);
|
||||
boolean batchMode = Environment.MAVEN_BATCH_MODE.hasCommandLineOption(args);
|
||||
|
||||
// System properties
|
||||
for (Iterator<String> it = args.iterator(); it.hasNext();) {
|
||||
@@ -228,21 +228,21 @@ public class DefaultClient implements Client {
|
||||
return DefaultResult.success(argv);
|
||||
}
|
||||
|
||||
if (!Environment.MVND_THREADS.hasCommandOption(args)) {
|
||||
Environment.MVND_THREADS.appendAsCommandLineOption(args, parameters.threads());
|
||||
if (!Environment.MVND_THREADS.hasCommandLineOption(args)) {
|
||||
Environment.MVND_THREADS.addCommandLineOption(args, parameters.threads());
|
||||
}
|
||||
if (!Environment.MVND_BUILDER.hasCommandOption(args)) {
|
||||
Environment.MVND_BUILDER.appendAsCommandLineOption(args, parameters.builder());
|
||||
if (!Environment.MVND_BUILDER.hasCommandLineOption(args)) {
|
||||
Environment.MVND_BUILDER.addCommandLineOption(args, parameters.builder());
|
||||
}
|
||||
final Path settings = parameters.settings();
|
||||
if (settings != null && !Environment.MAVEN_SETTINGS.hasCommandOption(args)) {
|
||||
Environment.MAVEN_SETTINGS.appendAsCommandLineOption(args, settings.toString());
|
||||
if (settings != null && !Environment.MAVEN_SETTINGS.hasCommandLineOption(args)) {
|
||||
Environment.MAVEN_SETTINGS.addCommandLineOption(args, settings.toString());
|
||||
}
|
||||
final Path localMavenRepository = parameters.mavenRepoLocal();
|
||||
if (localMavenRepository != null && !Environment.MAVEN_REPO_LOCAL.hasCommandOption(args)) {
|
||||
Environment.MAVEN_REPO_LOCAL.appendAsCommandLineOption(args, localMavenRepository.toString());
|
||||
if (localMavenRepository != null && !Environment.MAVEN_REPO_LOCAL.hasCommandLineOption(args)) {
|
||||
Environment.MAVEN_REPO_LOCAL.addCommandLineOption(args, localMavenRepository.toString());
|
||||
}
|
||||
Environment.MVND_TERMINAL_WIDTH.appendAsCommandLineOption(args, Integer.toString(output.getTerminalWidth()));
|
||||
Environment.MVND_TERMINAL_WIDTH.addCommandLineOption(args, Integer.toString(output.getTerminalWidth()));
|
||||
|
||||
final DaemonConnector connector = new DaemonConnector(parameters, registry);
|
||||
try (DaemonClientConnection daemon = connector.connect(output)) {
|
||||
|
@@ -322,7 +322,7 @@ public enum Environment {
|
||||
return property + "=" + type.normalize(value);
|
||||
}
|
||||
|
||||
public void appendAsCommandLineOption(List<String> args, String value) {
|
||||
public void addCommandLineOption(Collection<String> args, String value) {
|
||||
if (!options.isEmpty()) {
|
||||
args.add(options.get(0));
|
||||
args.add(type.normalize(value));
|
||||
@@ -331,26 +331,12 @@ public enum Environment {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCommandOption(Collection<String> args) {
|
||||
public boolean hasCommandLineOption(Collection<String> args) {
|
||||
final String[] prefixes = getPrefixes();
|
||||
return args.stream().anyMatch(arg -> Stream.of(prefixes).anyMatch(arg::startsWith));
|
||||
}
|
||||
|
||||
private String[] getPrefixes() {
|
||||
final String[] prefixes;
|
||||
if (options.isEmpty()) {
|
||||
prefixes = new String[] { "-D" + property + "=" };
|
||||
} else if (property != null) {
|
||||
prefixes = new String[options.size() + 1];
|
||||
options.toArray(prefixes);
|
||||
prefixes[options.size()] = "-D" + property + "=";
|
||||
} else {
|
||||
prefixes = options.toArray(new String[0]);
|
||||
}
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
public String removeCommandLineOption(List<String> args) {
|
||||
public String removeCommandLineOption(Collection<String> args) {
|
||||
final String[] prefixes = getPrefixes();
|
||||
String value = null;
|
||||
for (Iterator<String> it = args.iterator(); it.hasNext();) {
|
||||
@@ -378,6 +364,20 @@ public enum Environment {
|
||||
return value;
|
||||
}
|
||||
|
||||
private String[] getPrefixes() {
|
||||
final String[] prefixes;
|
||||
if (options.isEmpty()) {
|
||||
prefixes = new String[] { "-D" + property + "=" };
|
||||
} else if (property != null) {
|
||||
prefixes = new String[options.size() + 1];
|
||||
options.toArray(prefixes);
|
||||
prefixes[options.size()] = "-D" + property + "=";
|
||||
} else {
|
||||
prefixes = options.toArray(new String[0]);
|
||||
}
|
||||
return prefixes;
|
||||
}
|
||||
|
||||
public static String cygpath(String result) {
|
||||
String path = result.replace('/', '\\');
|
||||
if (path.matches("\\\\cygdrive\\\\[a-z]\\\\.*")) {
|
||||
|
@@ -52,35 +52,35 @@ public class NativeTestClient implements Client {
|
||||
final List<String> cmd = new ArrayList<String>(args.size() + 1);
|
||||
cmd.add(mvndNativeExecutablePath.toString());
|
||||
cmd.addAll(args);
|
||||
if (!Environment.MVND_DAEMON_STORAGE.hasCommandOption(args)) {
|
||||
if (!Environment.MVND_DAEMON_STORAGE.hasCommandLineOption(args)) {
|
||||
Path daemonStorage = parameters.daemonStorage();
|
||||
Environment.MVND_DAEMON_STORAGE.appendAsCommandLineOption(cmd, daemonStorage.toString());
|
||||
Environment.MVND_DAEMON_STORAGE.addCommandLineOption(cmd, daemonStorage.toString());
|
||||
}
|
||||
if (!Environment.MAVEN_REPO_LOCAL.hasCommandOption(args)) {
|
||||
if (!Environment.MAVEN_REPO_LOCAL.hasCommandLineOption(args)) {
|
||||
Path mavenRepoLocal = parameters.mavenRepoLocal();
|
||||
Environment.MAVEN_REPO_LOCAL.appendAsCommandLineOption(cmd, mavenRepoLocal.toString());
|
||||
Environment.MAVEN_REPO_LOCAL.addCommandLineOption(cmd, mavenRepoLocal.toString());
|
||||
}
|
||||
if (!Environment.MAVEN_SETTINGS.hasCommandOption(args)) {
|
||||
if (!Environment.MAVEN_SETTINGS.hasCommandLineOption(args)) {
|
||||
final Path settings = parameters.settings();
|
||||
if (settings != null) {
|
||||
Environment.MAVEN_SETTINGS.appendAsCommandLineOption(cmd, settings.toString());
|
||||
Environment.MAVEN_SETTINGS.addCommandLineOption(cmd, settings.toString());
|
||||
}
|
||||
}
|
||||
if (!Environment.MVND_THREADS.hasCommandOption(args)) {
|
||||
if (!Environment.MVND_THREADS.hasCommandLineOption(args)) {
|
||||
final String threads = parameters.threads();
|
||||
Environment.MVND_THREADS.appendAsCommandLineOption(cmd, threads);
|
||||
Environment.MVND_THREADS.addCommandLineOption(cmd, threads);
|
||||
}
|
||||
Environment.MVND_TERMINAL_WIDTH.appendAsCommandLineOption(cmd, Integer.toString(output.getTerminalWidth()));
|
||||
Environment.MVND_TERMINAL_WIDTH.addCommandLineOption(cmd, Integer.toString(output.getTerminalWidth()));
|
||||
|
||||
final ProcessBuilder builder = new ProcessBuilder(cmd.toArray(new String[0]))
|
||||
.directory(parameters.userDir().toFile()) //
|
||||
.redirectErrorStream(true);
|
||||
|
||||
final Map<String, String> env = builder.environment();
|
||||
if (!Environment.MVND_HOME.hasCommandOption(args)) {
|
||||
if (!Environment.MVND_HOME.hasCommandLineOption(args)) {
|
||||
env.put("MVND_HOME", System.getProperty("mvnd.home"));
|
||||
}
|
||||
if (!Environment.JAVA_HOME.hasCommandOption(args)) {
|
||||
if (!Environment.JAVA_HOME.hasCommandLineOption(args)) {
|
||||
env.put("JAVA_HOME", System.getProperty("java.home"));
|
||||
}
|
||||
final String cmdString = String.join(" ", cmd);
|
||||
|
Reference in New Issue
Block a user