Search in sources :

Example 21 with Violation

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

the class StyleCopParserTest method testViolationCompareTo.

/**
 * Test to catch a NPE in Violation.compareTo() because violation has to little data
 */
@Test
public void testViolationCompareTo() throws Exception {
    FullBuildModel model = getFullBuildModel("onefile.xml");
    Iterator<Violation> iterator = model.getFileModel("MainClass.cs").getTypeMap().get(StyleCopParser.TYPE_NAME).descendingIterator();
    Violation v = iterator.next();
    Violation otherV = iterator.next();
    assertTrue("compareTo() should return false", v.compareTo(otherV) != 0);
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 22 with Violation

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

the class OutputFileModel method createLimited.

private void createLimited() throws IOException {
    for (Map.Entry<String, TreeSet<Violation>> e : fileModel.getTypeMap().entrySet()) {
        String type = e.getKey();
        Set<Violation> violations = e.getValue();
        LimitedType limitedType = new LimitedType();
        limitedType.number = violations.size();
        int c = 0;
        for (Violation v : violations) {
            limitedType.violations.add(v);
            addToVMap(v);
            doViolation(v);
            c++;
            if (c >= config.getLimit()) {
                break;
            }
        }
        limitedMap.put(type, limitedType);
    }
}
Also used : Violation(hudson.plugins.violations.model.Violation) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 23 with Violation

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

the class FindBugsParser method getBugInstance.

private void getBugInstance() throws IOException, XmlPullParserException {
    String type = getParser().getAttributeValue("", "type");
    String priority = getParser().getAttributeValue("", "priority");
    getParser().next();
    classname = null;
    path = null;
    lineNumber = null;
    while (true) {
        String tag = getSibTag();
        if (tag == null) {
            break;
        }
        if (("Class".equals(tag) || "Method".equals(tag) || "Field".equals(tag)) && sameClassname(classname)) {
            if (StringUtil.isBlank(classname)) {
                classname = getParser().getAttributeValue("", "classname");
            }
            getParser().next();
            getSourceLines();
            endElement();
            continue;
        } else if ("SourceLine".equals(tag)) {
            getSourceLine();
        }
        skipTag();
    }
    String name = path == null ? resolveClassName(classname) : path;
    if (StringUtil.isBlank(name)) {
        LOG.info("Unable to decode BugInstance element");
        endElement();
        return;
    }
    File file = absoluteFileFinder.getFileForName(name);
    name = getRelativeName(name, file);
    Violation v = new Violation();
    v.setType("findbugs");
    v.setLine(lineNumber);
    v.setSource(type);
    v.setSeverity(normalizeSeverity(priority));
    v.setSeverityLevel(getSeverityLevel(v.getSeverity()));
    v.setMessage(convertType(type));
    getFileModel(name, file).addViolation(v);
    endElement();
}
Also used : Violation(hudson.plugins.violations.model.Violation) File(java.io.File)

Example 24 with Violation

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

the class FindBugsParser method getMavenFileInstance.

private void getMavenFileInstance() throws IOException, XmlPullParserException {
    // FIXME: I have no definition - just an example file
    // with no source files
    String classname = checkNotBlank("classname");
    String name = resolveClassName(classname);
    File file = absoluteFileFinder.getFileForName(name);
    name = getRelativeName(name, file);
    getParser().next();
    while (true) {
        String tag = getSibTag();
        if (tag == null) {
            break;
        }
        if (tag.equals("BugInstance")) {
            Violation v = new Violation();
            v.setType("findbugs");
            v.setLine(getInt("lineNumber"));
            v.setSource(checkNotBlank("type"));
            v.setSeverity(normalizeSeverity(checkNotBlank("priority")));
            v.setSeverityLevel(getSeverityLevel(v.getSeverity()));
            v.setMessage(checkNotBlank("message"));
            getFileModel(name, file).addViolation(v);
        }
        skipTag();
    }
    endElement();
}
Also used : Violation(hudson.plugins.violations.model.Violation) File(java.io.File)

Example 25 with Violation

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

the class JcReportParser method parseItemElement.

private Violation parseItemElement() throws IOException, XmlPullParserException {
    final String severity = SEVERITIES.get(getString("severity"));
    Violation ret = null;
    if (severity != null) {
        ret = new Violation();
        ret.setType("jcreport");
        // ret.setType(getString("origin")); // report the real source?
        ret.setLine(getString("line"));
        ret.setMessage(getString("message"));
        ret.setSource(getString("finding-type"));
        ret.setSeverity(severity);
        ret.setSeverityLevel(Severity.getSeverityLevel(severity));
    }
    return ret;
}
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