Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 227   Methods: 17
NCLOC: 184   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CommandLineOptions.java 84.6% 82.1% 82.4% 83%
coverage coverage
 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.PapariTextRenderer;
 11    import net.sourceforge.pmd.renderers.Renderer;
 12    import net.sourceforge.pmd.renderers.SummaryHTMLRenderer;
 13    import net.sourceforge.pmd.renderers.TextRenderer;
 14    import net.sourceforge.pmd.renderers.VBHTMLRenderer;
 15    import net.sourceforge.pmd.renderers.XMLRenderer;
 16    import net.sourceforge.pmd.renderers.YAHTMLRenderer;
 17   
 18    import java.io.InputStreamReader;
 19    import java.text.MessageFormat;
 20   
 21    public class CommandLineOptions {
 22   
 23    private boolean debugEnabled;
 24    private String targetJDK = "1.4";
 25    private boolean shortNamesEnabled;
 26    private int cpus = Runtime.getRuntime().availableProcessors();
 27   
 28    private String excludeMarker = PMD.EXCLUDE_MARKER;
 29    private String inputPath;
 30    private String reportFormat;
 31    private String reportFile;
 32    private String ruleSets;
 33    private String encoding = new InputStreamReader(System.in).getEncoding();
 34    private String linePrefix;
 35    private String linkPrefix;
 36    private int minPriority = Rule.LOWEST_PRIORITY;
 37   
 38   
 39    private boolean checkJavaFiles = true;
 40    private boolean checkJspFiles = false;
 41   
 42    private String[] args;
 43   
 44  34 public CommandLineOptions(String[] args) {
 45   
 46  34 if (args == null || args.length < 3) {
 47  2 throw new RuntimeException(usage());
 48    }
 49  32 int optIndex = 0;
 50  32 if (args[0].charAt(0) == '-') {
 51  8 optIndex = args.length - 3;
 52    }
 53   
 54  32 inputPath = args[optIndex];
 55  32 reportFormat = args[optIndex+1];
 56  32 ruleSets = new SimpleRuleSetNameMapper(args[optIndex+2]).getRuleSets();
 57   
 58  32 this.args = args;
 59   
 60  32 for (int i = 0; i < args.length; i++) {
 61  114 if (args[i].equals("-debug")) {
 62  3 debugEnabled = true;
 63  111 } else if (args[i].equals("-shortnames")) {
 64  2 shortNamesEnabled = true;
 65  109 } else if (args[i].equals("-encoding")) {
 66  2 encoding = args[++i];
 67  107 } else if (args[i].equals("-cpus")) {
 68  3 try {
 69  3 cpus = Integer.parseInt(args[++i]);
 70    } catch (NumberFormatException e) {
 71  0 throw new RuntimeException(MessageFormat.format(
 72    "cpus parameter must be a whole number, {0} received",
 73    new String[] { args[i] }));
 74    }
 75  104 } else if (args[i].equals("-targetjdk")) {
 76  4 targetJDK = args[++i];
 77  100 } else if (args[i].equals("-excludemarker")) {
 78  2 excludeMarker = args[++i];
 79  98 } else if (args[i].equals("-jsp")) {
 80  0 checkJspFiles = true;
 81  98 } else if (args[i].equals("-nojava")) {
 82  0 checkJavaFiles = false;
 83  98 } else if (args[i].equals("-lineprefix")) {
 84  0 linePrefix = args[++i];
 85  98 } else if (args[i].equals("-linkprefix")) {
 86  0 linkPrefix = args[++i];
 87  98 } else if (args[i].equals("-minimumpriority")) {
 88  0 try {
 89  0 minPriority = Integer.parseInt(args[++i]);
 90    } catch (NumberFormatException e) {
 91  0 throw new RuntimeException(MessageFormat.format(
 92    "minimumpriority parameter must be a whole number, {0} received",
 93    new String[] { args[i] }));
 94    }
 95  98 } else if (args[i].equals("-reportfile")) {
 96  2 reportFile = args[++i];
 97    }
 98    }
 99    }
 100   
 101  9 public Renderer createRenderer() {
 102  9 if (reportFormat.equals("xml")) {
 103  1 return new XMLRenderer();
 104  8 } else if (reportFormat.equals("ideaj")) {
 105  1 return new IDEAJRenderer(args);
 106  7 } else if (reportFormat.equals("papari")) {
 107  0 return new PapariTextRenderer();
 108  7 } else if (reportFormat.equals("text")) {
 109  1 return new TextRenderer();
 110  6 } else if (reportFormat.equals("emacs")) {
 111  1 return new EmacsRenderer();
 112  5 } else if (reportFormat.equals("csv")) {
 113  1 return new CSVRenderer();
 114  4 } else if (reportFormat.equals("html")) {
 115  1 return new HTMLRenderer();
 116  3 } else if (reportFormat.equals("yahtml")) {
 117  0 return new YAHTMLRenderer();
 118  3 } else if (reportFormat.equals("summaryhtml")) {
 119  0 return new SummaryHTMLRenderer(linkPrefix, linePrefix);
 120  3 } else if (reportFormat.equals("vbhtml")) {
 121  1 return new VBHTMLRenderer();
 122    }
 123  2 if (!reportFormat.equals("")) {
 124  1 try {
 125  1 return (Renderer) Class.forName(reportFormat).newInstance();
 126    } catch (Exception e) {
 127  1 throw new IllegalArgumentException("Can't find the custom format " + reportFormat + ": " + e.getClass().getName());
 128    }
 129    }
 130   
 131  1 throw new IllegalArgumentException("Can't create report with format of " + reportFormat);
 132    }
 133   
 134  1 public boolean containsCommaSeparatedFileList() {
 135  1 return inputPath.indexOf(',') != -1;
 136    }
 137   
 138  2 public String getInputPath() {
 139  2 return this.inputPath;
 140    }
 141   
 142  3 public String getEncoding() {
 143  3 return this.encoding;
 144    }
 145   
 146  2 public String getReportFormat() {
 147  2 return this.reportFormat;
 148    }
 149   
 150  2 public String getReportFile() {
 151  2 return this.reportFile;
 152    }
 153   
 154  2 public String getRulesets() {
 155  2 return this.ruleSets;
 156    }
 157   
 158  2 public String getExcludeMarker() {
 159  2 return this.excludeMarker;
 160    }
 161   
 162  3 public boolean debugEnabled() {
 163  3 return debugEnabled;
 164    }
 165   
 166  3 public int getCpus() {
 167  3 return cpus;
 168    }
 169   
 170  5 public String getTargetJDK() {
 171  5 return targetJDK;
 172    }
 173   
 174  2 public boolean shortNamesEnabled() {
 175  2 return shortNamesEnabled;
 176    }
 177   
 178  0 public int getMinPriority() {
 179  0 return minPriority;
 180    }
 181   
 182  2 public String usage() {
 183  2 return PMD.EOL + PMD.EOL +
 184    "Mandatory arguments:" + PMD.EOL +
 185    "1) A java source code filename or directory" + PMD.EOL +
 186    "2) A report format " + PMD.EOL +
 187    "3) A ruleset filename or a comma-delimited string of ruleset filenames" + PMD.EOL +
 188    PMD.EOL +
 189    "For example: " + PMD.EOL +
 190    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code html unusedcode" + PMD.EOL +
 191    PMD.EOL +
 192    "Optional arguments that may be put before or after the mandatory arguments: " + PMD.EOL +
 193    "-debug: prints debugging information" + PMD.EOL +
 194    "-targetjdk: specifies a language version to target - 1.3, 1.4, 1.5 or 1.6" + PMD.EOL +
 195    "-cpus: specifies the number of threads to create" + PMD.EOL +
 196    "-encoding: specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8)" + PMD.EOL +
 197    "-excludemarker: specifies the String that marks the a line which PMD should ignore; default is NOPMD" + PMD.EOL +
 198    "-shortnames: prints shortened filenames in the report" + PMD.EOL +
 199    "-linkprefix: path to HTML source, for summary html renderer only" + PMD.EOL +
 200    "-lineprefix: custom anchor to affected line in the source file, for summary html renderer only" + PMD.EOL +
 201    "-minimumpriority: rule priority threshold; rules with lower priority than they will not be used" + PMD.EOL +
 202    "-reportfile: send report output to a file; default to System.out" + PMD.EOL +
 203    PMD.EOL +
 204    "For example: " + PMD.EOL +
 205    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code text unusedcode,imports -targetjdk 1.5 -debug" + PMD.EOL +
 206    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code xml basic,design -encoding UTF-8" + PMD.EOL +
 207    PMD.EOL;
 208    }
 209   
 210    /**
 211    * @return Returns the checkJavaFiles.
 212    */
 213  0 public boolean isCheckJavaFiles() {
 214  0 return checkJavaFiles;
 215    }
 216   
 217    /**
 218    * @return Returns the checkJspFiles.
 219    */
 220  0 public boolean isCheckJspFiles() {
 221  0 return checkJspFiles;
 222    }
 223    }
 224   
 225   
 226   
 227