PageRenderTime 38ms CodeModel.GetById 14ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

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