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.Collections;
26 import java.util.List;
27
28 import org.apache.commons.cli.Options;
29 import org.apache.rat.OptionCollection;
30 import org.apache.rat.config.exclusion.StandardCollection;
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 = Collections.unmodifiableList(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
50 protected final PrintWriter writer;
51
52
53
54
55
56 public Help(final Writer writer) {
57 super();
58 this.writer = writer instanceof PrintWriter ? (PrintWriter) writer : new PrintWriter(writer);
59 }
60
61
62
63
64
65 public Help(final PrintStream stream) {
66 this(new PrintWriter(stream, false, StandardCharsets.UTF_8));
67 }
68
69
70
71
72
73 public void printUsage(final Options opts) {
74 String syntax = format("java -jar apache-rat/target/apache-rat-%s.jar [options] [DIR|ARCHIVE]", versionInfo.getVersion());
75 helpFormatter.printHelp(writer, syntax, header("Available options"), opts, header("Argument Types"));
76
77 String argumentPadding = printArgumentTypes();
78
79 writer.println(header("Standard Collections"));
80 for (StandardCollection sc : StandardCollection.values()) {
81 writer.format("%n<%s>%n", sc.name());
82 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
83 argumentPadding + sc.desc());
84 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
85 argumentPadding + "File patterns: " + (sc.patterns().isEmpty() ? "<none>" : String.join(", ", sc.patterns())));
86 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
87 argumentPadding + "Provides a path matcher: " + sc.hasStaticDocumentNameMatcher());
88 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
89 argumentPadding + "Provides a file processor: " + sc.fileProcessorBuilder().hasNext());
90 }
91 writer.println("\nA path matcher will match specific information about the file.");
92 writer.println("\nA file processor will process the associated \"ignore\" file for include and exclude directives");
93
94 writer.println(header("Notes"));
95 int idx = 1;
96 for (String note : NOTES) {
97 writer.format("%d. %s%n", idx++, note);
98 }
99
100 writer.flush();
101 }
102
103
104
105
106
107 public String printArgumentTypes() {
108 String argumentPadding = createPadding(helpFormatter.getLeftPadding() + HELP_PADDING);
109
110 for (OptionCollection.ArgumentType argType : OptionCollection.ArgumentType.values()) {
111 if (argType != OptionCollection.ArgumentType.NONE) {
112 writer.format("%n<%s>%n", argType.getDisplayName());
113 helpFormatter.printWrapped(writer, helpFormatter.getWidth(), helpFormatter.getLeftPadding() + HELP_PADDING + HELP_PADDING,
114 argumentPadding + argType.description().get());
115 }
116 }
117 return argumentPadding;
118 }
119 }