1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.wrapper.cli;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24
25
26
27 public abstract class AbstractPropertiesCommandLineConverter extends AbstractCommandLineConverter<Map<String, String>> {
28 protected abstract String getPropertyOption();
29
30 protected abstract String getPropertyOptionDetailed();
31
32 protected abstract String getPropertyOptionDescription();
33
34 public void configure(CommandLineParser parser) {
35 CommandLineOption option = parser.option(getPropertyOption(), getPropertyOptionDetailed());
36 option = option.hasArguments();
37 option.hasDescription(getPropertyOptionDescription());
38 }
39
40 protected Map<String, String> newInstance() {
41 return new HashMap<>();
42 }
43
44 public Map<String, String> convert(ParsedCommandLine options, Map<String, String> properties)
45 throws CommandLineArgumentException {
46 for (String keyValueExpression : options.option(getPropertyOption()).getValues()) {
47 int pos = keyValueExpression.indexOf("=");
48 if (pos < 0) {
49 properties.put(keyValueExpression, "");
50 } else {
51 properties.put(keyValueExpression.substring(0, pos), keyValueExpression.substring(pos + 1));
52 }
53 }
54 return properties;
55 }
56 }