Skip to content

Commit

Permalink
(Update-fix) cnescatlab#69 CSV export improvement
Browse files Browse the repository at this point in the history
+ New columns (language & message)
+ String [--] was removed in Values column when a violation has no value
and replaced by an empty string.
+ information on file are being displayed only when the checker has a
value
+ separator which was [,] was edited to be a tab [\t] as some message
contains commas.
  • Loading branch information
Omar Waldmann committed Sep 11, 2017
1 parent b79d358 commit c53c277
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

/**
* This class is an attribute of the {@code ExtensionPoint} implementing
* {@link IExporter} interface of the plugin <i>fr.cnes.analysis.tools.export</i>.
* {@link IExporter} interface of the plugin
* <i>fr.cnes.analysis.tools.export</i>.
* <p>
* This class is also exported in the <i>fr.cnes.analysis.tools.export.csv</i>
* plugin and could be used as a service from any third.
Expand All @@ -31,7 +32,9 @@
public class ExporterCsv implements IExporter {

/** Field separator */
private static final String SEPARATOR = ",";
private static final String SEPARATOR = "\t";
/** Field separator */
private static final String BLANK = "\n";

/**
* Default constructor. Required to execute a class from the contributed
Expand All @@ -50,19 +53,34 @@ public ExporterCsv() {
public void export(List<CheckResult> checkResults, File outputFile,
Map<String, String> parameters) throws IOException {
try (final FileWriter writer = new FileWriter(outputFile)) {
writer.write("Rule, File, Location, Line, Value\n");
writer.write("Rule" + SEPARATOR + "File" + SEPARATOR + "Location" + SEPARATOR + "Line"
+ SEPARATOR + "Message" + SEPARATOR + "Language" + SEPARATOR
+ "Value\n");
for (final CheckResult checkResult : checkResults) {
if (checkResult.getValue() != null) {
writer.write(checkResult.getName() + SEPARATOR
+ checkResult.getFile().getAbsolutePath() + SEPARATOR
+ checkResult.getLocation() + SEPARATOR
+ checkResult.getLine().toString() + SEPARATOR
+ checkResult.getValue() + "\n");
} else {
writer.write(checkResult.getName() + SEPARATOR
+ checkResult.getFile().getAbsolutePath() + SEPARATOR
+ checkResult.getLocation() + SEPARATOR
+ checkResult.getLine().toString() + ", -- \n");
if (checkResult.getLocation() != null || checkResult.getValue() != null) {
if (checkResult.getLocation() == null) {
writer.write(checkResult.getName() + SEPARATOR
+ checkResult.getFile().getAbsolutePath() + SEPARATOR + ""
+ SEPARATOR + checkResult.getLine().toString() + SEPARATOR
+ checkResult.getLangageId() + SEPARATOR + "" + SEPARATOR
+ checkResult.getValue() + BLANK);
} else if (checkResult.getValue() != null) {
writer.write(checkResult.getName() + SEPARATOR
+ checkResult.getFile().getAbsolutePath() + SEPARATOR + ""
+ SEPARATOR + checkResult.getLine().toString() + SEPARATOR
+ checkResult.getLangageId() + SEPARATOR + "" + SEPARATOR
+ checkResult.getValue() + BLANK);
} else {
writer.write(checkResult.getName() + SEPARATOR
+ checkResult.getFile().getAbsolutePath() + SEPARATOR
+ checkResult.getLocation() + SEPARATOR
+ checkResult.getLine().toString() + SEPARATOR
+ checkResult.getLangageId() + SEPARATOR
+ checkResult.getMessage().toString()
.replaceAll(SEPARATOR, "")
.replaceAll(BLANK, "")
+ SEPARATOR + "" + BLANK);
}
}
}
}
Expand Down

0 comments on commit c53c277

Please sign in to comment.