Search in sources :

Example 21 with FullFileModel

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;
}
Also used : FullFileModel(hudson.plugins.violations.model.FullFileModel) File(java.io.File)

Example 22 with FullFileModel

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());
}
Also used : FullBuildModel(hudson.plugins.violations.model.FullBuildModel) FullFileModel(hudson.plugins.violations.model.FullFileModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 23 with FullFileModel

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());
}
Also used : FullBuildModel(hudson.plugins.violations.model.FullBuildModel) FullFileModel(hudson.plugins.violations.model.FullFileModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 24 with FullFileModel

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();
}
Also used : FullFileModel(hudson.plugins.violations.model.FullFileModel)

Example 25 with FullFileModel

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);
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullFileModel(hudson.plugins.violations.model.FullFileModel) File(java.io.File)

Aggregations

FullFileModel (hudson.plugins.violations.model.FullFileModel)32 File (java.io.File)15 Violation (hudson.plugins.violations.model.Violation)12 ViolationsParserTest (hudson.plugins.violations.ViolationsParserTest)3 FullBuildModel (hudson.plugins.violations.model.FullBuildModel)3 Test (org.junit.Test)3 Element (org.w3c.dom.Element)3 AbsoluteFileFinder (hudson.plugins.violations.util.AbsoluteFileFinder)2 FilePath (hudson.FilePath)1 IOException2 (hudson.util.IOException2)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1