Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 154   Methods: 12
NCLOC: 126   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CommandLineOptions.java 91.7% 94.2% 100% 94%
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   
 20    public class CommandLineOptions {
 21   
 22    private boolean debugEnabled;
 23    private String targetJDK = "1.4";
 24    private boolean shortNamesEnabled;
 25   
 26    private String excludeMarker = ExcludeLines.EXCLUDE_MARKER;
 27    private String inputPath;
 28    private String reportFormat;
 29    private String ruleSets;
 30    private String encoding = new InputStreamReader(System.in).getEncoding();
 31   
 32    private String[] args;
 33   
 34  23 public CommandLineOptions(String[] args) {
 35   
 36  23 if (args == null || args.length < 3) {
 37  2 throw new RuntimeException(usage());
 38    }
 39   
 40  21 inputPath = args[0];
 41  21 reportFormat = args[1];
 42  21 ruleSets = new SimpleRuleSetNameMapper(args[2]).getRuleSets();
 43   
 44  21 this.args = args;
 45   
 46  21 for (int i = 0; i < args.length; i++) {
 47  73 if (args[i].equals("-debug")) {
 48  1 debugEnabled = true;
 49  72 } else if (args[i].equals("-shortnames")) {
 50  1 shortNamesEnabled = true;
 51  71 } else if (args[i].equals("-encoding")) {
 52  1 encoding = args[i + 1];
 53  70 } else if (args[i].equals("-targetjdk")) {
 54  2 targetJDK = args[i + 1];
 55  68 } else if (args[i].equals("-excludemarker")) {
 56  1 excludeMarker = args[i + 1];
 57    }
 58    }
 59    }
 60   
 61  9 public Renderer createRenderer() {
 62  9 if (reportFormat.equals("xml")) {
 63  1 return new XMLRenderer();
 64  8 } else if (reportFormat.equals("ideaj")) {
 65  1 return new IDEAJRenderer(args);
 66  7 } else if (reportFormat.equals("papari")) {
 67  0 return new PapariTextRenderer();
 68  7 } else if (reportFormat.equals("text")) {
 69  1 return new TextRenderer();
 70  6 } else if (reportFormat.equals("emacs")) {
 71  1 return new EmacsRenderer();
 72  5 } else if (reportFormat.equals("csv")) {
 73  1 return new CSVRenderer();
 74  4 } else if (reportFormat.equals("html")) {
 75  1 return new HTMLRenderer();
 76  3 } else if (reportFormat.equals("yahtml")) {
 77  0 return new YAHTMLRenderer();
 78  3 } else if (reportFormat.equals("summaryhtml")) {
 79  0 return new SummaryHTMLRenderer();
 80  3 } else if (reportFormat.equals("vbhtml")) {
 81  1 return new VBHTMLRenderer();
 82    }
 83  2 if (!reportFormat.equals("")) {
 84  1 try {
 85  1 return (Renderer) Class.forName(reportFormat).newInstance();
 86    } catch (Exception e) {
 87  1 throw new IllegalArgumentException("Can't find the custom format " + reportFormat + ": " + e.getClass().getName());
 88    }
 89    }
 90   
 91  1 throw new IllegalArgumentException("Can't create report with format of " + reportFormat);
 92    }
 93   
 94  1 public boolean containsCommaSeparatedFileList() {
 95  1 return inputPath.indexOf(',') != -1;
 96    }
 97   
 98  1 public String getInputPath() {
 99  1 return this.inputPath;
 100    }
 101   
 102  2 public String getEncoding() {
 103  2 return this.encoding;
 104    }
 105   
 106  1 public String getReportFormat() {
 107  1 return this.reportFormat;
 108    }
 109   
 110  1 public String getRulesets() {
 111  1 return this.ruleSets;
 112    }
 113   
 114  1 public String getExcludeMarker() {
 115  1 return this.excludeMarker;
 116    }
 117   
 118  1 public boolean debugEnabled() {
 119  1 return debugEnabled;
 120    }
 121   
 122  3 public String getTargetJDK() {
 123  3 return targetJDK;
 124    }
 125   
 126  1 public boolean shortNamesEnabled() {
 127  1 return shortNamesEnabled;
 128    }
 129   
 130  2 public String usage() {
 131  2 return PMD.EOL + PMD.EOL +
 132    "Mandatory arguments:" + PMD.EOL +
 133    "1) A java source code filename or directory" + PMD.EOL +
 134    "2) A report format " + PMD.EOL +
 135    "3) A ruleset filename or a comma-delimited string of ruleset filenames" + PMD.EOL +
 136    PMD.EOL +
 137    "For example: " + PMD.EOL +
 138    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code html unusedcode" + PMD.EOL +
 139    PMD.EOL +
 140    "Optional arguments that may be put after the mandatory arguments are: " + PMD.EOL +
 141    "-debug: prints debugging information " + PMD.EOL +
 142    "-targetjdk: specifies a language version to target - 1.3, 1.4, or 1.5" + PMD.EOL +
 143    "-encoding: specifies the character set encoding of the source code files PMD is reading (i.e., UTF-8)" + PMD.EOL +
 144    "-excludemarker: specifies the String that marks the a line which PMD should ignore; default is NOPMD" + PMD.EOL +
 145    "-shortnames: prints shortened filenames in the report" + PMD.EOL +
 146    PMD.EOL +
 147    "For example: " + PMD.EOL +
 148    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code text unusedcode,imports -targetjdk 1.5 -debug" + PMD.EOL +
 149    "c:\\> java -jar pmd-" + PMD.VERSION + ".jar c:\\my\\source\\code xml basic,design -encoding UTF-8" + PMD.EOL +
 150    PMD.EOL;
 151    }
 152    }
 153   
 154