Search in sources :

Example 41 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 42 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 43 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)

Example 44 with MavenReportException

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

the class JiraMojo method executeReport.

public void executeReport(Locale locale) throws MavenReportException {
    // Validate parameters
    List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, JIRA_COLUMNS);
    if (columnIds.isEmpty()) {
        // This can happen if the user has configured column names and they are all invalid
        throw new MavenReportException("maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid.");
    }
    try {
        // Download issues
        AbstractJiraDownloader issueDownloader;
        if (mockDownloader != null) {
            issueDownloader = mockDownloader;
        } else {
            AdaptiveJiraDownloader downloader = new AdaptiveJiraDownloader();
            downloader.setForceClassic(forceRss);
            issueDownloader = downloader;
        }
        configureIssueDownloader(issueDownloader);
        issueDownloader.doExecute();
        List<Issue> issueList = issueDownloader.getIssueList();
        if (StringUtils.isNotEmpty(versionPrefix)) {
            int originalNumberOfIssues = issueList.size();
            issueList = IssueUtils.filterIssuesWithVersionPrefix(issueList, versionPrefix);
            getLog().debug("Filtered out " + issueList.size() + " issues of " + originalNumberOfIssues + " that matched the versionPrefix '" + versionPrefix + "'.");
        }
        if (onlyCurrentVersion) {
            String version = (versionPrefix == null ? "" : versionPrefix) + project.getVersion();
            issueList = IssueUtils.getIssuesForVersion(issueList, version);
            getLog().info("The JIRA Report will contain issues only for the current version.");
        }
        // Generate the report
        IssuesReportGenerator report = new IssuesReportGenerator(IssuesReportHelper.toIntArray(columnIds));
        if (issueList.isEmpty()) {
            report.doGenerateEmptyReport(getBundle(locale), getSink());
        } else {
            report.doGenerateReport(getBundle(locale), getSink(), issueList);
        }
    } catch (Exception e) {
        getLog().warn(e);
    }
}
Also used : Issue(org.apache.maven.plugins.issues.Issue) IssuesReportGenerator(org.apache.maven.plugins.issues.IssuesReportGenerator) MavenReportException(org.apache.maven.reporting.MavenReportException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 45 with MavenReportException

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

the class ChangesMojo method copyStaticResources.

private void copyStaticResources() throws MavenReportException {
    final String pluginResourcesBase = "org/apache/maven/plugins/changes";
    String[] resourceNames = { "images/add.gif", "images/fix.gif", "images/icon_help_sml.gif", "images/remove.gif", "images/rss.png", "images/update.gif" };
    try {
        getLog().debug("Copying static resources.");
        for (String resourceName : resourceNames) {
            URL url = this.getClass().getClassLoader().getResource(pluginResourcesBase + "/" + resourceName);
            FileUtils.copyURLToFile(url, new File(getReportOutputDirectory(), resourceName));
        }
    } catch (IOException e) {
        throw new MavenReportException("Unable to copy static resources.");
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) 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