Search in sources :

Example 1 with DocumentationReporter

use of org.apache.maven.plugin.docck.reports.DocumentationReporter in project maven-plugins by apache.

the class AbstractCheckDocumentationMojo method buildErrorMessages.

private String buildErrorMessages(Map<MavenProject, DocumentationReporter> reporters) {
    String messages = "";
    StringBuilder buffer = new StringBuilder();
    for (Map.Entry<MavenProject, DocumentationReporter> entry : reporters.entrySet()) {
        MavenProject project = entry.getKey();
        DocumentationReporter reporter = entry.getValue();
        if (!reporter.getMessages().isEmpty()) {
            buffer.append("\no ").append(project.getName());
            buffer.append(" (");
            final int numberOfErrors = reporter.getMessagesByType(DocumentationReport.TYPE_ERROR).size();
            buffer.append(numberOfErrors).append(" error").append(numberOfErrors == 1 ? "" : "s");
            buffer.append(", ");
            final int numberOfWarnings = reporter.getMessagesByType(DocumentationReport.TYPE_WARN).size();
            buffer.append(numberOfWarnings).append(" warning").append(numberOfWarnings == 1 ? "" : "s");
            buffer.append(")");
            buffer.append("\n");
            for (String error : reporter.getMessages()) {
                buffer.append("  ").append(error).append("\n");
            }
        }
    }
    if (buffer.length() > 0) {
        messages = "The following documentation problems were found:\n" + buffer.toString();
    }
    return messages;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DocumentationReporter(org.apache.maven.plugin.docck.reports.DocumentationReporter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with DocumentationReporter

use of org.apache.maven.plugin.docck.reports.DocumentationReporter in project maven-plugins by apache.

the class AbstractCheckDocumentationMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    setupProxy();
    if (output != null) {
        getLog().info("Writing documentation check results to: " + output);
    }
    Map<MavenProject, DocumentationReporter> reporters = new LinkedHashMap<MavenProject, DocumentationReporter>();
    boolean hasErrors = false;
    for (MavenProject project : reactorProjects) {
        if (approveProjectPackaging(project.getPackaging())) {
            getLog().info("Checking project: " + project.getName());
            DocumentationReporter reporter = new DocumentationReporter();
            checkProject(project, reporter);
            if (!hasErrors && reporter.hasErrors()) {
                hasErrors = true;
            }
            reporters.put(project, reporter);
        } else {
            getLog().info("Skipping unsupported project: " + project.getName());
        }
    }
    String messages;
    messages = buildErrorMessages(reporters);
    if (!hasErrors) {
        messages += "No documentation errors were found.";
    }
    try {
        writeMessages(messages, hasErrors);
    } catch (IOException e) {
        throw new MojoExecutionException("Error writing results to output file: " + output);
    }
    if (hasErrors) {
        String logLocation;
        if (output == null) {
            logLocation = "Please see the console output above for more information.";
        } else {
            logLocation = "Please see \'" + output + "\' for more information.";
        }
        throw new MojoFailureException("Documentation problems were found. " + logLocation);
    }
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DocumentationReporter(org.apache.maven.plugin.docck.reports.DocumentationReporter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 DocumentationReporter (org.apache.maven.plugin.docck.reports.DocumentationReporter)2 MavenProject (org.apache.maven.project.MavenProject)2 IOException (java.io.IOException)1 Map (java.util.Map)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1