1 package com.stateofflow.eclipse.metrics.export.csv;
2
3 import java.io.File;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.io.PrintWriter;
7
8 import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
9 import com.stateofflow.eclipse.metrics.configuration.MetricPresentations;
10 import com.stateofflow.eclipse.metrics.metric.MetricId;
11
12 final class MetricsWriter {
13 public static MetricsWriter createMethodInstance(final MetricPresentations presentations) {
14 return new MetricsWriter("methods.csv", "PACKAGE,TYPE,METHOD,LINE", presentations);
15 }
16
17 public static MetricsWriter createTypeInstance(final MetricPresentations presentations) {
18 return new MetricsWriter("types.csv", "PACKAGE,TYPE,LINE", presentations);
19 }
20
21 private final String fileName;
22 private final HeaderWriter headerWriter;
23
24 private MetricsWriter(final String fileName, final String identifyingColumns, final MetricPresentations presentations) {
25 this.fileName = fileName;
26 headerWriter = new HeaderWriter(identifyingColumns, presentations);
27 }
28
29 public void write(final File directory, final MetricsCollator collator) throws IOException {
30 final PrintWriter writer = new PrintWriter(new FileWriter(new File(directory, fileName)));
31 final MetricId[] metricIds = collator.getMetricIds();
32 headerWriter.write(writer, metricIds);
33 new BodyWriter().write(writer, metricIds, collator);
34 writer.close();
35 }
36 }
37