PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/main/java/com/google/test/metric/CommandLineConfig.java

http://testability-explorer.googlecode.com/
Java | 132 lines | 87 code | 23 blank | 22 comment | 5 complexity | a45706ed950c2f7259109a1864ee9991 MD5 | raw file
  1/*
  2 * Copyright 2009 Google Inc.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 * use this file except in compliance with the License. You may obtain a copy of
  6 * the License at
  7 *
  8 * http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 13 * License for the specific language governing permissions and limitations under
 14 * the License.
 15 */
 16package com.google.test.metric;
 17
 18import com.google.inject.Inject;
 19import com.google.test.metric.ConfigModule.Error;
 20import com.google.test.metric.ConfigModule.Output;
 21import com.google.test.metric.ReportGeneratorProvider.ReportFormat;
 22
 23import org.kohsuke.args4j.Argument;
 24import org.kohsuke.args4j.CmdLineException;
 25import org.kohsuke.args4j.Option;
 26
 27import java.io.PrintStream;
 28import java.util.ArrayList;
 29import java.util.List;
 30
 31/**
 32 * Holds fields that Args4J sets by parsing the command line options. After the args are parsed,
 33 * build a TestabilityConfig.
 34 *
 35 * @author Jonathan Andrew Wolter <jaw@jawspeak.com>
 36 */
 37public class CommandLineConfig {
 38
 39  @Option(name = "-cp", usage = "colon delimited classpath to analyze (jars or directories)"
 40      + "\nEx. lib/one.jar:lib/two.jar")
 41  protected String cp;
 42
 43  @Option(name = "-printDepth", usage = "Maximum depth to recurse and print costs of classes/methods "
 44      + "that the classes under analysis depend on. Defaults to 0.")
 45  int printDepth = 2;
 46
 47  @Option(name = "-minCost", usage = "Minimum Total Class cost required to print that class' metrics.")
 48  int minCost = 1;
 49
 50  @Option(name = "-maxExcellentCost", usage = "Maximum Total Class cost to be classify it as 'excellent'.")
 51  int maxExcellentCost = 50;
 52
 53  @Option(name = "-worstOffenderCount", usage = "Print N number of worst offending classes.")
 54  public int worstOffenderCount = 20;
 55
 56  @Option(name = "-maxAcceptableCost", usage = "Maximum Total Class cost to be classify it as 'acceptable'.")
 57  int maxAcceptableCost = 100;
 58
 59  @Option(name = "-whitelist", usage = "colon delimited whitelisted packages that will not "
 60      + "count against you. Matches packages/classes starting with "
 61      + "given values. (Always whitelists java.*. RegExp OK.)")
 62  String wl = null;
 63
 64  @Option(name = "-print", usage = "summary: (default) print package summary information.\n"
 65      + "html: print package summary information in html format.\n"
 66      + "source: write out annotated source into directory.\n"
 67      + "detail: print detail drill down information for each method call. (DEPRECATED)\n"
 68      + "xml: print computer readable XML format.")
 69  String printer = "summary";
 70
 71  @Option(name = "-srcFileLineUrl", usage = "template for urls linking to a specific LINE in a file in a web "
 72      + "source code repository.\n"
 73      + "Ex. -srcFileLineUrl http://code.repository/basepath/{path}&line={line}\n"
 74      + "Ex. -srcFileLineUrl http://code.google.com/p/testability-explorer/source/browse/trunk/src/{path}#{line}")
 75  String srcFileLineUrl = "";
 76
 77  @Option(name = "-srcFileUrl", usage = "template for urls linking to a file in a web source code "
 78      + "repository.\nEx. -srcFileUrl http://code.repository/basepath/{path}\n"
 79      + "Ex. -srcFileUrl http://code.google.com/p/testability-explorer/source/browse/trunk/src/{path}")
 80  String srcFileUrl = "";
 81
 82  // TODO(alexeagle): this parameter is no longer used
 83  @Option(name = "-maxMethodCount", usage = "max number of methods to print in html summary")
 84  int maxMethodCount = 10;
 85
 86  @Option(name = "-maxLineCount", usage = "max number of lines in method to print in html summary")
 87  int maxLineCount = 10;
 88
 89  @Option(name = "-cyclomatic", metaVar = "cyclomatic cost multiplier", usage = "When computing the overall cost of the method the "
 90      + "individual costs are added using weighted average. "
 91      + "This represents the weight of the cyclomatic cost.")
 92  double cyclomaticMultiplier = 1;
 93
 94  @Option(name = "-global", metaVar = "global state cost multiplier", usage = "When computing the overall cost of the method the "
 95      + "individual costs are added using weighted average. "
 96      + "This represents the weight of the global state cost.")
 97  double globalMultiplier = 10;
 98
 99  @Option(name = "-constructor", metaVar = "work in constructor multiplier", usage = "Additional multiplier on costs that are incurred in a constructor")
100  double constructorMultiplier = 1;
101
102  @Argument(metaVar = "classes and packages to analyze", usage = "Classes or packages to analyze. "
103      + "Matches any class starting with these.\n"
104      + "Ex. com.example.analyze.these com.google.and.these.packages " + "com.google.AClass")
105  List<String> entryList = new ArrayList<String>();
106  ReportFormat format;
107
108  PrintStream out;
109  PrintStream err;
110
111  @Inject
112  public CommandLineConfig(@Output PrintStream out, @Error PrintStream err) {
113    this.out = out;
114    this.err = err;
115  }
116
117  public void validate() throws CmdLineException {
118    if (cp == null && entryList.isEmpty()) {
119      throw new CmdLineException("You must supply either the -cp flag, " +
120          "or the argument \"classes and packages to analyze\".");
121    }
122    cp = (cp != null ? cp : System.getProperty("java.class.path", "."));
123    if (entryList.isEmpty()) {
124      entryList.add(".");
125    }
126    try {
127      format = ReportFormat.valueOf(printer);
128    } catch (IllegalArgumentException e) {
129      throw new CmdLineException("Don't understand '-print' option '" + printer + "'");
130    }
131  }
132}