use of org.apache.maven.shared.artifact.filter.resolve.TransformableFilter in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method createPurgeArtifactsFilter.
/**
* Create the includes exclude filter to use when resolving and purging dependencies Also excludes any "system"
* scope dependencies
*
* @param dependencyArtifacts The dependency artifacts to use as a reference if we're excluding transitive
* dependencies
* @return the created filter
*/
private TransformableFilter createPurgeArtifactsFilter(Set<Artifact> dependencyArtifacts) {
List<TransformableFilter> subFilters = new ArrayList<TransformableFilter>();
// System dependencies should never be purged
subFilters.add(ScopeFilter.excluding(Artifact.SCOPE_SYSTEM));
if (this.snapshotsOnly) {
subFilters.add(new SnapshotsFilter());
}
// The CLI includes/excludes overrides configuration in the pom
if (!StringUtils.isEmpty(this.include)) {
this.includes = parseIncludes(this.include);
}
if (this.includes != null) {
subFilters.add(new PatternInclusionsFilter(includes));
}
if (!StringUtils.isEmpty(this.exclude)) {
this.excludes = parseIncludes(this.exclude);
}
if (this.excludes != null) {
subFilters.add(new PatternExclusionsFilter(excludes));
}
if (!actTransitively) {
subFilters.add(new DirectDependencyFilter(project.getArtifact(), dependencyArtifacts));
}
return new AndFilter(subFilters);
}
use of org.apache.maven.shared.artifact.filter.resolve.TransformableFilter in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method createPurgeArtifactsFilter.
/**
* Create the includes exclude filter to use when resolving and purging dependencies Also excludes any "system"
* scope dependencies
*
* @param theProject The Maven project.
* @param dependencies The dependencies to use as a reference if we're excluding transitive dependencies
* @param purgedArtifacts The artifacts already purged.
* @return the created filter
*/
private TransformableFilter createPurgeArtifactsFilter(MavenProject theProject, List<Dependency> dependencies, Set<Artifact> purgedArtifacts) {
List<TransformableFilter> subFilters = new ArrayList<TransformableFilter>();
// System dependencies should never be purged
subFilters.add(ScopeFilter.excluding(Artifact.SCOPE_SYSTEM));
if (this.snapshotsOnly) {
subFilters.add(new SnapshotsFilter());
}
// The CLI includes/excludes overrides configuration in the pom
if (!StringUtils.isEmpty(this.include)) {
this.includes = parseIncludes(this.include);
}
if (this.includes != null) {
subFilters.add(new PatternInclusionsFilter(includes));
}
if (!StringUtils.isEmpty(this.exclude)) {
this.excludes = parseIncludes(this.exclude);
}
if (this.excludes != null) {
subFilters.add(new PatternExclusionsFilter(excludes));
}
if (!actTransitively) {
subFilters.add(new DirectDependencyFilter(theProject.getArtifact(), dependencies));
}
List<String> exclusions = new ArrayList<String>(reactorProjects.size());
// It doesn't make sense to include projects from the reactor here since they're likely not able to be resolved
for (MavenProject reactorProject : reactorProjects) {
exclusions.add(toPatternExcludes(reactorProject.getArtifact()));
}
// There is no need to consider a second time artifacts that were already purged (re-resolved or not)
for (Artifact purgedArtifact : purgedArtifacts) {
exclusions.add(toPatternExcludes(purgedArtifact));
}
subFilters.add(new PatternExclusionsFilter(exclusions));
return new AndFilter(subFilters);
}
use of org.apache.maven.shared.artifact.filter.resolve.TransformableFilter 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 List<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<TransformableFilter>();
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);
}
}
use of org.apache.maven.shared.artifact.filter.resolve.TransformableFilter in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (!StringUtils.isEmpty(manualInclude)) {
manualIncludes = this.parseIncludes(manualInclude);
}
// If it's a manual purge, the only step is to delete from the local repo
if (manualIncludes != null && manualIncludes.size() > 0) {
manualPurge(manualIncludes);
return;
}
Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
TransformableFilter dependencyFilter = createPurgeArtifactsFilter(dependencyArtifacts);
Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(project, dependencyArtifacts, dependencyFilter);
if (resolvedArtifactsToPurge.isEmpty()) {
getLog().info("No artifacts included for purge for project: " + project.getId());
return;
}
verbose("Purging dependencies for project: " + project.getId());
purgeArtifacts(resolvedArtifactsToPurge);
if (reResolve) {
ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
try {
reResolveArtifacts(project, resolvedArtifactsToPurge, artifactFilter);
} catch (ArtifactResolutionException e) {
String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
} catch (ArtifactNotFoundException e) {
String failureMessage = "Failed to refresh project dependencies for: " + project.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
}
}
}
use of org.apache.maven.shared.artifact.filter.resolve.TransformableFilter in project maven-dependency-plugin by apache.
the class PurgeLocalRepositoryMojo method purgeLocalRepository.
/**
* Purges the local repository for the dependencies in the given Maven project.
*
* @param theProject Maven project.
* @param resolvedArtifactsToPurge The artifacts that were already purged.
* @throws MojoFailureException in case of errors during the purge.
*/
private void purgeLocalRepository(MavenProject theProject, Set<Artifact> purgedArtifacts) throws MojoFailureException {
List<Dependency> dependencies = theProject.getDependencies();
TransformableFilter dependencyFilter = createPurgeArtifactsFilter(theProject, dependencies, purgedArtifacts);
Set<Artifact> resolvedArtifactsToPurge = getFilteredResolvedArtifacts(theProject, dependencies, dependencyFilter);
if (resolvedArtifactsToPurge.isEmpty()) {
getLog().info("No artifacts included for purge for project: " + theProject.getId());
return;
}
verbose("Purging dependencies for project: " + theProject.getId());
purgeArtifacts(resolvedArtifactsToPurge);
purgedArtifacts.addAll(resolvedArtifactsToPurge);
if (reResolve) {
ArtifactFilter artifactFilter = dependencyFilter.transform(new ArtifactIncludeFilterTransformer());
try {
reResolveArtifacts(theProject, resolvedArtifactsToPurge, artifactFilter);
} catch (ArtifactResolutionException e) {
String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
} catch (ArtifactNotFoundException e) {
String failureMessage = "Failed to refresh project dependencies for: " + theProject.getId();
MojoFailureException failure = new MojoFailureException(failureMessage);
failure.initCause(e);
throw failure;
}
}
}
Aggregations