Search in sources :

Example 31 with Violation

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

the class SimianParserTest method testOneFileMessage.

@Test
public void testOneFileMessage() throws Exception {
    FullBuildModel model = getFullBuildModel("onefile.xml");
    Iterator<Violation> iterator = model.getFileModel("java/hudson/maven/MavenBuild.java").getTypeMap().get("simian").descendingIterator();
    Violation v = iterator.next();
    assertEquals("Message in violation is incorrect", "Duplication of 6 lines from <a href='#line76'>line 76</a>.", v.getMessage());
    v = iterator.next();
    assertEquals("Message in violation is incorrect", "Duplication of 6 lines from <a href='#line93'>line 93</a>.", v.getMessage());
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 32 with Violation

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

the class SimianParserTest method testTwoFilePopupMessage.

@Test
public void testTwoFilePopupMessage() throws Exception {
    FullBuildModel model = getFullBuildModel("twofile.xml");
    Iterator<Violation> iterator = model.getFileModel("java/hudson/maven/MavenBuild.java").getTypeMap().get(SimianParser.TYPE_NAME).descendingIterator();
    Violation v = iterator.next();
    assertEquals("Popup message in violation is incorrect", "Duplication of 6 lines from line 61 in MatrixRun.java.", v.getPopupMessage());
    iterator = model.getFileModel("java/hudson/matrix/MatrixRun.java").getTypeMap().get(SimianParser.TYPE_NAME).descendingIterator();
    v = iterator.next();
    assertEquals("Popup message in violation is incorrect", "Duplication of 6 lines from line 92 in MavenBuild.java.", v.getPopupMessage());
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 33 with Violation

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

the class OutputBuildModel method doSeverities.

/**
 * Output the severity numbers for a particular type in a file
 */
private void doSeverities(String type, FullFileModel file) {
    Set<Violation> violations = file.getTypeMap().get(type);
    if (violations == null) {
        return;
    }
    // Build up the severity counts and code numbers
    CodeCountMap codeMap = new CodeCountMap();
    int[] counts = new int[Severity.NUMBER_SEVERITIES];
    for (Violation v : violations) {
        counts[v.getSeverityLevel()]++;
        codeMap.add(v.getSource());
    }
    // Output severity counts
    for (int i = 0; i < counts.length; ++i) {
        if (counts[i] == 0) {
            continue;
        }
        writer.print("      <severity");
        writer.print(XMLUtil.toAttribute("level", i));
        writer.print(XMLUtil.toAttribute("count", counts[i]));
        writer.println("/>");
    }
    // Output severity code counts
    for (Map.Entry<String, Integer> e : codeMap.entrySet()) {
        writer.print("      <source ");
        writer.print(XMLUtil.toAttribute("name", e.getKey()));
        writer.print(XMLUtil.toAttribute("count", e.getValue()));
        writer.println("/>");
    }
}
Also used : Violation(hudson.plugins.violations.model.Violation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 34 with Violation

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

the class FileModelProxy method getFileContent.

/**
 * This gets called from the index.jelly script to render the marked up
 * contents of the file.
 *
 * @return a table of lines and associated violations in html.
 */
public List<BlockData> getFileContent() {
    List<BlockData> blockDataList = newArrayList();
    StringBuilder b = new StringBuilder();
    int previousLine = -1;
    int startLine = 0;
    int currentLine = -1;
    for (Map.Entry<Integer, String> e : fileModel.get().getLines().entrySet()) {
        currentLine = e.getKey();
        String line = e.getValue();
        // Check if at start of block
        if (currentLine != (previousLine + 1)) {
            // Check if need to write previous block
            if (b.length() > 0) {
                blockDataList.add(new BlockData(startLine, previousLine, b.toString(), new File(fileModel.get().getDisplayName()).getName()));
            }
            b = new StringBuilder();
            startLine = currentLine;
        }
        previousLine = currentLine;
        Set<Violation> v = fileModel.get().getLineViolationMap().get(currentLine);
        // TR
        b.append("<tr " + (v != null ? "class='violation'" : "") + ">");
        // Visual Studio
        if (v != null) {
            // Only first one needed for line
            for (Violation violation : v) {
                b.append("<td class='source icon'>");
                b.append(this.getVisualStudioLink(violation));
                b.append("</td>");
                break;
            }
        } else {
            b.append("<td class='source icon'/>\n");
        }
        // Icon
        if (v != null) {
            showIcon(b, v);
        } else {
            b.append("<td class='source icon'/>\n");
        }
        // Line number
        b.append("<td class='source line' id='line" + currentLine + "'>");
        if (v != null) {
            addVDiv(b);
        }
        b.append(currentLine);
        if (v != null) {
            showDiv(b, v);
            b.append("</div>");
        }
        b.append("</td>");
        b.append("<td class='source message'>");
        b.append(XMLUtil.escapeHTMLContent(contextPath + "/plugin/violations/images/tab.png", line));
        b.append("</td>\n");
        b.append("</tr>\n");
    }
    if (b.length() > 0) {
        blockDataList.add(new BlockData(startLine, previousLine, b.toString(), new File(fileModel.get().getDisplayName()).getName()));
    }
    return blockDataList;
}
Also used : Violation(hudson.plugins.violations.model.Violation) Map(java.util.Map) File(java.io.File)

Example 35 with Violation

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

the class CodenarcParser method parseViolationElement.

/**
 * Convert a Codenarc violation to a Hudson Violation.
 *
 * @return Violation
 */
private Violation parseViolationElement() throws IOException, XmlPullParserException {
    Violation ret = new Violation();
    ret.setType("codenarc");
    ret.setLine(getString("lineNumber"));
    ret.setSource(getString("ruleName"));
    setSeverity(ret, getString("priority"));
    getParser().next();
    // get the contents of the embedded SourceLine or Message element
    try {
        expectNextTag("SourceLine");
        // ignored
        getNextText("Missing SourceLine");
        // no message --- use the rule name as the default, which is the
        // most
        // descriptive
        ret.setMessage(ret.getSource());
    } catch (IOException ioe) {
        expectNextTag("Message");
        ret.setMessage(getNextText("Missing Message"));
    }
    // TODO: the following depends upon a patch to CodeNarc 0.9 - so should
    // be
    // exception tolerant
    // get the contents of the embedded Description element
    // expectNextTag("Description");
    // ret.setPopupMessage(getNextText("Missing Description"));
    getParser().next();
    endElement();
    return ret;
}
Also used : Violation(hudson.plugins.violations.model.Violation) IOException(java.io.IOException)

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