Search in sources :

Example 1 with CheckstyleResults

use of org.apache.maven.plugins.checkstyle.exec.CheckstyleResults in project maven-plugins by apache.

the class AbstractCheckstyleReport method executeReport.

/**
 * {@inheritDoc}
 */
public void executeReport(Locale locale) throws MavenReportException {
    checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
    checkDeprecatedParameterUsage(testSourceDirectory, "testSourceDirectory", "testSourceDirectories");
    locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath());
    locator.addSearchPath("url", "");
    locator.setOutputDirectory(new File(project.getBuild().getDirectory()));
    // for when we start using maven-shared-io and maven-shared-monitor...
    // locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );
    // locator = new Locator( getLog(), new File( project.getBuild().getDirectory() ) );
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        CheckstyleExecutorRequest request = createRequest().setLicenseArtifacts(collectArtifacts("license")).setConfigurationArtifacts(collectArtifacts("configuration")).setOmitIgnoredModules(omitIgnoredModules);
        CheckstyleResults results = checkstyleExecutor.executeCheckstyle(request);
        ResourceBundle bundle = getBundle(locale);
        generateReportStatics();
        generateMainReport(results, bundle);
        if (enableRSS) {
            CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest = new CheckstyleRssGeneratorRequest(this.project, this.getCopyright(), outputDirectory, getLog());
            checkstyleRssGenerator.generateRSS(results, checkstyleRssGeneratorRequest);
        }
    } catch (CheckstyleException e) {
        throw new MavenReportException("Failed during checkstyle configuration", e);
    } catch (CheckstyleExecutorException e) {
        throw new MavenReportException("Failed during checkstyle execution", e);
    } finally {
        // be sure to restore original context classloader
        Thread.currentThread().setContextClassLoader(currentClassLoader);
    }
}
Also used : CheckstyleResults(org.apache.maven.plugins.checkstyle.exec.CheckstyleResults) CheckstyleRssGeneratorRequest(org.apache.maven.plugins.checkstyle.rss.CheckstyleRssGeneratorRequest) CheckstyleExecutorRequest(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest) CheckstyleExecutorException(org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException) ResourceBundle(java.util.ResourceBundle) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with CheckstyleResults

use of org.apache.maven.plugins.checkstyle.exec.CheckstyleResults in project maven-plugins by apache.

the class CheckstyleReportListenerMultiSourceTest 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/path2/file2", null);
    fireFileStarted(event);
    message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.WARNING, null, getClass(), null);
    fireAddError(new AuditEvent(this, "/source/path2/file2", message));
    fireAddError(new AuditEvent(this, "/source/path2/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/path2/file4", null);
    fireFileStarted(event);
    message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.IGNORE, null, getClass(), null);
    fireAddError(new AuditEvent(this, "/source/path2/file4", message));
    fireAddError(new AuditEvent(this, "/source/path2/file4", message));
    fireAddError(new AuditEvent(this, "/source/path2/file4", message));
    fireAddError(new AuditEvent(this, "/source/path2/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));
}
Also used : CheckstyleResults(org.apache.maven.plugins.checkstyle.exec.CheckstyleResults) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) CheckstyleCheckerListener(org.apache.maven.plugins.checkstyle.exec.CheckstyleCheckerListener) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage)

Example 3 with CheckstyleResults

use of org.apache.maven.plugins.checkstyle.exec.CheckstyleResults 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));
}
Also used : CheckstyleResults(org.apache.maven.plugins.checkstyle.exec.CheckstyleResults) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) CheckstyleCheckerListener(org.apache.maven.plugins.checkstyle.exec.CheckstyleCheckerListener) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage)

Aggregations

CheckstyleResults (org.apache.maven.plugins.checkstyle.exec.CheckstyleResults)3 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)2 LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)2 CheckstyleCheckerListener (org.apache.maven.plugins.checkstyle.exec.CheckstyleCheckerListener)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 File (java.io.File)1 ResourceBundle (java.util.ResourceBundle)1 CheckstyleExecutorException (org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException)1 CheckstyleExecutorRequest (org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest)1 CheckstyleRssGeneratorRequest (org.apache.maven.plugins.checkstyle.rss.CheckstyleRssGeneratorRequest)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1