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());
}
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());
}
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("/>");
}
}
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;
}
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;
}
Aggregations