use of hudson.plugins.violations.model.FullFileModel in project violations-plugin by jenkinsci.
the class PyflakesParser method getFileModel.
private FullFileModel getFileModel(FullBuildModel model, String name, File sourceFile) {
FullFileModel fileModel = model.getFileModel(name);
File other = fileModel.getSourceFile();
if (sourceFile == null || ((other != null) && (other.equals(sourceFile) || other.exists()))) {
return fileModel;
}
fileModel.setSourceFile(sourceFile);
fileModel.setLastModified(sourceFile.lastModified());
return fileModel;
}
use of hudson.plugins.violations.model.FullFileModel in project violations-plugin by jenkinsci.
the class CodenarcParserTest method testParseFullBuildModelFromFileWithSourceDirectory.
@Test
public void testParseFullBuildModelFromFileWithSourceDirectory() throws Exception {
FullBuildModel model = getFullBuildModel("CodeNarcXmlReportWithSourceDirectory.xml");
FullFileModel fileModel = model.getFileModel("webapps/testapp/grails-app/controllers/LoginController.groovy");
assertEquals("Number of violations is incorrect", 10, model.getCountNumber("codenarc"));
assertEquals("Number of files is incorrect", 7, model.getFileModelMap().size());
assertNotNull("LoginController model is null", fileModel.getSourceFile());
}
use of hudson.plugins.violations.model.FullFileModel in project violations-plugin by jenkinsci.
the class GendarmeParserTest method testParseViolationData.
@Test
public void testParseViolationData() throws IOException {
FullBuildModel model = getFullBuildModel("Gendarme" + (File.separatorChar == '/' ? "_unix" : "") + ".xml");
assertEquals("Number of violations is incorrect", 3, model.getCountNumber(GendarmeParser.TYPE_NAME));
for (String fileModelKey : model.getFileModelMap().keySet()) {
FullFileModel ffmodel = model.getFileModelMap().get(fileModelKey);
logger.info(fileModelKey + ".displayName=" + ffmodel.getDisplayName());
logger.info(fileModelKey + ".path=" + (ffmodel.getSourceFile() == null ? "null" : ffmodel.getSourceFile().getAbsolutePath()));
}
assertEquals("Number of files is incorrect", 2, model.getFileModelMap().size());
}
use of hudson.plugins.violations.model.FullFileModel in project violations-plugin by jenkinsci.
the class CodenarcParser method parseFileElement.
/*
* <Package path='grails-app/controllers' totalFiles='30'
* filesWithViolations='3' priority1='0' priority2='2' priority3='3'> <File
* name='LoginController.groovy'> <Violation ruleName='UnusedImport'
* priority='3' lineNumber='2'> <SourceLine><![CDATA[import
* org.grails.plugins.springsecurity
* .service.AuthenticateService]]></SourceLine> </Violation> </File> <File
* name='RegisterController.groovy'> <Violation ruleName='UnusedImport'
* priority='3' lineNumber='4'> <SourceLine><![CDATA[import
* org.springframework
* .security.providers.UsernamePasswordAuthenticationToken as
* AuthToken]]></SourceLine> </Violation> <Violation ruleName='UnusedImport'
* priority='3' lineNumber='5'> <SourceLine><![CDATA[import
* org.springframework.security.context.SecurityContextHolder as
* SCH]]></SourceLine></Violation> <Violation
* ruleName='GrailsPublicControllerMethod' priority='2' lineNumber='226'>
* <SourceLine><![CDATA[def sendValidationEmail(def person)
* {]]></SourceLine> </Violation> <Violation ruleName="AbcComplexity"
* priority="2" lineNumber=""> <Message><![CDATA[The ABC score for method
* [foobar] is [92.0]]]></Message> </Violation> </File> </Package>
*/
/**
* Handle a Codenarc File element.
*/
private void parseFileElement(String sourceDirectory, String path) throws IOException, XmlPullParserException {
String sourcePath = getProjectPath().getAbsolutePath();
if (sourceDirectory != null && !sourceDirectory.isEmpty()) {
sourcePath += "/" + sourceDirectory;
}
String absoluteFileName = fixAbsolutePath(sourcePath + "/" + path + "/" + checkNotBlank("name"));
// consume "file" tag
getParser().next();
FullFileModel fileModel = getFileModel(absoluteFileName);
// Loop through the child elements, getting the violations
while (skipToTag("Violation")) {
fileModel.addViolation(parseViolationElement());
endElement();
}
endElement();
}
use of hudson.plugins.violations.model.FullFileModel 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);
}
Aggregations