use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.
the class FxCopParser method parseIssue.
private void parseIssue(Element issue, Element parent, String parentName, String subName) {
// Path, File, Line, Level
String typeName = getString(parent, "TypeName");
String category = getString(parent, "Category");
String checkId = getString(parent, "CheckId");
Violation violation = new Violation();
violation.setType("fxcop");
violation.setSource(category + "#" + checkId);
setSeverityLevel(violation, getString(issue, "Level"));
StringBuilder msgBuilder = new StringBuilder();
if (subName != null) {
msgBuilder.append(subName);
msgBuilder.append(" ");
}
FxCopRule rule = ruleSet.getRule(category, checkId);
if (rule != null) {
msgBuilder.append("<a href=\"");
msgBuilder.append(rule.getUrl());
msgBuilder.append("\">");
msgBuilder.append(typeName);
msgBuilder.append("</a>");
violation.setPopupMessage(rule.getDescription());
} else {
msgBuilder.append(typeName);
}
msgBuilder.append(" - ");
msgBuilder.append(issue.getTextContent());
violation.setMessage(msgBuilder.toString());
String filePath = getString(issue, "Path");
String fileName = getString(issue, "File");
String fileLine = getString(issue, "Line");
FullFileModel fileModel;
if ((filePath.length() > 0) && (fileName.length() > 0) && (fileLine.length() > 0)) {
violation.setLine(fileLine);
// fileModel = model.getFileModel(filePath.substring(2) + "/" + fileName);
fileModel = model.getFileModel(resolveName(filePath + File.separatorChar + fileName));
if (fileModel.getSourceFile() == null) {
File sourceFile = new File(filePath, fileName);
if (sourceFile.exists()) {
fileModel.setSourceFile(sourceFile);
fileModel.setLastModified(sourceFile.lastModified());
}
}
} else {
fileModel = model.getFileModel(parentName);
}
fileModel.addViolation(violation);
}
use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.
the class GendarmeParser method parseViolations.
private void parseViolations(List<Element> ruleElements) {
// searching source files
AbsoluteFileFinder finder = new AbsoluteFileFinder();
// add the project path to the search source
finder.addSourcePath(this.projectPath.getPath());
// if there's additional paths, add them too
if (this.sourcePaths != null) {
finder.addSourcePaths(this.sourcePaths);
}
for (Element ruleElement : ruleElements) {
String ruleName = ruleElement.getAttribute("Name");
GendarmeRule rule = this.rules.get(ruleName);
String problem = ruleElement.getElementsByTagName("problem").item(0).getTextContent();
String solution = ruleElement.getElementsByTagName("solution").item(0).getTextContent();
List<Element> targetElements = XmlElementUtil.getNamedChildElements(ruleElement, "target");
for (Element targetElement : targetElements) {
// String targetName = targetElement.getAttribute("Name");
String targetAssembly = targetElement.getAttribute("Assembly");
DotNetAssembly assembly = new DotNetAssembly(targetAssembly);
List<Element> defectElements = XmlElementUtil.getNamedChildElements(targetElement, "defect");
for (Element defectElement : defectElements) {
String severityString = defectElement.getAttribute("Severity");
String source = defectElement.getAttribute("Source");
// String location = defectElement.getAttribute("Location");
String confidence = defectElement.getAttribute("Confidence");
String filePath = "";
String fileName = "";
int line = 0;
if (rule.getType() != GendarmeRuleType.Assembly) {
Pattern pattern = Pattern.compile("^(.*)\\(.([0-9]*)\\)$");
Matcher matcher = pattern.matcher(source);
logger.info("matcher.groupCount() : " + matcher.groupCount());
logger.info("matcher.matches() : " + matcher.matches());
logger.info("source : " + source);
if (matcher.matches()) {
for (int cpt = 0; cpt < matcher.groupCount(); cpt++) {
logger.info("group(" + ((int) (cpt + 1)) + "): " + matcher.group(cpt + 1));
}
}
if (matcher.matches()) {
String fullPath = matcher.group(1);
File sourceFile = new File(fullPath);
fileName = sourceFile.getName();
filePath = sourceFile.getParent();
line = Integer.parseInt(matcher.group(2));
}
}
// create the violation
Violation violation = new Violation();
// construct the error message
StringBuilder messageBuilder = new StringBuilder();
if (rule.getUrl() != null) {
messageBuilder.append("<a href=\"").append(rule.getUrl().toString()).append("\">");
messageBuilder.append(rule.getName());
messageBuilder.append("</a>");
} else {
messageBuilder.append(rule.getName());
}
messageBuilder.append(" - ").append(problem).append("<br/>");
messageBuilder.append("Solution: ").append(solution).append("<br/>");
messageBuilder.append("Confidence: ").append(confidence);
violation.setMessage(messageBuilder.toString());
violation.setPopupMessage(problem);
// construct the severity
if (severityString.equals("Low")) {
violation.setSeverityLevel(Severity.LOW_VALUE);
violation.setSeverity(Severity.LOW);
} else if (severityString.equals("Medium")) {
violation.setSeverityLevel(Severity.MEDIUM_VALUE);
violation.setSeverity(Severity.MEDIUM);
} else if (severityString.equals("High")) {
violation.setSeverityLevel(Severity.HIGH_VALUE);
violation.setSeverity(Severity.HIGH);
} else if (severityString.equals("Critical")) {
violation.setSeverityLevel(Severity.HIGH_VALUE);
violation.setSeverity(Severity.HIGH);
} else {
violation.setSeverityLevel(Severity.MEDIUM_VALUE);
violation.setSeverity(Severity.MEDIUM);
}
violation.setType(TYPE_NAME);
violation.setSource(rule.getName());
// try to get the file
// TODO : test it with Linux Master => Windows Slave node. Unix/Windows path could be a problem.
FullFileModel fileModel;
if ((filePath.length() > 0) && (fileName.length() > 0)) {
violation.setLine(line);
// get the display name of the file
String displayName = ParseUtil.resolveAbsoluteName(this.projectPath, filePath + File.separatorChar + fileName);
// try to get the source file, add it if not already
// exists
fileModel = model.getFileModel(displayName);
if (fileModel.getSourceFile() == null) {
finder.addSourcePath(filePath);
File sourceFile = finder.getFileForName(fileName);
if (sourceFile != null && sourceFile.exists()) {
fileModel.setSourceFile(sourceFile);
fileModel.setLastModified(sourceFile.lastModified());
logger.info("fileModel.getSourceFile() : " + fileModel.getSourceFile().getAbsolutePath());
} else {
logger.info("sourceFile.exists()==false: " + filePath + "," + fileName);
}
} else {
logger.info("fileModel.getSourceFile() != null: " + displayName);
}
} else {
// if there's no source files, just put the assembly
// name
fileModel = model.getFileModel(assembly.getName() + ".dll");
logger.info("fileModel.getSourceFile() : " + (fileModel.getSourceFile() == null ? "null" : fileModel.getSourceFile().getAbsolutePath()));
}
logger.info("fileModel.getDisplayName() : " + fileModel.getDisplayName());
logger.info("reportParentFile : " + reportParentFile);
logger.info("fileName : " + fileName);
logger.info("filePath : " + filePath);
// Add the violation to the model
fileModel.addViolation(violation);
}
}
}
}
use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.
the class Pep8Parser method parseLine.
/**
* Parses a PEP 8 line and adding a violation if regex
* @param model build model to add violations to
* @param line the line in the file.
* @param projectPath the path to use to resolve the file.
*/
public void parseLine(FullBuildModel model, String line, File projectPath) {
Pep8Violation pep8Violation = getPep8Violation(line);
if (pep8Violation != null) {
Violation violation = new Violation();
violation.setType("pep8");
violation.setLine(pep8Violation.getLineStr());
violation.setMessage(pep8Violation.getMessage());
violation.setSource(pep8Violation.getViolationId());
setServerityLevel(violation, pep8Violation.getViolationId());
FullFileModel fileModel = getFileModel(model, pep8Violation.getFileName(), absoluteFileFinder.getFileForName(pep8Violation.getFileName()));
fileModel.addViolation(violation);
}
}
use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.
the class SimianParser method parseSetElement.
/**
* Parses the <set/> block and adds the found duplication violations.
* @throws IOException thrown by XmlPullParser
* @throws XmlPullParserException thrown by XmlPullParser
*/
private void parseSetElement() throws IOException, XmlPullParserException {
List<DuplicationBlock> blocks = new ArrayList<DuplicationBlock>();
while (skipToTag("block")) {
blocks.add(parseBlockElement());
getParser().next();
endElement();
}
for (DuplicationBlock block : blocks) {
List<DuplicationBlock> otherBlocks = new ArrayList<DuplicationBlock>(blocks);
otherBlocks.remove(block);
Violation violation = createViolation(block);
setViolationMessages(violation, block, otherBlocks);
FullFileModel fileModel = getFileModel(block.absolutePath);
fileModel.addViolation(violation);
}
}
use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.
the class StyleCopParser method parseViolations.
/**
* Parse the Violation tag and add it to the build model
* @param elements list of Violation tags
*/
private void parseViolations(List<Element> elements) throws IOException {
for (Element element : elements) {
Violation violation = new Violation();
violation.setLine(getString(element, "LineNumber"));
violation.setMessage(element.getTextContent() + " (" + getString(element, "RuleId") + ")");
violation.setSeverity(Severity.MEDIUM);
violation.setSeverityLevel(Severity.MEDIUM_VALUE);
violation.setType(TYPE_NAME);
String temp = getString(element, "RuleNamespace");
int i = temp.lastIndexOf('.');
if (i != -1) {
violation.setSource(temp.substring(i));
} else {
violation.setSource(getString(element, "RuleId"));
}
// Add the violation to the model
String displayName = new FilePath(reportParentFile).child(getString(element, "Source")).getRemote();
displayName = ParseUtil.resolveAbsoluteName(reportParentFile, displayName);
/* TODO: apply heuristics to fine the source.
StyleCop just puts whatever path representation it gets from MSBuild into @Source,
which can be relative (to the current directory MSBuild run in, which we won't know.)
In such a case, there's really no reliable way for us to deterministically figure out
where the source code is in the source tree.
The resolution against 'reportParentFile' is quite arbitrary in that sense and only
works if the report is created into the same directory as the MSBuild current directory,
but it is a backward compatible behaviour.
*/
FullFileModel fileModel = model.getFileModel(displayName);
fileModel.addViolation(violation);
}
}
Aggregations