use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddIgnored.
@Test
public void testAddIgnored() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.IGNORE, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.addError(ev);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerEmpty.xml"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddExceptionBeforeFileFinished.
@Test
public void testAddExceptionBeforeFileFinished() throws Exception {
final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", null, null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
logger.fileFinished(fileFinishedEvent);
logger.auditFinished(null);
verifyXml(getPath("ExpectedXMLLoggerException3.xml"), outStream);
assertWithMessage("Invalid close count").that(outStream.getCloseCount()).isEqualTo(1);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathQueryGeneratorTest method testConstructorWithTreeWalkerAuditEvent.
@Test
public void testConstructorWithTreeWalkerAuditEvent() {
final Violation violation = new Violation(12, 1, "messages.properties", null, null, null, null, null, null);
final TreeWalkerAuditEvent event = new TreeWalkerAuditEvent(new FileContents(fileText), "InputXpathQueryGenerator", violation, rootAst);
final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(event, DEFAULT_TAB_WIDTH);
final List<String> actual = queryGenerator.generate();
final List<String> expected = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS" + "/LITERAL_PUBLIC");
assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.Violation 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.
* @throws Error wraps any java.lang.Error happened during execution
* @noinspection ProhibitedExceptionThrown
*/
// -@cs[CyclomaticComplexity] no easy way to split this logic of processing the file
private void processFiles(List<File> files) throws CheckstyleException {
for (final File file : files) {
String fileName = null;
try {
fileName = file.getAbsolutePath();
final long timestamp = file.lastModified();
if (cacheFile != null && cacheFile.isInCache(fileName, timestamp) || !acceptFileStarted(fileName)) {
continue;
}
if (cacheFile != null) {
cacheFile.put(fileName, timestamp);
}
fireFileStarted(fileName);
final SortedSet<Violation> fileMessages = processFile(file);
fireErrors(fileName, fileMessages);
fireFileFinished(fileName);
}// processing. See https://github.com/checkstyle/checkstyle/issues/2285
catch (Exception ex) {
if (fileName != null && cacheFile != null) {
cacheFile.remove(fileName);
}
// 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) {
if (fileName != null && cacheFile != null) {
cacheFile.remove(fileName);
}
// 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.Violation in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testFormatModuleWithModuleId.
@Test
public void testFormatModuleWithModuleId() {
final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, "ModuleId", TestModule.class, "Mocked violation.");
final AuditEvent event = new AuditEvent("", "InputMockFile.java", violation);
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
final String expected = "[WARN] InputMockFile.java:1:1: Mocked violation. [ModuleId]";
assertWithMessage("Invalid format").that(formatter.format(event)).isEqualTo(expected);
}
Aggregations