use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddException.
@Test
public void testAddException() throws IOException {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", null, null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
logger.auditFinished(null);
final String[] expectedLines = { "<exception>", "<![CDATA[", "stackTrace]]>", "</exception>", "" };
verifyLines(expectedLines);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddErrorOnZeroColumns.
@Test
public void testAddErrorOnZeroColumns() throws IOException {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message = new LocalizedMessage(1, 0, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addError(ev);
logger.auditFinished(null);
final String[] expectedLines = { "<error line=\"1\" severity=\"error\" message=\"key\"" + " source=\"com.puppycrawl.tools.checkstyle.XMLLoggerTest\"/>" };
verifyLines(expectedLines);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class XMLLoggerTest method testFileStarted.
@Test
public void testFileStarted() throws IOException {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final AuditEvent ev = new AuditEvent(this, "Test.java");
logger.fileStarted(ev);
logger.auditFinished(null);
final String[] expectedLines = { "<file name=\"Test.java\">" };
verifyLines(expectedLines);
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project maven-plugins by apache.
the class CheckstyleReportGenerator method sortConfiguration.
private void sortConfiguration(List<ConfReference> result, Configuration config, ChainedItem<Configuration> parent, CheckstyleResults results) {
for (Configuration childConfig : config.getChildren()) {
String ruleName = childConfig.getName();
if (treeWalkerNames.contains(ruleName)) {
// special sub-case: TreeWalker is the parent of multiple rules, not an effective rule
sortConfiguration(result, childConfig, new ChainedItem<>(config, parent), results);
} else {
String fixedmessage = getConfigAttribute(childConfig, null, "message", null);
// Grab the severity from the rule configuration, use null as default value
String configSeverity = getConfigAttribute(childConfig, null, "severity", null);
// count rule violations
long violations = 0;
AuditEvent lastMatchedEvent = null;
for (List<AuditEvent> errors : results.getFiles().values()) {
for (AuditEvent event : errors) {
if (matchRule(event, ruleName, fixedmessage, configSeverity)) {
lastMatchedEvent = event;
violations++;
}
}
}
if (// forget rules without violations
violations > 0) {
String category = RuleUtil.getCategory(lastMatchedEvent);
result.add(new ConfReference(category, childConfig, parent, violations, result.size()));
}
}
}
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project maven-plugins by apache.
the class CheckstyleReportGenerator method doFileEvents.
private void doFileEvents(List<AuditEvent> eventList, String filename) {
for (AuditEvent event : eventList) {
SeverityLevel level = event.getSeverityLevel();
if ((getSeverityLevel() != null) && !(getSeverityLevel() != level)) {
continue;
}
sink.tableRow();
sink.tableCell();
iconTool.iconSeverity(level.getName(), IconTool.TEXT_SIMPLE);
sink.tableCell_();
sink.tableCell();
String category = RuleUtil.getCategory(event);
if (category != null) {
sink.text(category);
}
sink.tableCell_();
sink.tableCell();
String ruleName = RuleUtil.getName(event);
if (ruleName != null) {
sink.text(ruleName);
}
sink.tableCell_();
sink.tableCell();
sink.text(event.getMessage());
sink.tableCell_();
sink.tableCell();
int line = event.getLine();
if (getXrefLocation() != null && line != 0) {
sink.link(getXrefLocation() + "/" + filename.replaceAll("\\.java$", ".html") + "#L" + line);
sink.text(String.valueOf(line));
sink.link_();
} else if (line != 0) {
sink.text(String.valueOf(line));
}
sink.tableCell_();
sink.tableRow_();
}
}
Aggregations