<commit_before>/************************************************************************************************/
/* i-Code CNES is a static code analyzer. */
/* This software is a free software, under the terms of the Eclipse Public License version 1.0. */
/* http://www.eclipse.org/legal/epl-v10.html */
/************************************************************************************************/
package fr.cnes.analysis.tools.export.csv;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.export.IExporter;

/**
 * This class is an attribute of the {@code ExtensionPoint} implementing
 * {@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.
 * </p>
 * <p>
 * This class is responsible of the export in the format CSV of
 * {@link CheckResult} elements into a {@link File}.
 * </p>
 * 
 * @since 3.0
 */
public class ExporterCsv implements IExporter {

    /** Field 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
     * extension point.
     */
    public ExporterCsv() {
    }

    /*
     * (non-Javadoc)
     * 
     * @see fr.cnes.analysis.tools.export.IExport#export(java.util.List,
     * java.io.File)
     */
    @Override
    public void export(List<CheckResult> checkResults, File outputFile,
                    Map<String, String> parameters) throws IOException {
        try (final FileWriter writer = new FileWriter(outputFile)) {
            writer.write("Rule" + SEPARATOR + "File" + SEPARATOR + "Location" + SEPARATOR + "Line"
                            + SEPARATOR + "Message" + SEPARATOR + "Language" + SEPARATOR
                            + "Value\n");
            for (final CheckResult checkResult : checkResults) {
                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);
                    }
                }
            }
        }
<commit_msg>Fix #96 Columns names correction<commit_after>/************************************************************************************************/
/* i-Code CNES is a static code analyzer. */
/* This software is a free software, under the terms of the Eclipse Public License version 1.0. */
/* http://www.eclipse.org/legal/epl-v10.html */
/************************************************************************************************/
package fr.cnes.analysis.tools.export.csv;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import fr.cnes.analysis.tools.analyzer.datas.CheckResult;
import fr.cnes.analysis.tools.export.IExporter;

/**
 * This class is an attribute of the {@code ExtensionPoint} implementing
 * {@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.
 * </p>
 * <p>
 * This class is responsible of the export in the format CSV of
 * {@link CheckResult} elements into a {@link File}.
 * </p>
 * 
 * @since 3.0
 */
public class ExporterCsv implements IExporter {

    /** Field 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
     * extension point.
     */
    public ExporterCsv() {
    }

    /*
     * (non-Javadoc)
     * 
     * @see fr.cnes.analysis.tools.export.IExport#export(java.util.List,
     * java.io.File)
     */
    @Override
    public void export(List<CheckResult> checkResults, File outputFile,
                    Map<String, String> parameters) throws IOException {
        try (final FileWriter writer = new FileWriter(outputFile)) {
            writer.write("Rule" + SEPARATOR + "File" + SEPARATOR + "Location" + SEPARATOR + "Line"
                            + SEPARATOR + "Language" + SEPARATOR + "Message" + SEPARATOR + "Value"
                            + BLANK);
            for (final CheckResult checkResult : checkResults) {
                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);
                    }
                }
            }
        }

{'fraction_non_alphanumeric': 0.15000610277065787, 'fraction_numerical': 0.0017087757842060296, 'mean_word_length': 1.6262820512820513, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3961105', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1870, 'n_words': 463}