Search in sources :

Example 1 with JavadocBundle

use of org.apache.maven.plugins.javadoc.resolver.JavadocBundle 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<>();
    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<>();
    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.plugins.javadoc.resolver.JavadocBundle) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArrayList(java.util.ArrayList) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) IOException(java.io.IOException) BootclasspathArtifact(org.apache.maven.plugins.javadoc.options.BootclasspathArtifact) JavadocPathArtifact(org.apache.maven.plugins.javadoc.options.JavadocPathArtifact) ResourcesArtifact(org.apache.maven.plugins.javadoc.options.ResourcesArtifact) Artifact(org.apache.maven.artifact.Artifact) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) DocletArtifact(org.apache.maven.plugins.javadoc.options.DocletArtifact) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with JavadocBundle

use of org.apache.maven.plugins.javadoc.resolver.JavadocBundle 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<>();
    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.plugins.javadoc.resolver.JavadocBundle) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) IOException(java.io.IOException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 3 with JavadocBundle

use of org.apache.maven.plugins.javadoc.resolver.JavadocBundle in project maven-plugins by apache.

the class AbstractJavadocMojo method collectOfflineLinks.

private Set<OfflineLink> collectOfflineLinks() throws MavenReportException {
    Set<OfflineLink> result = new LinkedHashSet<>();
    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.plugins.javadoc.resolver.JavadocBundle) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) IOException(java.io.IOException) OfflineLink(org.apache.maven.plugins.javadoc.options.OfflineLink) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 4 with JavadocBundle

use of org.apache.maven.plugins.javadoc.resolver.JavadocBundle in project maven-plugins by apache.

the class AbstractJavadocMojo method copyJavadocResources.

/**
 * Method that copy all <code>doc-files</code> directories from <code>javadocDirectory</code> of
 * the current project or of the projects in the reactor to the <code>outputDirectory</code>.
 *
 * @param anOutputDirectory the output directory
 * @throws java.io.IOException if any
 * @see <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.2.html#docfiles">Reference
 *      Guide, Copies new "doc-files" directory for holding images and examples</a>
 * @see #docfilessubdirs
 */
private void copyJavadocResources(File anOutputDirectory) throws IOException {
    if (anOutputDirectory == null || !anOutputDirectory.exists()) {
        throw new IOException("The outputDirectory " + anOutputDirectory + " doesn't exists.");
    }
    if (includeDependencySources) {
        resolveDependencyBundles();
        if (isNotEmpty(dependencyJavadocBundles)) {
            for (JavadocBundle bundle : dependencyJavadocBundles) {
                File dir = bundle.getResourcesDirectory();
                JavadocOptions options = bundle.getOptions();
                if (dir != null && dir.isDirectory()) {
                    JavadocUtil.copyJavadocResources(anOutputDirectory, dir, options == null ? null : options.getExcludedDocfilesSubdirs());
                }
            }
        }
    }
    if (getJavadocDirectory() != null) {
        JavadocUtil.copyJavadocResources(anOutputDirectory, getJavadocDirectory(), excludedocfilessubdir);
    }
    if (isAggregator() && project.isExecutionRoot()) {
        for (MavenProject subProject : reactorProjects) {
            if (subProject != project && getJavadocDirectory() != null) {
                String javadocDirRelative = PathUtils.toRelative(project.getBasedir(), getJavadocDirectory().getAbsolutePath());
                File javadocDir = new File(subProject.getBasedir(), javadocDirRelative);
                JavadocUtil.copyJavadocResources(anOutputDirectory, javadocDir, excludedocfilessubdir);
            }
        }
    }
}
Also used : JavadocBundle(org.apache.maven.plugins.javadoc.resolver.JavadocBundle) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) MavenProject(org.apache.maven.project.MavenProject) IOException(java.io.IOException) File(java.io.File)

Example 5 with JavadocBundle

use of org.apache.maven.plugins.javadoc.resolver.JavadocBundle in project maven-plugins by apache.

the class AbstractJavadocMojo method collectLinks.

private Set<String> collectLinks() throws MavenReportException {
    Set<String> links = new LinkedHashSet<>();
    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.plugins.javadoc.resolver.JavadocBundle) JavadocOptions(org.apache.maven.plugins.javadoc.options.JavadocOptions) IOException(java.io.IOException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

IOException (java.io.IOException)5 JavadocOptions (org.apache.maven.plugins.javadoc.options.JavadocOptions)5 JavadocBundle (org.apache.maven.plugins.javadoc.resolver.JavadocBundle)5 LinkedHashSet (java.util.LinkedHashSet)4 MavenReportException (org.apache.maven.reporting.MavenReportException)4 File (java.io.File)2 ArrayList (java.util.ArrayList)1 Artifact (org.apache.maven.artifact.Artifact)1 BootclasspathArtifact (org.apache.maven.plugins.javadoc.options.BootclasspathArtifact)1 DocletArtifact (org.apache.maven.plugins.javadoc.options.DocletArtifact)1 JavadocPathArtifact (org.apache.maven.plugins.javadoc.options.JavadocPathArtifact)1 OfflineLink (org.apache.maven.plugins.javadoc.options.OfflineLink)1 ResourcesArtifact (org.apache.maven.plugins.javadoc.options.ResourcesArtifact)1 TagletArtifact (org.apache.maven.plugins.javadoc.options.TagletArtifact)1 MavenProject (org.apache.maven.project.MavenProject)1 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)1