Search in sources :

Example 11 with Violation

use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.

the class PMDParser method parseViolationElement.

private Violation parseViolationElement() throws IOException, XmlPullParserException {
    Violation ret = new Violation();
    ret.setType("pmd");
    String line = getParser().getAttributeValue("", "beginline");
    if (line == null) {
        // in pmd version 3.9 and lower the attribute is "line"
        line = getParser().getAttributeValue("", "line");
    }
    ret.setLine(line);
    ret.setSource(getParser().getAttributeValue("", "rule"));
    setSeverity(ret, getParser().getAttributeValue("", "priority"));
    ret.setMessage(getNextText("Expecting text"));
    getParser().next();
    // violation element
    endElement();
    return ret;
}
Also used : Violation(hudson.plugins.violations.model.Violation)

Example 12 with Violation

use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.

the class ReSharperParser method parse.

public void parse(final FullBuildModel model, final File projectPath, final String fileName, final String[] sourcePaths) throws IOException {
    absoluteFileFinder.addSourcePath(projectPath.getAbsolutePath());
    absoluteFileFinder.addSourcePaths(sourcePaths);
    final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder;
    try {
        docBuilder = docBuilderFactory.newDocumentBuilder();
        final Document docElement = docBuilder.parse(new FileInputStream(new File(projectPath, fileName)));
        NodeList nl = docElement.getElementsByTagName("IssueType");
        if (nl == null)
            return;
        for (int i = 0; i < nl.getLength(); i++) {
            final Element issueTypeElement = (Element) nl.item(i);
            final IssueType issueType = parseIssueType(issueTypeElement);
            issueTypes.put(issueType.getId(), issueType);
        }
        nl = docElement.getElementsByTagName("Issue");
        if (nl == null)
            return;
        for (int i = 0; i < nl.getLength(); i++) {
            final Element issueElement = (Element) nl.item(i);
            final Issue issue = parseIssue(issueElement);
            final IssueType issueType = issueTypes.get(issue.getTypeId());
            if (// couldn't find the issue type, skip it
            issueType == null)
                continue;
            final Violation violation = new Violation();
            violation.setType("resharper");
            violation.setMessage(issue.getMessage());
            violation.setPopupMessage(issueType.getDescription() + " - " + issue.getMessage());
            violation.setSource(issueType.getCategory());
            violation.setLine(issue.getLine());
            violation.setSeverity(SEVERITIES.get(issueType.getSeverity()));
            violation.setSeverityLevel(Severity.getSeverityLevel(violation.getSeverity()));
            final File file = absoluteFileFinder.getFileForName(issue.getFile());
            final FullFileModel fullFileModel = getFileModel(model, issue.getFile().replace('\\', '/'), file);
            fullFileModel.addViolation(violation);
        }
    } catch (final ParserConfigurationException pce) {
        throw new IOException2(pce);
    } catch (final SAXException se) {
        throw new IOException2(se);
    }
}
Also used : Violation(hudson.plugins.violations.model.Violation) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FullFileModel(hudson.plugins.violations.model.FullFileModel) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) IOException2(hudson.util.IOException2)

Example 13 with Violation

use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.

the class JcReportParser method parseFileElement.

private void parseFileElement() throws IOException, XmlPullParserException {
    final String name = getString("name");
    // consume "file" tag
    getParser().next();
    if (null != name && name.length() > 0) {
        FullFileModel fileModel = null;
        // Loop through the child elements, getting the "item" ones
        while (skipToTag("item")) {
            final Violation violation = parseItemElement();
            if (null != violation) {
                if (fileModel == null) {
                    fileModel = getFileModel(fixAbsolutePath(name));
                }
                fileModel.addViolation(parseItemElement());
            }
            getParser().next();
            endElement();
        }
    }
    endElement();
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullFileModel(hudson.plugins.violations.model.FullFileModel)

Example 14 with Violation

use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.

the class CheckstyleParser method parseErrorElement.

private Violation parseErrorElement() throws IOException, XmlPullParserException {
    Violation ret = new Violation();
    ret.setType("checkstyle");
    ret.setLine(getString("line"));
    ret.setMessage(getString("message"));
    ret.setSource(getString("source"));
    setSeverity(ret, getString("severity"));
    getParser().next();
    endElement();
    return ret;
}
Also used : Violation(hudson.plugins.violations.model.Violation)

Example 15 with Violation

use of hudson.plugins.violations.model.Violation in project violations-plugin by jenkinsci.

the class CssLintParser method parseIssueElement.

private Violation parseIssueElement() throws IOException, XmlPullParserException {
    Violation violation = new Violation();
    violation.setType(TYPE_NAME);
    violation.setLine(getString("line"));
    violation.setMessage(getString("reason"));
    violation.setSource(getString("evidence"));
    setSeverity(violation, getString("severity"));
    getParser().next();
    endElement();
    return violation;
}
Also used : Violation(hudson.plugins.violations.model.Violation)

Aggregations

Violation (hudson.plugins.violations.model.Violation)41 FullFileModel (hudson.plugins.violations.model.FullFileModel)12 ViolationsParserTest (hudson.plugins.violations.ViolationsParserTest)8 FullBuildModel (hudson.plugins.violations.model.FullBuildModel)8 Test (org.junit.Test)8 File (java.io.File)6 Map (java.util.Map)3 Element (org.w3c.dom.Element)3 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 FilePath (hudson.FilePath)1 AbsoluteFileFinder (hudson.plugins.violations.util.AbsoluteFileFinder)1 IOException2 (hudson.util.IOException2)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Matcher (java.util.regex.Matcher)1