Search in sources :

Example 36 with MavenReportException

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

the class AbstractJavadocMojo method getExcludedPackages.

/**
     * Method to get the packages specified in the <code>excludePackageNames</code> parameter. The packages are split
     * with ',', ':', or ';' and then formatted.
     *
     * @return an array of String objects that contain the package names
     * @throws MavenReportException
     */
private String[] getExcludedPackages() throws MavenReportException {
    Set<String> excluded = new LinkedHashSet<String>();
    if (includeDependencySources) {
        try {
            resolveDependencyBundles();
        } catch (IOException e) {
            throw new MavenReportException("Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e);
        }
        if (isNotEmpty(dependencyJavadocBundles)) {
            for (JavadocBundle bundle : dependencyJavadocBundles) {
                JavadocOptions options = bundle.getOptions();
                if (options != null && isNotEmpty(options.getExcludePackageNames())) {
                    excluded.addAll(options.getExcludePackageNames());
                }
            }
        }
    }
    // for the specified excludePackageNames
    if (StringUtils.isNotEmpty(excludePackageNames)) {
        List<String> packageNames = Arrays.asList(excludePackageNames.split("[,:;]"));
        excluded.addAll(trimValues(packageNames));
    }
    String[] result = new String[excluded.size()];
    if (isNotEmpty(excluded)) {
        int idx = 0;
        for (String exclude : excluded) {
            result[idx] = exclude.replace('.', File.separatorChar);
            idx++;
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JavadocBundle(org.apache.maven.plugin.javadoc.resolver.JavadocBundle) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) IOException(java.io.IOException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 37 with MavenReportException

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

the class AbstractJavadocMojo method getDependencySourcePaths.

/**
     * Resolve dependency sources so they can be included directly in the javadoc process. To customize this,
     * override {@link AbstractJavadocMojo#configureDependencySourceResolution(SourceResolverConfig)}.
     * @return List of source paths.
     * @throws MavenReportException {@link MavenReportException}
     */
protected final List<String> getDependencySourcePaths() throws MavenReportException {
    try {
        if (sourceDependencyCacheDir.exists()) {
            FileUtils.forceDelete(sourceDependencyCacheDir);
            sourceDependencyCacheDir.mkdirs();
        }
    } catch (IOException e) {
        throw new MavenReportException("Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e);
    }
    final SourceResolverConfig config = getDependencySourceResolverConfig();
    final List<TransformableFilter> andFilters = new ArrayList<TransformableFilter>();
    final List<String> dependencyIncludes = dependencySourceIncludes;
    final List<String> dependencyExcludes = dependencySourceExcludes;
    if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes) || isNotEmpty(dependencyExcludes)) {
        if (!includeTransitiveDependencySources) {
            andFilters.add(createDependencyArtifactFilter());
        }
        if (isNotEmpty(dependencyIncludes)) {
            andFilters.add(new PatternInclusionsFilter(dependencyIncludes));
        }
        if (isNotEmpty(dependencyExcludes)) {
            andFilters.add(new PatternExclusionsFilter(dependencyExcludes));
        }
        config.withFilter(new AndFilter(andFilters));
    }
    try {
        return resourceResolver.resolveDependencySourcePaths(config);
    } catch (final ArtifactResolutionException e) {
        throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    } catch (final ArtifactNotFoundException e) {
        throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    }
}
Also used : PatternInclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PatternExclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter) AndFilter(org.apache.maven.shared.artifact.filter.resolve.AndFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) TransformableFilter(org.apache.maven.shared.artifact.filter.resolve.TransformableFilter) SourceResolverConfig(org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 38 with MavenReportException

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

the class AbstractJavadocMojo method executeJavadocCommandLine.

/**
     * Execute the Javadoc command line
     *
     * @param cmd                    not null
     * @param javadocOutputDirectory not null
     * @throws MavenReportException if any errors occur
     */
private void executeJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException {
    if (getLog().isDebugEnabled()) {
        // no quoted arguments
        getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
    }
    String cmdLine = null;
    if (debug) {
        cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
        cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
        writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
    }
    CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
    try {
        int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
        String output = (StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim());
        if (exitCode != 0) {
            if (cmdLine == null) {
                cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
                cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
            }
            writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
            if (StringUtils.isNotEmpty(output) && StringUtils.isEmpty(err.getOutput()) && isJavadocVMInitError(output)) {
                throw new MavenReportException(output + '\n' + '\n' + JavadocUtil.ERROR_INIT_VM + '\n' + "Or, try to reduce the Java heap size for the Javadoc goal using " + "-Dminmemory=<size> and -Dmaxmemory=<size>." + '\n' + '\n' + "Command line was: " + cmdLine + '\n' + '\n' + "Refer to the generated Javadoc files in '" + javadocOutputDirectory + "' dir.\n");
            }
            if (StringUtils.isNotEmpty(output)) {
                getLog().info(output);
            }
            StringBuilder msg = new StringBuilder("\nExit code: ");
            msg.append(exitCode);
            if (StringUtils.isNotEmpty(err.getOutput())) {
                msg.append(" - ").append(err.getOutput());
            }
            msg.append('\n');
            msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
            msg.append("Refer to the generated Javadoc files in '").append(javadocOutputDirectory).append("' dir.\n");
            throw new MavenReportException(msg.toString());
        }
        if (StringUtils.isNotEmpty(output)) {
            getLog().info(output);
        }
    } catch (CommandLineException e) {
        throw new MavenReportException("Unable to execute javadoc command: " + e.getMessage(), e);
    }
    if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
        getLog().warn("Javadoc Warnings");
        StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
        while (token.hasMoreTokens()) {
            String current = token.nextToken().trim();
            getLog().warn(current);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 39 with MavenReportException

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

the class AbstractJavadocMojo method addCommandLineOptions.

/**
     * Generate an <code>options</code> file for all options and arguments and add the <code>@options</code> in the
     * command line.
     *
     * @param cmd                    not null
     * @param arguments              not null
     * @param javadocOutputDirectory not null
     * @throws MavenReportException if any
     * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#argumentfiles">
     *      Reference Guide, Command line argument files</a>
     * @see #OPTIONS_FILE_NAME
     */
private void addCommandLineOptions(Commandline cmd, List<String> arguments, File javadocOutputDirectory) throws MavenReportException {
    File optionsFile = new File(javadocOutputDirectory, OPTIONS_FILE_NAME);
    StringBuilder options = new StringBuilder();
    options.append(StringUtils.join(arguments.toArray(new String[arguments.size()]), SystemUtils.LINE_SEPARATOR));
    try {
        FileUtils.fileWrite(optionsFile.getAbsolutePath(), null, /* platform encoding */
        options.toString());
    } catch (IOException e) {
        throw new MavenReportException("Unable to write '" + optionsFile.getName() + "' temporary file for command execution", e);
    }
    cmd.createArg().setValue("@" + OPTIONS_FILE_NAME);
}
Also used : IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 40 with MavenReportException

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

the class CpdReport method executeCpd.

private void executeCpd() throws MavenReportException {
    if (cpd != null) {
        // CPD has already been run
        getLog().debug("CPD has already been run - skipping redundant execution.");
        return;
    }
    Properties p = new Properties();
    if (ignoreLiterals) {
        p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
    }
    if (ignoreIdentifiers) {
        p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
    }
    try {
        if (filesToProcess == null) {
            filesToProcess = getFilesToProcess();
        }
        try {
            excludeDuplicationsFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
        } catch (MojoExecutionException e) {
            throw new MavenReportException("Error loading exclusions", e);
        }
        String encoding = determineEncoding(!filesToProcess.isEmpty());
        Language cpdLanguage;
        if ("java".equals(language) || null == language) {
            cpdLanguage = new JavaLanguage(p);
        } else if ("javascript".equals(language)) {
            cpdLanguage = new EcmascriptLanguage();
        } else if ("jsp".equals(language)) {
            cpdLanguage = new JSPLanguage();
        } else {
            cpdLanguage = LanguageFactory.createLanguage(language, p);
        }
        CPDConfiguration cpdConfiguration = new CPDConfiguration();
        cpdConfiguration.setMinimumTileSize(minimumTokens);
        cpdConfiguration.setLanguage(cpdLanguage);
        cpdConfiguration.setSourceEncoding(encoding);
        cpd = new CPD(cpdConfiguration);
        for (File file : filesToProcess.keySet()) {
            cpd.add(file);
        }
    } catch (UnsupportedEncodingException e) {
        throw new MavenReportException("Encoding '" + getSourceEncoding() + "' is not supported.", e);
    } catch (IOException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    getLog().debug("Executing CPD...");
    cpd.go();
    getLog().debug("CPD finished.");
    // so the "check" goals can check for violations
    if (isXml()) {
        writeNonHtml(cpd);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) CPDConfiguration(net.sourceforge.pmd.cpd.CPDConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Properties(java.util.Properties) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) Language(net.sourceforge.pmd.cpd.Language) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) CPD(net.sourceforge.pmd.cpd.CPD) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) File(java.io.File) 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