Search in sources :

Example 6 with MavenReportException

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

the class AbstractJavadocMojo method copyAdditionalJavadocResources.

/**
     * Method that copy additional Javadoc resources from given artifacts.
     *
     * @param anOutputDirectory the output directory
     * @throws MavenReportException if any
     * @see #resourcesArtifacts
     */
private void copyAdditionalJavadocResources(File anOutputDirectory) throws MavenReportException {
    Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
    if (isEmpty(resourcesArtifacts)) {
        return;
    }
    UnArchiver unArchiver;
    try {
        unArchiver = archiverManager.getUnArchiver("jar");
    } catch (NoSuchArchiverException e) {
        throw new MavenReportException("Unable to extract resources artifact. " + "No archiver for 'jar' available.", e);
    }
    for (ResourcesArtifact item : resourcesArtifacts) {
        Artifact artifact;
        try {
            artifact = createAndResolveArtifact(item);
        } catch (ArtifactResolverException e) {
            throw new MavenReportException("Unable to resolve artifact:" + item, e);
        }
        unArchiver.setSourceFile(artifact.getFile());
        unArchiver.setDestDirectory(anOutputDirectory);
        // remove the META-INF directory from resource artifact
        IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
        selectors[0].setExcludes(new String[] { "META-INF/**" });
        unArchiver.setFileSelectors(selectors);
        getLog().info("Extracting contents of resources artifact: " + artifact.getArtifactId());
        try {
            unArchiver.extract();
        } catch (ArchiverException e) {
            throw new MavenReportException("Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e);
        }
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 7 with MavenReportException

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

the class AbstractJavadocMojo method validateJavadocOptions.

/**
     * Checks for the validity of the Javadoc options used by the user.
     *
     * @throws MavenReportException if error
     */
private void validateJavadocOptions() throws MavenReportException {
    // encoding
    if (StringUtils.isNotEmpty(getEncoding()) && !JavadocUtil.validateEncoding(getEncoding())) {
        throw new MavenReportException("Unsupported option <encoding/> '" + getEncoding() + "'");
    }
    // locale
    if (StringUtils.isNotEmpty(this.locale)) {
        StringTokenizer tokenizer = new StringTokenizer(this.locale, "_");
        final int maxTokens = 3;
        if (tokenizer.countTokens() > maxTokens) {
            throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "', should be language_country_variant.");
        }
        Locale localeObject = null;
        if (tokenizer.hasMoreTokens()) {
            String language = tokenizer.nextToken().toLowerCase(Locale.ENGLISH);
            if (!Arrays.asList(Locale.getISOLanguages()).contains(language)) {
                throw new MavenReportException("Unsupported language '" + language + "' in option <locale/> '" + this.locale + "'");
            }
            localeObject = new Locale(language);
            if (tokenizer.hasMoreTokens()) {
                String country = tokenizer.nextToken().toUpperCase(Locale.ENGLISH);
                if (!Arrays.asList(Locale.getISOCountries()).contains(country)) {
                    throw new MavenReportException("Unsupported country '" + country + "' in option <locale/> '" + this.locale + "'");
                }
                localeObject = new Locale(language, country);
                if (tokenizer.hasMoreTokens()) {
                    String variant = tokenizer.nextToken();
                    localeObject = new Locale(language, country, variant);
                }
            }
        }
        if (localeObject == null) {
            throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "', should be language_country_variant.");
        }
        this.locale = localeObject.toString();
        final List<Locale> availableLocalesList = Arrays.asList(Locale.getAvailableLocales());
        if (StringUtils.isNotEmpty(localeObject.getVariant()) && !availableLocalesList.contains(localeObject)) {
            StringBuilder sb = new StringBuilder();
            sb.append("Unsupported option <locale/> with variant '").append(this.locale);
            sb.append("'");
            localeObject = new Locale(localeObject.getLanguage(), localeObject.getCountry());
            this.locale = localeObject.toString();
            sb.append(", trying to use <locale/> without variant, i.e. '").append(this.locale).append("'");
            if (getLog().isWarnEnabled()) {
                getLog().warn(sb.toString());
            }
        }
        if (!availableLocalesList.contains(localeObject)) {
            throw new MavenReportException("Unsupported option <locale/> '" + this.locale + "'");
        }
    }
}
Also used : Locale(java.util.Locale) StringTokenizer(java.util.StringTokenizer) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 8 with MavenReportException

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

the class AbstractJavadocMojo method collectLinks.

private Set<String> collectLinks() throws MavenReportException {
    Set<String> links = 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.getLinks())) {
                    links.addAll(options.getLinks());
                }
            }
        }
    }
    if (isNotEmpty(this.links)) {
        links.addAll(this.links);
    }
    links.addAll(getDependenciesLinks());
    return links;
}
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 9 with MavenReportException

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

the class AbstractJavadocMojo method addCommandLinePackages.

/**
     * Generate a file called <code>packages</code> to hold all package names and add the <code>@packages</code> in
     * the command line.
     *
     * @param cmd                    not null
     * @param javadocOutputDirectory not null
     * @param packageNames           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 #PACKAGES_FILE_NAME
     */
private void addCommandLinePackages(Commandline cmd, File javadocOutputDirectory, List<String> packageNames) throws MavenReportException {
    File packagesFile = new File(javadocOutputDirectory, PACKAGES_FILE_NAME);
    try {
        FileUtils.fileWrite(packagesFile.getAbsolutePath(), null, /* platform encoding */
        StringUtils.join(packageNames.iterator(), SystemUtils.LINE_SEPARATOR));
    } catch (IOException e) {
        throw new MavenReportException("Unable to write '" + packagesFile.getName() + "' temporary file for command execution", e);
    }
    cmd.createArg().setValue("@" + PACKAGES_FILE_NAME);
}
Also used : IOException(java.io.IOException) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 10 with MavenReportException

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

the class AbstractJavadocMojo method addCommandLineArgFile.

/**
     * Generate a file called <code>argfile</code> (or <code>files</code>, depending the JDK) to hold files and add
     * the <code>@argfile</code> (or <code>@file</code>, depending the JDK) in the command line.
     *
     * @param cmd                    not null
     * @param javadocOutputDirectory not null
     * @param files                  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 <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.html#runningjavadoc">
     *      What s New in Javadoc 1.4
     *      </a>
     * @see #isJavaDocVersionAtLeast(float)
     * @see #ARGFILE_FILE_NAME
     * @see #FILES_FILE_NAME
     */
private void addCommandLineArgFile(Commandline cmd, File javadocOutputDirectory, List<String> files) throws MavenReportException {
    File argfileFile;
    if (isJavaDocVersionAtLeast(SINCE_JAVADOC_1_4)) {
        argfileFile = new File(javadocOutputDirectory, ARGFILE_FILE_NAME);
        cmd.createArg().setValue("@" + ARGFILE_FILE_NAME);
    } else {
        argfileFile = new File(javadocOutputDirectory, FILES_FILE_NAME);
        cmd.createArg().setValue("@" + FILES_FILE_NAME);
    }
    try {
        FileUtils.fileWrite(argfileFile.getAbsolutePath(), null, /* platform encoding */
        StringUtils.join(files.iterator(), SystemUtils.LINE_SEPARATOR));
    } catch (IOException e) {
        throw new MavenReportException("Unable to write '" + argfileFile.getName() + "' temporary file for command execution", e);
    }
}
Also used : IOException(java.io.IOException) 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