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