use of com.puppycrawl.tools.checkstyle.DefaultLogger in project maven-plugins by apache.
the class CheckstyleViolationCheckMojo method getListener.
private AuditListener getListener() throws MojoFailureException, MojoExecutionException {
AuditListener listener = null;
if (StringUtils.isNotEmpty(outputFileFormat)) {
File resultFile = outputFile;
OutputStream out = getOutputStream(resultFile);
if ("xml".equals(outputFileFormat)) {
listener = new XMLLogger(out, true);
} else if ("plain".equals(outputFileFormat)) {
try {
// Write a plain output file to the standard output file,
// and write an XML output file to the temp directory that can be used to count violations
outputXmlFile = File.createTempFile("checkstyle-result", ".xml");
outputXmlFile.deleteOnExit();
OutputStream xmlOut = getOutputStream(outputXmlFile);
CompositeAuditListener compoundListener = new CompositeAuditListener();
compoundListener.addListener(new XMLLogger(xmlOut, true));
compoundListener.addListener(new DefaultLogger(out, true));
listener = compoundListener;
} catch (IOException e) {
throw new MojoExecutionException("Unable to create temporary file", e);
}
} else {
throw new MojoFailureException("Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'.");
}
}
return listener;
}
use of com.puppycrawl.tools.checkstyle.DefaultLogger in project maven-plugins by apache.
the class AbstractCheckstyleReport method getListener.
/**
* Creates and returns the report generation listener.
*
* @return The audit listener.
* @throws MavenReportException If something goes wrong.
*/
protected AuditListener getListener() throws MavenReportException {
AuditListener listener = null;
if (StringUtils.isNotEmpty(outputFileFormat)) {
File resultFile = outputFile;
OutputStream out = getOutputStream(resultFile);
if ("xml".equals(outputFileFormat)) {
listener = new XMLLogger(out, true);
} else if ("plain".equals(outputFileFormat)) {
listener = new DefaultLogger(out, true);
} else {
// TODO: failure if not a report
throw new MavenReportException("Invalid output file format: (" + outputFileFormat + "). Must be 'plain' or 'xml'.");
}
}
return listener;
}
use of com.puppycrawl.tools.checkstyle.DefaultLogger in project maven-plugins by apache.
the class AbstractCheckstyleReport method getConsoleListener.
/**
* Creates and returns the console listener.
*
* @return The console listener.
* @throws MavenReportException If something goes wrong.
*/
protected DefaultLogger getConsoleListener() throws MavenReportException {
DefaultLogger consoleListener;
if (useFile == null) {
stringOutputStream = new ByteArrayOutputStream();
consoleListener = new DefaultLogger(stringOutputStream, false);
} else {
OutputStream out = getOutputStream(useFile);
consoleListener = new DefaultLogger(out, true);
}
return consoleListener;
}
use of com.puppycrawl.tools.checkstyle.DefaultLogger in project checkstyle by checkstyle.
the class CheckstyleAntTask method getListeners.
/**
* Return the list of listeners set in this task.
* @return the list of listeners.
*/
private AuditListener[] getListeners() {
final int formatterCount = Math.max(1, formatters.size());
final AuditListener[] listeners = new AuditListener[formatterCount];
// formatters
try {
if (formatters.isEmpty()) {
final OutputStream debug = new LogOutputStream(this, Project.MSG_DEBUG);
final OutputStream err = new LogOutputStream(this, Project.MSG_ERR);
listeners[0] = new DefaultLogger(debug, true, err, true);
} else {
for (int i = 0; i < formatterCount; i++) {
final Formatter formatter = formatters.get(i);
listeners[i] = formatter.createListener(this);
}
}
} catch (IOException ex) {
throw new BuildException(String.format(Locale.ROOT, "Unable to create listeners: " + "formatters {%s}.", formatters), ex);
}
return listeners;
}
use of com.puppycrawl.tools.checkstyle.DefaultLogger in project checkstyle by checkstyle.
the class CheckstyleAntTaskTest method testDefaultLoggerListenerWithToFile.
@Test
public void testDefaultLoggerListenerWithToFile() throws IOException {
final CheckstyleAntTask.Formatter formatter = new CheckstyleAntTask.Formatter();
formatter.setUseFile(false);
formatter.setTofile(new File("target/"));
assertTrue(formatter.createListener(null) instanceof DefaultLogger);
}
Aggregations