use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class Checker method processFiles.
/**
* Processes a list of files with all FileSetChecks.
* @param files a list of files to process.
* @throws CheckstyleException if error condition within Checkstyle occurs.
* @noinspection ProhibitedExceptionThrown
*/
private void processFiles(List<File> files) throws CheckstyleException {
for (final File file : files) {
try {
final String fileName = file.getAbsolutePath();
final long timestamp = file.lastModified();
if (cache != null && cache.isInCache(fileName, timestamp) || !CommonUtils.matchesFileExtension(file, fileExtensions) || !acceptFileStarted(fileName)) {
continue;
}
if (cache != null) {
cache.put(fileName, timestamp);
}
fireFileStarted(fileName);
final SortedSet<LocalizedMessage> fileMessages = processFile(file);
fireErrors(fileName, fileMessages);
fireFileFinished(fileName);
}// processing. See https://github.com/checkstyle/checkstyle/issues/2285
catch (Exception ex) {
// We need to catch all exceptions to put a reason failure (file name) in exception
throw new CheckstyleException("Exception was thrown while processing " + file.getPath(), ex);
} catch (Error error) {
// We need to catch all errors to put a reason failure (file name) in error
throw new Error("Error was thrown while processing " + file.getPath(), error);
}
}
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project maven-plugins by apache.
the class CheckstyleReportListenerTest method testListeners.
public void testListeners() {
fireAuditStarted(null);
AuditEvent event = new AuditEvent(this, "/source/path/file1", null);
fireFileStarted(event);
LocalizedMessage message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.INFO, null, getClass(), null);
fireAddError(new AuditEvent(this, "/source/path/file1", message));
fireFileFinished(event);
event = new AuditEvent(this, "/source/path/file2", null);
fireFileStarted(event);
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.WARNING, null, getClass(), null);
fireAddError(new AuditEvent(this, "/source/path/file2", message));
fireAddError(new AuditEvent(this, "/source/path/file2", message));
fireFileFinished(event);
event = new AuditEvent(this, "/source/path/file3", null);
fireFileStarted(event);
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.ERROR, null, getClass(), null);
fireAddError(new AuditEvent(this, "/source/path/file3", message));
fireAddError(new AuditEvent(this, "/source/path/file3", message));
fireAddError(new AuditEvent(this, "/source/path/file3", message));
fireFileFinished(event);
event = new AuditEvent(this, "/source/path/file4", null);
fireFileStarted(event);
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.IGNORE, null, getClass(), null);
fireAddError(new AuditEvent(this, "/source/path/file4", message));
fireAddError(new AuditEvent(this, "/source/path/file4", message));
fireAddError(new AuditEvent(this, "/source/path/file4", message));
fireAddError(new AuditEvent(this, "/source/path/file4", message));
fireFileFinished(event);
fireAuditFinished(null);
CheckstyleCheckerListener listener = listenerMap.get(SeverityLevel.INFO);
CheckstyleResults results = listener.getResults();
assertEquals("Test total files", 4, results.getFiles().size());
assertEquals("Test file count", 4, results.getFileCount());
assertEquals("test file violations", 1, results.getFileViolations("file1").size());
assertEquals("test file severities", 1, results.getSeverityCount("file1", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.IGNORE));
listener = listenerMap.get(SeverityLevel.WARNING);
results = listener.getResults();
assertEquals("Test total files", 4, results.getFiles().size());
assertEquals("Test file count", 4, results.getFileCount());
assertEquals("test file violations", 2, results.getFileViolations("file2").size());
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.INFO));
assertEquals("test file severities", 2, results.getSeverityCount("file2", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.IGNORE));
listener = listenerMap.get(SeverityLevel.ERROR);
results = listener.getResults();
assertEquals("Test total files", 4, results.getFiles().size());
assertEquals("Test file count", 4, results.getFileCount());
assertEquals("test file violations", 3, results.getFileViolations("file3").size());
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.WARNING));
assertEquals("test file severities", 3, results.getSeverityCount("file3", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.IGNORE));
listener = listenerMap.get(SeverityLevel.IGNORE);
results = listener.getResults();
assertEquals("Test total files", 4, results.getFiles().size());
assertEquals("Test file count", 4, results.getFileCount());
assertEquals("test file violations", 0, results.getFileViolations("file4").size());
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.IGNORE));
}
Aggregations