Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.qulice.checkstyle;

import com.jcabi.log.Logger;
import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
Expand Down Expand Up @@ -66,23 +67,37 @@ public CheckstyleValidator(final Environment env) {
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Collection<Violation> validate(final Collection<File> files) {
if (files == null) {
throw new IllegalArgumentException("Files collection cannot be null");
}
final List<File> sources = this.getNonExcludedFiles(files);
try {
this.checker.process(sources);
} catch (final CheckstyleException ex) {
throw new IllegalStateException("Failed to process files", ex);
throw new IllegalStateException(
String.format("Failed to process files: %s", ex.getMessage()),
ex
);
}
final List<AuditEvent> events = this.listener.events();
final Collection<Violation> results = new LinkedList<>();
for (final AuditEvent event : events) {
final String check = event.getSourceName();
final String checkname = check.substring(check.lastIndexOf('.') + 1);
final String filename = event.getFileName();
final String line = String.valueOf(event.getLine());
final String message = event.getMessage();
if (filename == null) {
Logger.warn(this, "Skipping violation with null filename for check %s", checkname);
continue;
}
results.add(
new Violation.Default(
this.name(),
check.substring(check.lastIndexOf('.') + 1),
event.getFileName(),
String.valueOf(event.getLine()),
event.getMessage()
checkname,
filename,
line,
message
)
);
}
Expand Down