Search in sources :

Example 21 with MavenReportException

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

the class AbstractCheckstyleReport method getOutputStream.

private OutputStream getOutputStream(File file) throws MavenReportException {
    File parentFile = file.getAbsoluteFile().getParentFile();
    if (!parentFile.exists()) {
        parentFile.mkdirs();
    }
    FileOutputStream fileOutputStream;
    try {
        fileOutputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        throw new MavenReportException("Unable to create output stream: " + file, e);
    }
    return fileOutputStream;
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 22 with MavenReportException

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

the class TracMojo method executeReport.

public void executeReport(Locale locale) throws MavenReportException {
    // Validate parameters
    List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, TRAC_COLUMNS, DEPRECATED_TRAC_COLUMNS, getLog());
    if (columnIds.size() == 0) {
        // 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
        TracDownloader issueDownloader = new TracDownloader();
        configureIssueDownloader(issueDownloader);
        List<Issue> issueList = issueDownloader.getIssueList();
        // Generate the report
        IssuesReportGenerator report = new IssuesReportGenerator(IssuesReportHelper.toIntArray(columnIds));
        if (issueList.isEmpty()) {
            report.doGenerateEmptyReport(getBundle(locale), getSink());
            getLog().warn("No ticket has matched.");
        } else {
            report.doGenerateReport(getBundle(locale), getSink(), issueList);
        }
    } catch (MalformedURLException e) {
        // Rethrow this error so that the build fails
        throw new MavenReportException("The Trac URL is incorrect.");
    } catch (XmlRpcException e) {
        // Rethrow this error so that the build fails
        throw new MavenReportException("XmlRpc Error.", e);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Issue(org.apache.maven.plugins.issues.Issue) IssuesReportGenerator(org.apache.maven.plugins.issues.IssuesReportGenerator) XmlRpcException(org.apache.xmlrpc.XmlRpcException) MalformedURLException(java.net.MalformedURLException) MavenReportException(org.apache.maven.reporting.MavenReportException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 23 with MavenReportException

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

the class GitHubMojo method executeReport.

@Override
protected void executeReport(Locale locale) throws MavenReportException {
    // Validate parameters
    List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, githubColumns);
    if (columnIds.size() == 0) {
        // 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
        GitHubDownloader issueDownloader = new GitHubDownloader(project, githubAPIScheme, githubAPIPort, includeOpenIssues, onlyMilestoneIssues);
        issueDownloader.configureAuthentication(settingsDecrypter, githubAPIServerId, settings, getLog());
        List<Issue> issueList = issueDownloader.getIssueList();
        if (onlyCurrentVersion) {
            issueList = IssueUtils.getIssuesForVersion(issueList, project.getVersion());
            getLog().info("The GitHub 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());
            getLog().warn("No issue was matched.");
        } else {
            report.doGenerateReport(getBundle(locale), getSink(), issueList);
        }
    } catch (MalformedURLException e) {
        // Rethrow this error so that the build fails
        throw new MavenReportException("The Github URL is incorrect.");
    } catch (Exception e) {
        throw new MavenReportException(e.getMessage(), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Issue(org.apache.maven.plugins.issues.Issue) IssuesReportGenerator(org.apache.maven.plugins.issues.IssuesReportGenerator) MalformedURLException(java.net.MalformedURLException) MavenReportException(org.apache.maven.reporting.MavenReportException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 24 with MavenReportException

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

the class PmdReport method executePmd.

private void executePmd() throws MavenReportException {
    if (renderer != null) {
        // PMD has already been run
        getLog().debug("PMD has already been run - skipping redundant execution.");
        return;
    }
    try {
        excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
    } catch (MojoExecutionException e) {
        throw new MavenReportException("Unable to load exclusions", e);
    }
    // configure ResourceManager
    locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath());
    locator.addSearchPath("url", "");
    locator.setOutputDirectory(targetDirectory);
    renderer = new PmdCollectingRenderer();
    PMDConfiguration pmdConfiguration = getPMDConfiguration();
    String[] sets = new String[rulesets.length];
    try {
        for (int idx = 0; idx < rulesets.length; idx++) {
            String set = rulesets[idx];
            getLog().debug("Preparing ruleset: " + set);
            RuleSetReferenceId id = new RuleSetReferenceId(set);
            File ruleset = locator.getResourceAsFile(id.getRuleSetFileName(), getLocationTemp(set));
            if (null == ruleset) {
                throw new MavenReportException("Could not resolve " + set);
            }
            sets[idx] = ruleset.getAbsolutePath();
        }
    } catch (ResourceNotFoundException e) {
        throw new MavenReportException(e.getMessage(), e);
    } catch (FileResourceCreationException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    pmdConfiguration.setRuleSets(StringUtils.join(sets, ","));
    try {
        if (filesToProcess == null) {
            filesToProcess = getFilesToProcess();
        }
        if (filesToProcess.isEmpty() && !"java".equals(language)) {
            getLog().warn("No files found to process. Did you add your additional source folders like javascript?" + " (see also build-helper-maven-plugin)");
        }
    } catch (IOException e) {
        throw new MavenReportException("Can't get file list", e);
    }
    String encoding = getSourceEncoding();
    if (StringUtils.isEmpty(encoding) && !filesToProcess.isEmpty()) {
        getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!");
        encoding = ReaderFactory.FILE_ENCODING;
    }
    pmdConfiguration.setSourceEncoding(encoding);
    List<DataSource> dataSources = new ArrayList<>(filesToProcess.size());
    for (File f : filesToProcess.keySet()) {
        dataSources.add(new FileDataSource(f));
    }
    if (sets.length > 0) {
        processFilesWithPMD(pmdConfiguration, dataSources);
    } else {
        getLog().debug("Skipping PMD execution as no rulesets are defined.");
    }
    if (renderer.hasErrors()) {
        if (!skipPmdError) {
            getLog().error("PMD processing errors:");
            getLog().error(renderer.getErrorsAsString());
            throw new MavenReportException("Found " + renderer.getErrors().size() + " PMD processing errors");
        }
        getLog().warn("There are " + renderer.getErrors().size() + " PMD processing errors:");
        getLog().warn(renderer.getErrorsAsString());
    }
    removeExcludedViolations(renderer.getViolations());
    // so the "check" goals can check for violations
    if (isXml() && renderer != null) {
        writeNonHtml(renderer.asReport());
    }
    if (benchmark) {
        try (PrintStream benchmarkFileStream = new PrintStream(benchmarkOutputFilename)) {
            (new TextReport()).generate(Benchmarker.values(), benchmarkFileStream);
        } catch (FileNotFoundException fnfe) {
            getLog().error("Unable to generate benchmark file: " + benchmarkOutputFilename, fnfe);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) RuleSetReferenceId(net.sourceforge.pmd.RuleSetReferenceId) FileResourceCreationException(org.codehaus.plexus.resource.loader.FileResourceCreationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) TextReport(net.sourceforge.pmd.benchmark.TextReport) DataSource(net.sourceforge.pmd.util.datasource.DataSource) FileDataSource(net.sourceforge.pmd.util.datasource.FileDataSource) FileDataSource(net.sourceforge.pmd.util.datasource.FileDataSource) ResourceNotFoundException(org.codehaus.plexus.resource.loader.ResourceNotFoundException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration)

Example 25 with MavenReportException

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

the class CpdReport method writeNonHtml.

void writeNonHtml(CPD cpd) throws MavenReportException {
    Renderer r = createRenderer();
    if (r == null) {
        return;
    }
    String buffer = r.render(filterMatches(cpd.getMatches()));
    File targetFile = new File(targetDirectory, "cpd." + format);
    targetDirectory.mkdirs();
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(targetFile), getOutputEncoding())) {
        writer.write(buffer);
        if (includeXmlInSite) {
            File siteDir = getReportOutputDirectory();
            siteDir.mkdirs();
            FileUtils.copyFile(targetFile, new File(siteDir, "cpd." + format));
        }
    } catch (IOException ioe) {
        throw new MavenReportException(ioe.getMessage(), ioe);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) XMLRenderer(net.sourceforge.pmd.cpd.XMLRenderer) CSVRenderer(net.sourceforge.pmd.cpd.CSVRenderer) Renderer(net.sourceforge.pmd.cpd.Renderer) 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)

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