You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/08/30 07:14:16 UTC
[maven-mvnd] branch master updated: Missing argument for option -D, fixes #662 (#679)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
The following commit(s) were added to refs/heads/master by this push:
new 449e815 Missing argument for option -D, fixes #662 (#679)
449e815 is described below
commit 449e8159735acb70a93fa9d1b84d55fd836e91e4
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Aug 30 09:14:12 2022 +0200
Missing argument for option -D, fixes #662 (#679)
Co-authored-by: 核桃 <he...@2dfire.com>
---
.../org/mvndaemon/mvnd/client/DefaultClient.java | 27 +++++++++++++++++++++-
.../org/mvndaemon/mvnd/it/MavenConfNativeIT.java | 3 ++-
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
index 7a4759a..eb890ba 100644
--- a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
+++ b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
@@ -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(
diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java
index 8a694c6..ff875c6 100644
--- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java
+++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MavenConfNativeIT.java
@@ -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);