Search in sources :

Example 46 with MavenReportException

use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.

the class PmdReport method writeNonHtml.

/**
     * Use the PMD renderers to render in any format aside from HTML.
     *
     * @param report
     * @throws MavenReportException
     */
private void writeNonHtml(Report report) throws MavenReportException {
    Renderer r = createRenderer();
    if (r == null) {
        return;
    }
    File targetFile = new File(targetDirectory, "pmd." + format);
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(targetFile), getOutputEncoding())) {
        targetDirectory.mkdirs();
        r.setWriter(writer);
        r.start();
        r.renderFileReport(report);
        r.end();
        if (includeXmlInSite) {
            File siteDir = getReportOutputDirectory();
            siteDir.mkdirs();
            FileUtils.copyFile(targetFile, new File(siteDir, "pmd." + format));
        }
    } catch (IOException ioe) {
        throw new MavenReportException(ioe.getMessage(), ioe);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) HTMLRenderer(net.sourceforge.pmd.renderers.HTMLRenderer) XMLRenderer(net.sourceforge.pmd.renderers.XMLRenderer) CSVRenderer(net.sourceforge.pmd.renderers.CSVRenderer) Renderer(net.sourceforge.pmd.renderers.Renderer) TextRenderer(net.sourceforge.pmd.renderers.TextRenderer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 47 with MavenReportException

use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.

the class PmdReport method getPMDConfiguration.

/**
     * Constructs the PMD configuration class, passing it an argument that configures the target JDK.
     *
     * @return the resulting PMD
     * @throws org.apache.maven.reporting.MavenReportException if targetJdk is not supported
     */
public PMDConfiguration getPMDConfiguration() throws MavenReportException {
    PMDConfiguration configuration = new PMDConfiguration();
    LanguageVersion languageVersion = null;
    if (("java".equals(language) || null == language) && null != targetJdk) {
        languageVersion = LanguageRegistry.findLanguageVersionByTerseName("java " + targetJdk);
        if (languageVersion == null) {
            throw new MavenReportException("Unsupported targetJdk value '" + targetJdk + "'.");
        }
    } else if ("javascript".equals(language) || "ecmascript".equals(language)) {
        languageVersion = LanguageRegistry.findLanguageVersionByTerseName("ecmascript");
    } else if ("jsp".equals(language)) {
        languageVersion = LanguageRegistry.findLanguageVersionByTerseName("jsp");
    }
    if (languageVersion != null) {
        getLog().debug("Using language " + languageVersion);
        configuration.setDefaultLanguageVersion(languageVersion);
    }
    if (typeResolution) {
        try {
            @SuppressWarnings("unchecked") List<String> classpath = includeTests ? project.getTestClasspathElements() : project.getCompileClasspathElements();
            getLog().debug("Using aux classpath: " + classpath);
            configuration.prependClasspath(StringUtils.join(classpath.iterator(), File.pathSeparator));
        } catch (Exception e) {
            throw new MavenReportException(e.getMessage(), e);
        }
    }
    if (null != suppressMarker) {
        configuration.setSuppressMarker(suppressMarker);
    }
    configuration.setBenchmark(benchmark);
    if (analysisCache) {
        configuration.setAnalysisCacheLocation(analysisCacheLocation);
        getLog().debug("Using analysis cache location: " + analysisCacheLocation);
    }
    return configuration;
}
Also used : LanguageVersion(net.sourceforge.pmd.lang.LanguageVersion) ResourceNotFoundException(org.codehaus.plexus.resource.loader.ResourceNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) FileResourceCreationException(org.codehaus.plexus.resource.loader.FileResourceCreationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 48 with MavenReportException

use of org.apache.maven.reporting.MavenReportException in project maven-plugins by apache.

the class PmdReport method processFilesWithPMD.

private void processFilesWithPMD(PMDConfiguration pmdConfiguration, List<DataSource> dataSources) throws MavenReportException {
    RuleSetFactory ruleSetFactory = new RuleSetFactory(RuleSetFactory.class.getClassLoader(), RulePriority.valueOf(this.minimumPriority), false, true);
    RuleContext ruleContext = new RuleContext();
    try {
        getLog().debug("Executing PMD...");
        PMD.processFiles(pmdConfiguration, ruleSetFactory, dataSources, ruleContext, Arrays.<Renderer>asList(renderer));
        if (getLog().isDebugEnabled()) {
            getLog().debug("PMD finished. Found " + renderer.getViolations().size() + " violations.");
        }
    } catch (Exception e) {
        String message = "Failure executing PMD: " + e.getLocalizedMessage();
        if (!skipPmdError) {
            throw new MavenReportException(message, e);
        }
        getLog().warn(message, e);
    }
}
Also used : RuleSetFactory(net.sourceforge.pmd.RuleSetFactory) RuleContext(net.sourceforge.pmd.RuleContext) ResourceNotFoundException(org.codehaus.plexus.resource.loader.ResourceNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException) IOException(java.io.IOException) FileResourceCreationException(org.codehaus.plexus.resource.loader.FileResourceCreationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

MavenReportException (org.apache.maven.reporting.MavenReportException)48 File (java.io.File)23 IOException (java.io.IOException)23 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 ArrayList (java.util.ArrayList)10 Artifact (org.apache.maven.artifact.Artifact)7 FileOutputStream (java.io.FileOutputStream)6 Locale (java.util.Locale)6 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)6 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)6 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)6 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)6 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)6 FileNotFoundException (java.io.FileNotFoundException)5 Writer (java.io.Writer)5 LinkedHashSet (java.util.LinkedHashSet)5 SiteRendererSink (org.apache.maven.doxia.siterenderer.sink.SiteRendererSink)5 OutputStreamWriter (java.io.OutputStreamWriter)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3