1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.help;
20
21 import java.io.PrintStream;
22 import java.io.PrintWriter;
23 import java.io.Writer;
24 import java.nio.charset.StandardCharsets;
25 import java.util.List;
26
27 import org.apache.commons.cli.Options;
28 import org.apache.rat.OptionCollection;
29 import org.apache.rat.config.exclusion.StandardCollection;
30 import org.apache.rat.ui.UIOptionCollection;
31
32 import static java.lang.String.format;
33
34
35
36
37 public class Help extends AbstractHelp {
38
39
40
41
42 protected static final List<String> NOTES = List.of(
43 "RAT highlights possible issues.",
44 "RAT reports require interpretation.",
45 "RAT often requires some tuning before it runs well against a project.",
46 "RAT relies on heuristics: it may miss issues");
47
48
49 protected final PrintWriter writer;
50
51
52
53
54
55 public Help(final UIOptionCollection<?> optionCollection, final Writer writer) {
56 super(optionCollection);
57 this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
58 }
59
60
61
62
63
64 public Help(final UIOptionCollection<?> optionCollection, final PrintStream stream) {
65 this(optionCollection, new PrintWriter(stream, false, StandardCharsets.UTF_8));
66 }
67
68
69
70
71
72 public void printUsage(final Options opts) {
73 String syntax = format("java -jar apache-rat/target/apache-rat-%s.jar [options] [DIR|ARCHIVE]", versionInfo.getVersion());
74 helpFormatter.printHelp(writer, syntax, header("Available options"), opts, header("Argument Types"));
75
76 String argumentPadding = printArgumentTypes();
77
78 writer.println(header("Standard Collections"));
79 for (StandardCollection sc : StandardCollection.values()) {
80 writer.format("%n<%s>%n", sc.name());
81 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
82 argumentPadding + sc.desc());
83 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
84 argumentPadding + "File patterns: " + (sc.patterns().isEmpty() ? "<none>" : String.join(", ", sc.patterns())));
85 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
86 argumentPadding + "Provides a path matcher: " + sc.hasStaticDocumentNameMatcher());
87 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
88 argumentPadding + "Provides a file processor: " + sc.fileProcessorBuilder().hasNext());
89 }
90 writer.println("\nA path matcher will match specific information about the file.");
91 writer.println("\nA file processor will process the associated \"ignore\" file for include and exclude directives");
92
93 writer.println(header("Notes"));
94 int idx = 1;
95 for (String note : NOTES) {
96 writer.format("%d. %s%n", idx++, note);
97 }
98
99 writer.flush();
100 }
101
102
103
104
105
106 public String printArgumentTypes() {
107 String argumentPadding = createPadding(helpFormatter.getLeftPadding() + HELP_PADDING);
108
109 for (OptionCollection.ArgumentType argType : OptionCollection.ArgumentType.values()) {
110 if (argType != OptionCollection.ArgumentType.NONE) {
111 writer.format("%n<%s>%n", argType.getDisplayName());
112 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
113 argumentPadding + argType.description().get());
114 }
115 }
116 return argumentPadding;
117 }
118 }