Search in sources :

Example 1 with SourceResolverConfig

use of org.apache.maven.plugins.javadoc.resolver.SourceResolverConfig 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

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 SourceResolverConfig (org.apache.maven.plugins.javadoc.resolver.SourceResolverConfig)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 AndFilter (org.apache.maven.shared.artifact.filter.resolve.AndFilter)1 PatternExclusionsFilter (org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter)1 PatternInclusionsFilter (org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter)1 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)1