Search in sources :

Example 1 with JavadocOptions

use of org.apache.maven.plugin.javadoc.options.JavadocOptions in project maven-plugins by apache.

the class ResourceResolver method resolveBundlesFromArtifacts.

private List<JavadocBundle> resolveBundlesFromArtifacts(final SourceResolverConfig config, final List<Artifact> artifacts) throws IOException {
    final List<Artifact> toResolve = new ArrayList<Artifact>(artifacts.size());
    for (final Artifact artifact : artifacts) {
        if (config.filter() != null && !new ArtifactIncludeFilterTransformer().transform(config.filter()).include(artifact)) {
            continue;
        }
        if (config.includeCompileSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
        if (config.includeTestSources()) {
            toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
        }
    }
    List<String> dirs = null;
    try {
        dirs = resolveAndUnpack(toResolve, config, RESOURCE_VALID_CLASSIFIERS, false);
    } catch (ArtifactResolutionException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    } catch (ArtifactNotFoundException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(e.getMessage(), e);
        }
    }
    List<JavadocBundle> result = new ArrayList<JavadocBundle>();
    if (dirs != null) {
        for (String d : dirs) {
            File dir = new File(d);
            File resources = new File(dir, ResourcesBundleMojo.RESOURCES_DIR_PATH);
            JavadocOptions options = null;
            File javadocOptions = new File(dir, ResourcesBundleMojo.BUNDLE_OPTIONS_PATH);
            if (javadocOptions.exists()) {
                FileInputStream reader = null;
                try {
                    reader = new FileInputStream(javadocOptions);
                    options = new JavadocOptionsXpp3Reader().read(reader);
                } catch (XmlPullParserException e) {
                    IOException error = new IOException("Failed to parse javadoc options: " + e.getMessage());
                    error.initCause(e);
                    throw error;
                } finally {
                    close(reader);
                }
            }
            result.add(new JavadocBundle(options, resources));
        }
    }
    return result;
}
Also used : ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) FileInputStream(java.io.FileInputStream) JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) File(java.io.File)

Example 2 with JavadocOptions

use of org.apache.maven.plugin.javadoc.options.JavadocOptions 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 3 with JavadocOptions

use of org.apache.maven.plugin.javadoc.options.JavadocOptions in project maven-plugins by apache.

the class AbstractJavadocMojo method addTagletsFromTagletArtifacts.

/**
     * Auto-detect taglets class name from <code>tagletArtifacts</code> and add them to arguments.
     *
     * @param arguments not null
     * @throws MavenReportException if any
     * @see JavadocUtil#getTagletClassNames(File)
     */
private void addTagletsFromTagletArtifacts(List<String> arguments) throws MavenReportException {
    Set<TagletArtifact> tArtifacts = new LinkedHashSet<TagletArtifact>();
    if (tagletArtifacts != null && tagletArtifacts.length > 0) {
        tArtifacts.addAll(Arrays.asList(tagletArtifacts));
    }
    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.getTagletArtifacts())) {
                    tArtifacts.addAll(options.getTagletArtifacts());
                }
            }
        }
    }
    if (isEmpty(tArtifacts)) {
        return;
    }
    List<String> tagletsPath = new ArrayList<String>();
    for (TagletArtifact aTagletArtifact : tArtifacts) {
        if ((StringUtils.isNotEmpty(aTagletArtifact.getGroupId())) && (StringUtils.isNotEmpty(aTagletArtifact.getArtifactId())) && (StringUtils.isNotEmpty(aTagletArtifact.getVersion()))) {
            Artifact artifact;
            try {
                artifact = createAndResolveArtifact(aTagletArtifact);
            } catch (ArtifactResolverException e) {
                throw new MavenReportException("Unable to resolve artifact:" + aTagletArtifact, e);
            }
            tagletsPath.add(artifact.getFile().getAbsolutePath());
        }
    }
    tagletsPath = JavadocUtil.pruneFiles(tagletsPath);
    for (String tagletJar : tagletsPath) {
        if (!tagletJar.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            continue;
        }
        List<String> tagletClasses;
        try {
            tagletClasses = JavadocUtil.getTagletClassNames(new File(tagletJar));
        } catch (IOException e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("IOException: " + e.getMessage(), e);
            }
            continue;
        } catch (ClassNotFoundException e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("ClassNotFoundException: " + e.getMessage(), e);
            }
            continue;
        } catch (NoClassDefFoundError e) {
            if (getLog().isWarnEnabled()) {
                getLog().warn("Unable to auto-detect Taglet class names from '" + tagletJar + "'. Try to specify them with <taglets/>.");
            }
            if (getLog().isDebugEnabled()) {
                getLog().debug("NoClassDefFoundError: " + e.getMessage(), e);
            }
            continue;
        }
        if (tagletClasses != null && !tagletClasses.isEmpty()) {
            for (String tagletClass : tagletClasses) {
                addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(tagletClass), SINCE_JAVADOC_1_4);
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JavadocBundle(org.apache.maven.plugin.javadoc.resolver.JavadocBundle) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) IOException(java.io.IOException) 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) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with JavadocOptions

use of org.apache.maven.plugin.javadoc.options.JavadocOptions in project maven-plugins by apache.

the class AbstractJavadocMojo method collectOfflineLinks.

private Set<OfflineLink> collectOfflineLinks() throws MavenReportException {
    Set<OfflineLink> result = new LinkedHashSet<OfflineLink>();
    OfflineLink javaApiLink = getDefaultJavadocApiLink();
    if (javaApiLink != null) {
        result.add(javaApiLink);
    }
    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.getOfflineLinks())) {
                    result.addAll(options.getOfflineLinks());
                }
            }
        }
    }
    if (this.offlineLinks != null && this.offlineLinks.length > 0) {
        result.addAll(Arrays.asList(this.offlineLinks));
    }
    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) OfflineLink(org.apache.maven.plugin.javadoc.options.OfflineLink) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 5 with JavadocOptions

use of org.apache.maven.plugin.javadoc.options.JavadocOptions in project maven-plugins by apache.

the class ResourceResolver method resolveBundleFromProject.

private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project, Artifact artifact) throws IOException {
    List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
    List<String> classifiers = new ArrayList<String>();
    if (config.includeCompileSources()) {
        classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    if (config.includeTestSources()) {
        classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
    }
    for (String classifier : classifiers) {
        File optionsFile = new File(project.getBuild().getDirectory(), "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
        if (!optionsFile.exists()) {
            continue;
        }
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(optionsFile);
            JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);
            stream.close();
            stream = null;
            bundles.add(new JavadocBundle(options, new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
        } catch (XmlPullParserException e) {
            IOException error = new IOException("Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
            error.initCause(e);
            throw error;
        } finally {
            close(stream);
        }
    }
    return bundles;
}
Also used : JavadocOptionsXpp3Reader(org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader) JavadocOptions(org.apache.maven.plugin.javadoc.options.JavadocOptions) ArrayList(java.util.ArrayList) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

JavadocOptions (org.apache.maven.plugin.javadoc.options.JavadocOptions)8 IOException (java.io.IOException)7 File (java.io.File)5 JavadocBundle (org.apache.maven.plugin.javadoc.resolver.JavadocBundle)5 LinkedHashSet (java.util.LinkedHashSet)4 MavenReportException (org.apache.maven.reporting.MavenReportException)4 ArrayList (java.util.ArrayList)3 FileInputStream (java.io.FileInputStream)2 Artifact (org.apache.maven.artifact.Artifact)2 JavadocOptionsXpp3Reader (org.apache.maven.plugin.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 Writer (java.io.Writer)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)1 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)1 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)1 OfflineLink (org.apache.maven.plugin.javadoc.options.OfflineLink)1 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)1