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