mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-26 05:58:27 +00:00
Co-authored-by: 核桃 <hetao@2dfire.com>
This commit is contained in:
@@ -30,11 +30,14 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.fusesource.jansi.internal.CLibrary;
|
||||
import org.jline.utils.AttributedString;
|
||||
@@ -139,9 +142,23 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
|
||||
public static void setSystemPropertiesFromCommandLine(List<String> args) {
|
||||
for (String arg : args) {
|
||||
final Iterator<String> iterator = args.iterator();
|
||||
boolean defineIsEmpty = false;
|
||||
while (iterator.hasNext()) {
|
||||
final String arg = iterator.next();
|
||||
String val = Environment.MAVEN_DEFINE.removeCommandLineOption(new ArrayList<>(Collections.singletonList(arg)));
|
||||
/* not -D or --define and pre define is empty */
|
||||
if (val == null && defineIsEmpty) {
|
||||
defineIsEmpty = false;
|
||||
/* not all of Environment, use arg as pre define value */
|
||||
val = maybeDefineCommandLineOption(arg) ? arg : "";
|
||||
}
|
||||
if (val != null) {
|
||||
/* empty -D or --define, next arg is value */
|
||||
if (val.isEmpty() && iterator.hasNext()) {
|
||||
defineIsEmpty = true;
|
||||
continue;
|
||||
}
|
||||
if (val.isEmpty()) {
|
||||
throw new IllegalArgumentException("Missing argument for option " + arg);
|
||||
}
|
||||
@@ -156,6 +173,14 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean maybeDefineCommandLineOption(String arg) {
|
||||
// if arg maybe MAVEN_DEFINE value
|
||||
return EnumSet.allOf(Environment.class)
|
||||
.stream()
|
||||
.filter(e -> e != Environment.MAVEN_DEFINE)
|
||||
.noneMatch(e -> e.hasCommandLineOption(Collections.singletonList(arg)));
|
||||
}
|
||||
|
||||
public DefaultClient(DaemonParameters parameters) {
|
||||
// Those options are needed in order to be able to set the environment correctly
|
||||
this.parameters = parameters.withJdkJavaOpts(
|
||||
|
@@ -37,8 +37,9 @@ public class MavenConfNativeIT {
|
||||
@Test
|
||||
void version() throws IOException, InterruptedException {
|
||||
final TestClientOutput o = new TestClientOutput();
|
||||
// this test also exercise the "-D foo=bar" syntax for defining properties
|
||||
client.execute(o, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
|
||||
"-Dexpression=maven.conf", "-q", "-DforceStdout", "--raw-streams").assertSuccess();
|
||||
"-D", "expression=maven.conf", "-q", "-DforceStdout", "--raw-streams").assertSuccess();
|
||||
String conf = parameters.mvndHome().resolve("mvn/conf").toString();
|
||||
assertTrue(o.getMessages().stream()
|
||||
.anyMatch(m -> m.toString().contains(conf)), "Output should contain " + conf);
|
||||
|
Reference in New Issue
Block a user