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