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

http://testability-explorer.googlecode.com/ · Java · 107 lines · 64 code · 13 blank · 30 comment · 6 complexity · 450d2c83fa730a54cd9697b7c5409b6d 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.AbstractModule;
  18. import com.google.inject.Inject;
  19. import com.google.inject.Provides;
  20. import com.google.test.metric.ReportGeneratorProvider.ReportFormat;
  21. import java.io.PrintStream;
  22. import java.util.List;
  23. /**
  24. * Module which provides the simple configuration needed to make Testability Explorer reports.
  25. *
  26. * Contrast this class with the CommandLineConfiguration class which takes simple strings (from the
  27. * command line), and then parses it into this TestabilityConfiguration, for use by the
  28. * TestabilityRunner.
  29. * @author Jonathan Andrew Wolter <jaw@jawspeak.com>
  30. */
  31. public class JavaTestabilityModule extends AbstractModule {
  32. private final List<String> entryList;
  33. private final PrintStream err;
  34. private final int printDepth;
  35. private final ReportFormat format;
  36. @Inject
  37. public JavaTestabilityModule(CommandLineConfig config) {
  38. entryList = config.entryList;
  39. err = config.err;
  40. format = config.format;
  41. printDepth = config.printDepth;
  42. convertEntryListValues();
  43. }
  44. public JavaTestabilityModule(List<String> entryList,
  45. PrintStream err, int printDepth, ReportFormat format) {
  46. this.entryList = entryList;
  47. this.err = err;
  48. this.printDepth = printDepth;
  49. this.format = format;
  50. }
  51. public List<String> getEntryList() {
  52. return entryList;
  53. }
  54. public PrintStream getErr() {
  55. return err;
  56. }
  57. public int getPrintDepth() {
  58. return printDepth;
  59. }
  60. public ReportFormat getFormat() {
  61. return format;
  62. }
  63. @Override
  64. protected void configure() {
  65. }
  66. @Provides WhiteList getWhiteList(CommandLineConfig config) {
  67. RegExpWhiteList regExpWhitelist = new RegExpWhiteList("java.");
  68. regExpWhitelist.addPackage("javax.");
  69. for (String packageName : config.wl == null ? new String[] {} : config.wl.split("[,:]")) {
  70. regExpWhitelist.addPackage(packageName);
  71. }
  72. return regExpWhitelist;
  73. }
  74. /*
  75. * Converts entryList class and package values into paths by replacing any "." with a "/" Also
  76. * checks for entries that contain multiple values separated by a space (" "), and splits them out
  77. * into separate entries. This may happen when main() is called explicitly from another class,
  78. * such as the {@link com.google.ant.TestabilityTask}
  79. */
  80. // TODO(jwolter) can we remove this now that there is a convenient programmatic API.
  81. private void convertEntryListValues() {
  82. for (int i = 0; i < entryList.size(); i++) {
  83. if (entryList.get(i).contains(" ")) {
  84. String[] entries = entryList.get(i).split(" ");
  85. entryList.set(i, entries[0].replaceAll("/", "."));
  86. for (int j = 1; j < entries.length; j++) {
  87. entryList.add(entries[j].replaceAll("/", "."));
  88. }
  89. } else {
  90. entryList.set(i, entryList.get(i).replaceAll("/", "."));
  91. }
  92. }
  93. }
  94. }