1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package net.sourceforge.pmd;
5
6 import net.sourceforge.pmd.renderers.CSVRenderer;
7 import net.sourceforge.pmd.renderers.EmacsRenderer;
8 import net.sourceforge.pmd.renderers.HTMLRenderer;
9 import net.sourceforge.pmd.renderers.IDEAJRenderer;
10 import net.sourceforge.pmd.renderers.Renderer;
11 import net.sourceforge.pmd.renderers.TextRenderer;
12 import net.sourceforge.pmd.renderers.XMLRenderer;
13 import net.sourceforge.pmd.renderers.VBHTMLRenderer;
14
15 public class CommandLineOptions {
16
17 private boolean debugEnabled;
18 private boolean jdk13;
19 private boolean shortNamesEnabled;
20
21 private String inputFileName;
22 private String reportFormat;
23 private String ruleSets;
24
25 private String[] args;
26
27 public CommandLineOptions(String[] args) {
28
29 if (args == null || args.length < 3) {
30 throw new RuntimeException(usage());
31 }
32
33 inputFileName = args[0];
34 reportFormat = args[1];
35 ruleSets = args[2];
36
37 this.args = args;
38
39 for (int i=0; i<args.length; i++) {
40 if (args[i].equals("-debug")) {
41 debugEnabled = true;
42 } else if (args[i].equals("-shortnames")) {
43 shortNamesEnabled = true;
44 } else if (args[i].equals("-jdk13")) {
45 jdk13 = true;
46 }
47 }
48 }
49
50 public Renderer createRenderer() {
51 if (reportFormat.equals("xml")) {
52 return new XMLRenderer();
53 }
54 if (reportFormat.equals("ideaj")) {
55 return new IDEAJRenderer(args);
56 }
57 if (reportFormat.equals("text")) {
58 return new TextRenderer();
59 }
60 if (reportFormat.equals("emacs")) {
61 return new EmacsRenderer();
62 }
63 if (reportFormat.equals("csv")) {
64 return new CSVRenderer();
65 }
66 if (reportFormat.equals("html")) {
67 return new HTMLRenderer();
68 }
69 if (reportFormat.equals("vbhtml")) {
70 return new VBHTMLRenderer();
71 }
72 if (!reportFormat.equals("")) {
73 try {
74 return (Renderer)Class.forName(reportFormat).newInstance();
75 } catch (Exception e) {
76 throw new IllegalArgumentException("Can't find the custom format " + reportFormat + ": " + e.getClass().getName());
77 }
78 }
79
80 throw new IllegalArgumentException("Can't create report with format of " + reportFormat);
81 }
82
83 public boolean containsCommaSeparatedFileList() {
84 return inputFileName.indexOf(',') != -1;
85 }
86
87 public String getInputFileName() {
88 return this.inputFileName;
89 }
90
91 public String getReportFormat() {
92 return this.reportFormat;
93 }
94
95 public String getRulesets() {
96 return this.ruleSets;
97 }
98
99 public boolean debugEnabled() {
100 return debugEnabled;
101 }
102
103 public boolean jdk13() {
104 return jdk13;
105 }
106
107 public boolean shortNamesEnabled() {
108 return shortNamesEnabled;
109 }
110
111 public String usage() {
112 return PMD.EOL +
113 PMD.EOL +
114 "Mandatory arguments:" + PMD.EOL +
115 "1) A java source code filename or directory" + PMD.EOL +
116 "2) A report format " + PMD.EOL +
117 "3) A ruleset filename or a comma-delimited string of ruleset filenames" + PMD.EOL +
118 PMD.EOL +
119 "For example: " + PMD.EOL +
120 "c://> java -jar pmd-1.5.jar c://my//source//code html rulesets/unusedcode.xml,rulesets/imports.xml" + PMD.EOL +
121 PMD.EOL +
122 "Optional arguments that may be put after the mandatory arguments are: " + PMD.EOL +
123 "-debug: prints debugging information " + PMD.EOL +
124 "-jdk13: enables PMD to parse source code written using 'assert' as an identifier" + PMD.EOL +
125 "-shortnames: prints shortened filenames in the report" + PMD.EOL +
126 PMD.EOL +
127 "For example: " + PMD.EOL +
128 "c://> java -jar pmd-1.5.jar c://my//source//code html rulesets/unusedcode.xml,rulesets/imports.xml -jdk13 -debug" + PMD.EOL +
129 PMD.EOL;
130 }
131 }
132
133
This page was automatically generated by Maven