Search in sources :

Example 6 with PatternInclusionsFilter

use of org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter in project maven-plugins by apache.

the class AbstractJavadocMojo method createDependencyArtifactFilter.

/**
 * Returns a ArtifactFilter that only includes direct dependencies of this project
 * (verified via groupId and artifactId).
 *
 * @return
 */
private TransformableFilter createDependencyArtifactFilter() {
    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    List<String> artifactPatterns = new ArrayList<>(dependencyArtifacts.size());
    for (Artifact artifact : dependencyArtifacts) {
        artifactPatterns.add(artifact.getGroupId() + ":" + artifact.getArtifactId());
    }
    return new PatternInclusionsFilter(artifactPatterns);
}
Also used : PatternInclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter) ArrayList(java.util.ArrayList) 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)

Example 7 with PatternInclusionsFilter

use of org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter 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 Map<String, Collection<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<>();
    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.plugins.javadoc.resolver.SourceResolverConfig) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

ArrayList (java.util.ArrayList)7 PatternInclusionsFilter (org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter)7 AndFilter (org.apache.maven.shared.artifact.filter.resolve.AndFilter)5 PatternExclusionsFilter (org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter)5 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)5 Artifact (org.apache.maven.artifact.Artifact)4 IOException (java.io.IOException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 MavenProject (org.apache.maven.project.MavenProject)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 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 ResourcesArtifact (org.apache.maven.plugin.javadoc.options.ResourcesArtifact)1 TagletArtifact (org.apache.maven.plugin.javadoc.options.TagletArtifact)1 SourceResolverConfig (org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig)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