Search in sources :

Example 6 with FullFileModel

use of hudson.plugins.violations.model.FullFileModel 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 7 with FullFileModel

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

the class ZptlintParser 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 8 with FullFileModel

use of hudson.plugins.violations.model.FullFileModel 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 9 with FullFileModel

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

the class JsLintParser method parseFileElement.

private void parseFileElement() throws IOException, XmlPullParserException {
    String relativeName = fixAbsolutePath(checkNotBlank("name"));
    File absoluteFile = absoluteFileFinder.getFileForName(relativeName);
    String absoluteFileName = absoluteFile == null ? relativeName : absoluteFile.getAbsolutePath();
    // consume "file" tag
    getParser().next();
    FullFileModel fileModel = getFileModel(absoluteFileName);
    // loop thru the child elements, getting the "issue" ones
    while (skipToTag("issue")) {
        fileModel.addViolation(parseIssueElement());
    }
    endElement();
}
Also used : FullFileModel(hudson.plugins.violations.model.FullFileModel) File(java.io.File)

Example 10 with FullFileModel

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

the class CheckstyleParser method parseFileElement.

private void parseFileElement() throws IOException, XmlPullParserException {
    String absoluteFileName = fixAbsolutePath(checkNotBlank("name"));
    // consume "file" tag
    getParser().next();
    FullFileModel fileModel = getFileModel(absoluteFileName);
    // Loop tru the child elements, getting the "error" ones
    while (skipToTag("error")) {
        fileModel.addViolation(parseErrorElement());
    }
    endElement();
}
Also used : FullFileModel(hudson.plugins.violations.model.FullFileModel)

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