CsvFormatter.java
1/*******************************************************************************
2 * Copyright (c) 2009 Mountainminds GmbH & Co. KG and others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Brock Janiczak - initial API and implementation
10 *
11 * $Id: $
12 *******************************************************************************/
13package org.jacoco.report.csv;
14
15import java.io.IOException;
16
17import org.jacoco.core.analysis.ICoverageNode;
18import org.jacoco.report.ILanguageNames;
19import org.jacoco.report.IReportFormatter;
20import org.jacoco.report.IReportVisitor;
21import org.jacoco.report.ISingleReportOutput;
22import org.jacoco.report.JavaNames;
23
24/**
25 * Report formatter that will create a single CSV file. By default the filename
26 * used will be the name of the session.
27 *
28 * @author Brock Janiczak
29 * @version $Revision: $
30 */
31public class CsvFormatter implements IReportFormatter {
32
33 private ISingleReportOutput output;
34
35 private ILanguageNames languageNames = new JavaNames();
36
37 private String outputEncoding = "UTF-8";
38
39 public IReportVisitor createReportVisitor(final ICoverageNode session)
40 throws IOException {
41
42 if (output == null) {
43 throw new IllegalStateException("No report output set.");
44 }
45
46 return new CsvReportFile(languageNames, output.createFile(),
47 outputEncoding);
48 }
49
50 /**
51 * Sets the report output callback for this report formatter. This is a
52 * mandatory property.
53 *
54 * @param output
55 * file output
56 */
57 public void setReportOutput(final ISingleReportOutput output) {
58 this.output = output;
59 }
60
61 /**
62 * Sets the implementation for language name display. Java language names
63 * are defined by default.
64 *
65 * @param languageNames
66 * converter for language specific names
67 */
68 public void setLanguageNames(final ILanguageNames languageNames) {
69 this.languageNames = languageNames;
70 }
71
72 /**
73 * Returns the language names call-back used in this report.
74 *
75 * @return language names
76 */
77 public ILanguageNames getLanguageNames() {
78 return languageNames;
79 }
80
81 /**
82 * Sets the encoding used for generated CSV document. Default is UTF-8.
83 *
84 * @param outputEncoding
85 * CSV output encoding
86 */
87 public void setOutputEncoding(final String outputEncoding) {
88 this.outputEncoding = outputEncoding;
89 }
90
91}