1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.tools;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.commons.cli.Option;
25 import org.apache.commons.lang3.StringUtils;
26 import org.apache.commons.text.WordUtils;
27 import org.apache.rat.commandline.Arg;
28
29 import static java.lang.String.format;
30
31
32
33
34 public class MavenOption extends AbstractOption {
35
36 private static final Map<Arg, String> DEFAULT_VALUES = new HashMap<>();
37
38 static {
39 DEFAULT_VALUES.put(Arg.OUTPUT_FILE, "${project.build.directory}/rat.txt");
40 }
41
42
43
44
45
46
47 MavenOption(final Option option) {
48 super(option, MavenGenerator.createName(option));
49 }
50
51 @Override
52 protected String cleanupName(final Option option) {
53 return format("<%s>", MavenGenerator.createName(option));
54 }
55
56 @Override
57 public String getDefaultValue() {
58 Arg arg = Arg.findArg(option);
59 String result = DEFAULT_VALUES.get(arg);
60 if (result == null) {
61 result = arg.defaultValue();
62 }
63 return result;
64 }
65
66 public String getPropertyAnnotation(final String fname) {
67 StringBuilder sb = new StringBuilder("@Parameter");
68 String property = option.hasArgs() ? null : format("property = \"rat.%s\"", fname);
69 String defaultValue = option.isDeprecated() ? null : getDefaultValue();
70 if (property != null || defaultValue != null) {
71 sb.append("(");
72 if (property != null) {
73 sb.append(property).append(defaultValue != null ? ", " : StringUtils.EMPTY);
74 }
75 if (defaultValue != null) {
76 sb.append(format("defaultValue = \"%s\"", defaultValue));
77 }
78 sb.append(")");
79 }
80 return sb.toString();
81 }
82
83 public String getMethodSignature(final String indent, final boolean multiple) {
84 StringBuilder sb = new StringBuilder();
85 if (isDeprecated()) {
86 sb.append(format("%s@Deprecated%n", indent));
87 }
88 String fname = WordUtils.capitalize(name);
89 String args = option.hasArg() ? "String" : "boolean";
90 if (multiple) {
91 if (!(fname.endsWith("s") || fname.endsWith("Approved") || fname.endsWith("Denied"))) {
92 fname = fname + "s";
93 }
94 args = args + "[]";
95 }
96
97 return sb.append(format("%1$s%5$s%n%1$spublic void set%3$s(%4$s %2$s)",
98 indent, name, fname, args, getPropertyAnnotation(fname)))
99 .toString();
100 }
101 }