/testability-explorer/src/main/java/com/google/test/metric/report/PropertiesReportGenerator.java
Java | 60 lines | 27 code | 9 blank | 24 comment | 0 complexity | bf6162837c862648373c30f77470a215 MD5 | raw file
1/* 2 * Copyright 2007 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.report; 17 18import java.io.IOException; 19import java.io.OutputStream; 20import java.util.Properties; 21 22import com.google.test.metric.ClassCost; 23import com.google.test.metric.CostModel; 24 25/** 26 * Write out the classes and their metrics in a Java properties file format. 27 * @author alexeagle@google.com (Alex Eagle) 28 * 29 */ 30public class PropertiesReportGenerator implements ReportGenerator { 31 32 private final Properties properties = new Properties(); 33 private final OutputStream out; 34 private final CostModel costModel; 35 36 /** 37 * @param out where the report should be written 38 */ 39 public PropertiesReportGenerator(OutputStream out, CostModel costModel) { 40 this.out = out; 41 this.costModel = costModel; 42 } 43 44 public void addClassCost(ClassCost classCost) { 45 properties.setProperty(classCost.getClassName(), String.valueOf(costModel.computeClass(classCost))); 46 } 47 48 public void printFooter() { 49 try { 50 properties.store(out, "Metrics generated by Testability Explorer"); 51 } catch (IOException e) { 52 throw new RuntimeException(e); 53 } 54 } 55 56 public void printHeader() { 57 // Nothing to do 58 } 59 60}