1 package com.stateofflow.eclipse.metrics.export.html;
2
3 import java.io.IOException;
4
5 import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
6 import com.stateofflow.eclipse.metrics.collator.MetricsCollatorSet;
7 import com.stateofflow.eclipse.metrics.export.Exporter;
8 import com.stateofflow.eclipse.metrics.util.ProgressMonitor;
9
10 public final class HtmlExporter implements Exporter {
11 public static final String QUALIFIED_TYPE_NAME_PAGE_NAME_START = "QualifiedTypeName.";
12 public static final String UNQUALIFIED_TYPE_NAME_PAGE_NAME_START = "UnqualifiedTypeName.";
13 public static final String DASHBOARD_FILE_NAME = "dashboard";
14
15 public static final String PROJECT_METRIC_LEVEL = "Project";
16 public static final String METHOD_METRIC_LEVEL = "Method";
17 public static final String TYPE_METRIC_LEVEL = "Type";
18 public static final String PACKAGE_METRIC_LEVEL = "Package";
19
20 private final HtmlExportFactory factory;
21 private MetricsCollatorSet collatorSet;
22
23 HtmlExporter(final HtmlExportFactory factory) {
24 this.factory = factory;
25 }
26
27 private void export(final ProgressMonitor progressMonitor) throws IOException {
28 progressMonitor.beginTask("Exporting", 6);
29 collatorSet.aggregate(progressMonitor.newChild(1));
30
31 final MetricsPagesWriter metricsPagesWriter = factory.createMetricsPagesWriter();
32 metricsPagesWriter.writeTypeAndMethodMetricsPages(getMethodMetricsCollator(), HtmlExporter.METHOD_METRIC_LEVEL, progressMonitor.newChild(1));
33 metricsPagesWriter.writeTypeAndMethodMetricsPages(getTypeMetricsCollator(), HtmlExporter.TYPE_METRIC_LEVEL, progressMonitor.newChild(1));
34 metricsPagesWriter.writePackageMetricsPages(collatorSet.getPackageMetrics(), progressMonitor.newChild(1));
35 metricsPagesWriter.writeProjectMetricsPage(collatorSet, progressMonitor.newChild(1));
36
37 factory.createIndexPageWriter().write(collatorSet, progressMonitor.newChild(1));
38 }
39
40 public void export(final MetricsCollator typeMetrics, final MetricsCollator methodMetrics, final ProgressMonitor monitor) throws Exception {
41 collatorSet = new MetricsCollatorSet(methodMetrics, typeMetrics, new MetricsCollator(factory.getPresentations()));
42
43 monitor.beginTask("Exporting Metrics HTML", 3);
44 factory.createImageAndDashboardWriter(collatorSet).run(monitor.newChild(1));
45 factory.createJavaWriter().run(monitor.newChild(1));
46 export(monitor.newChild(1));
47 }
48
49 private MetricsCollator getMethodMetricsCollator() {
50 return collatorSet.getMethodMetrics();
51 }
52
53 private MetricsCollator getTypeMetricsCollator() {
54 return collatorSet.getTypeMetrics();
55 }
56 }
57