<commit_before>package org.pescuma.buildhealth.extractor.staticanalysis.console;

import static org.pescuma.buildhealth.extractor.utils.FilenameToLanguage.*;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.LineRange;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.warnings.parser.AbstractWarningsParser;
import hudson.plugins.warnings.parser.ParsingCanceledException;

import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.HashSet;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.pescuma.buildhealth.core.BuildData;
import org.pescuma.buildhealth.utils.Location;

class WarningsHelper {
	
	static void extractFromParser(String name, AbstractWarningsParser parser, Reader input, BuildData data)
			throws IOException, ParsingCanceledException {
		Collection<FileAnnotation> anns = parser.parse(input);
		
		// Remove dups
		anns = new HashSet<FileAnnotation>(anns);
		
		for (FileAnnotation ann : anns) {
			LineRange r = ann.getLineRanges().iterator().next();
			Location loc = Location.create(ann.getFileName(), r.getStart(), ann.getColumnStart(), r.getEnd(),
					ann.getColumnEnd());
			
			String category = (ann.getPriority() == Priority.HIGH ? "Compiler errors" : "Compiler warnings");
			
			if (!StringUtils.isBlank(ann.getCategory()))
				category += "/" + ann.getCategory().replace('\\', '/');
			
			String message = unescapeHTML(ann.getMessage());
			
			data.add(1, "Static analysis", detectLanguage(ann.getFileName()), name, Location.toFormatedString(loc),
					category, message, toSeverity(ann.getPriority()));
		}
	}
	
	private static String unescapeHTML(String message) {
		return StringEscapeUtils.unescapeHtml(message).replace("&apos;", "'");
	}
	
	private static String toSeverity(Priority priority) {
		switch (priority) {
			case HIGH:
				return "High";
			case NORMAL:
				return "Medium";
			case LOW:
				return "Low";
			default:<commit_msg>WarningsHelper: try to fix path separator<commit_after>package org.pescuma.buildhealth.extractor.staticanalysis.console;

import static org.pescuma.buildhealth.extractor.utils.FilenameToLanguage.*;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.analysis.util.model.LineRange;
import hudson.plugins.analysis.util.model.Priority;
import hudson.plugins.warnings.parser.AbstractWarningsParser;
import hudson.plugins.warnings.parser.ParsingCanceledException;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import java.util.HashSet;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.pescuma.buildhealth.core.BuildData;
import org.pescuma.buildhealth.utils.Location;

class WarningsHelper {
	
	static void extractFromParser(String name, AbstractWarningsParser parser, Reader input, BuildData data)
			throws IOException, ParsingCanceledException {
		Collection<FileAnnotation> anns = parser.parse(input);
		
		// Remove dups
		anns = new HashSet<FileAnnotation>(anns);
		
		for (FileAnnotation ann : anns) {
			LineRange r = ann.getLineRanges().iterator().next();
			String fileName = ann.getFileName().replace('/', File.separatorChar);
			
			Location loc = Location
					.create(fileName, r.getStart(), ann.getColumnStart(), r.getEnd(), ann.getColumnEnd());
			
			String category = (ann.getPriority() == Priority.HIGH ? "Compiler errors" : "Compiler warnings");
			
			if (!StringUtils.isBlank(ann.getCategory()))
				category += "/" + ann.getCategory().replace('\\', '/');
			
			String message = unescapeHTML(ann.getMessage());
			
			data.add(1, "Static analysis", detectLanguage(fileName), name, Location.toFormatedString(loc), category,
					message, toSeverity(ann.getPriority()));
		}
	}
	
	private static String unescapeHTML(String message) {
		return StringEscapeUtils.unescapeHtml(message).replace("&apos;", "'");
	}
	
	private static String toSeverity(Priority priority) {
		switch (priority) {
			case HIGH:
				return "High";
			case NORMAL:
				return "Medium";
			case LOW:
				return "Low";
			default:
{'fraction_non_alphanumeric': 0.12526741145709533, 'fraction_numerical': 0.0004753981459472308, 'mean_word_length': 4.9687943262411345, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4560970', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1242, 'n_words': 249}