<commit_before>package hudson.plugins.warnings.parser.jcreportparser;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import hudson.Extension;

import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.warnings.parser.AbstractWarningsParser;
import hudson.plugins.warnings.parser.Messages;
import hudson.plugins.warnings.parser.ParsingCanceledException;
import hudson.plugins.warnings.parser.Warning;

import hudson.util.IOException2;

/**
 * JcReportParser-Class. This class parses from the jcReport.xml and creates warnings from its content.
 *
 * @author <NAME>, <EMAIL>
 */
@Extension
public class JcReportParser extends AbstractWarningsParser {

    /**
     * Generated document field serialVersionUID.
     */
    private static final long serialVersionUID = -1302787609831475403L;

    /**
     * Creates a new instance of JcReportParser.
     *
     * @author <NAME>, <EMAIL>
     * @NOTE: Only the Super-Constructor is called with 3 Localizables.
     */
    public JcReportParser() {
        super(Messages._Warnings_JCReport_ParserName(), Messages._Warnings_JCReport_LinkName(), Messages
                ._Warnings_JCReport_TrendName());
    }

    /**
     * Inherited from the super-class.
     *
     * @author <NAME>, <EMAIL> This overwritten method passes the reader to createReport()
     *         and starts adding all the warnings to the Collection that will be returned at the end of the method.
     * @return warnings -> the collection of Warnings parsed from the Report.
     * @param reader
     *            -> the reader that parses from the source-file.
     * @exception IOException
     *                -> thrown by createReport()
     * @exception ParsingCanceledException
     *                -> thrown by createReport()
     */
    @Override
    public Collection<FileAnnotation> parse(final Reader reader) throws IOException, ParsingCanceledException {
        final Report report = createReport(reader);
        List<FileAnnotation> warnings = new ArrayList<FileAnnotation>();

        for (int i = 0; i < report.getFiles().size(); i++) {

            final File file = report.getFiles().get(i);

            for (int j = 0; j < file.getItems().size(); j++) {
                final Item item = file.getItems().get(j);
                final Warning warning = createWarning(file.getName(), getLineNumber(item.getLine()),
                        item.getFindingtype(), item.getMessage(), getPriority(item.getSeverity()));

                warning.setOrigin(item.getOrigin());
                warning.setPackageName(file.getPackageName());
                warning.setPathName(file.getSrcdir());
                warning.setColumnPosition(getLineNumber(item.getColumn()), getLineNumber(item.getEndcolumn()));
                warnings.add(warning);
            }
        }
        return warnings;
    }

    /**
     * The severity-level parsed from the JcReport will be matched with a priority.
     *
     * @author <NAME>, <EMAIL>
     * @return priority -> the priority-enum matching with the issueLevel.
     * @param issueLevel
     *            -> the severity-level parsed from the JcReport.
     */
    private Priority getPriority(final String issueLevel) {

        if (issueLevel == null || issueLevel.isEmpty()) {
            return Priority.HIGH;
        }

        if (issueLevel.contains("CriticalError")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("Error")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("CriticalWarning")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("Warning")) {
            return Priority.NORMAL;
        }
        else {
            return Priority.LOW;
        }

    }
<commit_msg>issueLevel.isEmpty replaced with Stringutils.isEmtpy(issueLevel).<commit_after>package hudson.plugins.warnings.parser.jcreportparser;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.digester3.Digester;
import org.apache.commons.digester3.binder.DigesterLoader;
import org.apache.commons.lang.StringUtils;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import hudson.Extension;

import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.warnings.parser.AbstractWarningsParser;
import hudson.plugins.warnings.parser.Messages;
import hudson.plugins.warnings.parser.ParsingCanceledException;
import hudson.plugins.warnings.parser.Warning;

import hudson.util.IOException2;

/**
 * JcReportParser-Class. This class parses from the jcReport.xml and creates warnings from its content.
 *
 * @author <NAME>, <EMAIL>
 */
@Extension
public class JcReportParser extends AbstractWarningsParser {

    /**
     * Generated document field serialVersionUID.
     */
    private static final long serialVersionUID = -1302787609831475403L;

    /**
     * Creates a new instance of JcReportParser.
     *
     * @author <NAME>, <EMAIL>
     * @NOTE: Only the Super-Constructor is called with 3 Localizables.
     */
    public JcReportParser() {
        super(Messages._Warnings_JCReport_ParserName(), Messages._Warnings_JCReport_LinkName(), Messages
                ._Warnings_JCReport_TrendName());
    }

    /**
     * Inherited from the super-class.
     *
     * @author <NAME>, <EMAIL> This overwritten method passes the reader to createReport()
     *         and starts adding all the warnings to the Collection that will be returned at the end of the method.
     * @return warnings -> the collection of Warnings parsed from the Report.
     * @param reader
     *            -> the reader that parses from the source-file.
     * @exception IOException
     *                -> thrown by createReport()
     * @exception ParsingCanceledException
     *                -> thrown by createReport()
     */
    @Override
    public Collection<FileAnnotation> parse(final Reader reader) throws IOException, ParsingCanceledException {
        final Report report = createReport(reader);
        List<FileAnnotation> warnings = new ArrayList<FileAnnotation>();

        for (int i = 0; i < report.getFiles().size(); i++) {

            final File file = report.getFiles().get(i);

            for (int j = 0; j < file.getItems().size(); j++) {
                final Item item = file.getItems().get(j);
                final Warning warning = createWarning(file.getName(), getLineNumber(item.getLine()),
                        item.getFindingtype(), item.getMessage(), getPriority(item.getSeverity()));

                warning.setOrigin(item.getOrigin());
                warning.setPackageName(file.getPackageName());
                warning.setPathName(file.getSrcdir());
                warning.setColumnPosition(getLineNumber(item.getColumn()), getLineNumber(item.getEndcolumn()));
                warnings.add(warning);
            }
        }
        return warnings;
    }

    /**
     * The severity-level parsed from the JcReport will be matched with a priority.
     *
     * @author <NAME>, <EMAIL>
     * @return priority -> the priority-enum matching with the issueLevel.
     * @param issueLevel
     *            -> the severity-level parsed from the JcReport.
     */
    private Priority getPriority(final String issueLevel) {

        if (issueLevel == null || StringUtils.isEmpty(issueLevel)) {
            return Priority.HIGH;
        }

        if (issueLevel.contains("CriticalError")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("Error")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("CriticalWarning")) {
            return Priority.HIGH;
        }
        else if (issueLevel.contains("Warning")) {
            return Priority.NORMAL;
        }
        else {
            return Priority.LOW;
        }

    }

{'fraction_non_alphanumeric': 0.10304562417238473, 'fraction_numerical': 0.006019020103527146, 'mean_word_length': 2.6074685193226226, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772714', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2216, 'n_words': 553}