Skip to content

Commit

Permalink
Missing argument for option -D apache#662
Browse files Browse the repository at this point in the history
  • Loading branch information
核桃 committed Jul 2, 2022
1 parent 1ec11ab commit d642ac5
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -139,9 +135,23 @@ public static void main(String[] argv) throws Exception {
}

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);
}
Expand All @@ -156,6 +166,14 @@ public static void setSystemPropertiesFromCommandLine(List<String> args) {
}
}

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(
Expand Down

0 comments on commit d642ac5

Please sign in to comment.