Search in sources :

Example 1 with TagletArtifact

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

the class AbstractJavadocMojo method getTagletPath.

/**
 * Method to get the path of the taglet artifacts used in the <code>-tagletpath</code> option.
 *
 * @return a string that contains taglet path, separated by the System pathSeparator string
 *         (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
 * @throws MavenReportException if any
 * @see File#pathSeparator
 */
private String getTagletPath() throws MavenReportException {
    Set<TagletArtifact> tArtifacts = collectTagletArtifacts();
    Collection<String> pathParts = new ArrayList<>();
    for (TagletArtifact tagletArtifact : tArtifacts) {
        if ((tagletArtifact != null) && (StringUtils.isNotEmpty(tagletArtifact.getGroupId())) && (StringUtils.isNotEmpty(tagletArtifact.getArtifactId())) && (StringUtils.isNotEmpty(tagletArtifact.getVersion()))) {
            pathParts.addAll(getArtifactsAbsolutePath(tagletArtifact));
        }
    }
    Set<Taglet> taglets = collectTaglets();
    for (Taglet taglet : taglets) {
        if (taglet == null) {
            continue;
        }
        if ((taglet.getTagletArtifact() != null) && (StringUtils.isNotEmpty(taglet.getTagletArtifact().getGroupId())) && (StringUtils.isNotEmpty(taglet.getTagletArtifact().getArtifactId())) && (StringUtils.isNotEmpty(taglet.getTagletArtifact().getVersion()))) {
            pathParts.addAll(getArtifactsAbsolutePath(taglet.getTagletArtifact()));
            pathParts = JavadocUtil.pruneFiles(pathParts);
        } else if (StringUtils.isNotEmpty(taglet.getTagletpath())) {
            pathParts.add(taglet.getTagletpath());
            pathParts = JavadocUtil.pruneDirs(project, pathParts);
        }
    }
    StringBuilder path = new StringBuilder();
    path.append(StringUtils.join(pathParts.iterator(), File.pathSeparator));
    if (StringUtils.isNotEmpty(tagletpath)) {
        path.append(JavadocUtil.unifyPathSeparator(tagletpath));
    }
    return path.toString();
}
Also used : ArrayList(java.util.ArrayList) TagletArtifact(org.apache.maven.plugins.javadoc.options.TagletArtifact) Taglet(org.apache.maven.plugins.javadoc.options.Taglet)

Example 2 with TagletArtifact

use of org.apache.maven.plugins.javadoc.options.TagletArtifact 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)

Aggregations

ArrayList (java.util.ArrayList)2 TagletArtifact (org.apache.maven.plugins.javadoc.options.TagletArtifact)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)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 JavadocOptions (org.apache.maven.plugins.javadoc.options.JavadocOptions)1 JavadocPathArtifact (org.apache.maven.plugins.javadoc.options.JavadocPathArtifact)1 ResourcesArtifact (org.apache.maven.plugins.javadoc.options.ResourcesArtifact)1 Taglet (org.apache.maven.plugins.javadoc.options.Taglet)1 JavadocBundle (org.apache.maven.plugins.javadoc.resolver.JavadocBundle)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)1