use of org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer in project maven-plugins by apache.
the class ResourceResolver method resolveBundlesFromArtifacts.
private List<JavadocBundle> resolveBundlesFromArtifacts(final SourceResolverConfig config, final List<Artifact> artifacts) throws IOException {
final List<Artifact> toResolve = new ArrayList<Artifact>(artifacts.size());
for (final Artifact artifact : artifacts) {
if (config.filter() != null && !new ArtifactIncludeFilterTransformer().transform(config.filter()).include(artifact)) {
continue;
}
if (config.includeCompileSources()) {
toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
}
if (config.includeTestSources()) {
toResolve.add(createResourceArtifact(artifact, AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, config));
}
}
List<String> dirs = null;
try {
dirs = resolveAndUnpack(toResolve, config, RESOURCE_VALID_CLASSIFIERS, false);
} catch (ArtifactResolutionException e) {
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.getMessage(), e);
}
} catch (ArtifactNotFoundException e) {
if (getLogger().isDebugEnabled()) {
getLogger().debug(e.getMessage(), e);
}
}
List<JavadocBundle> result = new ArrayList<JavadocBundle>();
if (dirs != null) {
for (String d : dirs) {
File dir = new File(d);
File resources = new File(dir, ResourcesBundleMojo.RESOURCES_DIR_PATH);
JavadocOptions options = null;
File javadocOptions = new File(dir, ResourcesBundleMojo.BUNDLE_OPTIONS_PATH);
if (javadocOptions.exists()) {
FileInputStream reader = null;
try {
reader = new FileInputStream(javadocOptions);
options = new JavadocOptionsXpp3Reader().read(reader);
} catch (XmlPullParserException e) {
IOException error = new IOException("Failed to parse javadoc options: " + e.getMessage());
error.initCause(e);
throw error;
} finally {
close(reader);
}
}
result.add(new JavadocBundle(options, resources));
}
}
return result;
}
use of org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer in project maven-plugins by apache.
the class ResourceResolver method resolveAndUnpack.
private List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config, final List<String> validClassifiers, final boolean propagateErrors) throws ArtifactResolutionException, ArtifactNotFoundException {
// NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually
// resolve transitively...this is just used to aggregate resolution failures into a single
// exception.
final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
final Artifact pomArtifact = config.project().getArtifact();
final ArtifactRepository localRepo = config.localRepository();
final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
final ArtifactFilter filter;
if (config.filter() != null) {
filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
} else {
filter = null;
}
ArtifactFilter resolutionFilter = null;
if (filter != null) {
// Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
// NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
// and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
// to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
}
Map<String, Artifact> managed = config.project().getManagedVersionMap();
final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact, managed, localRepo, remoteRepos, artifactMetadataSource, resolutionFilter);
final List<String> result = new ArrayList<String>(artifacts.size());
for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
continue;
}
final File d = new File(config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());
if (!d.exists()) {
d.mkdirs();
}
try {
final UnArchiver unArchiver = archiverManager.getUnArchiver(a.getType());
unArchiver.setDestDirectory(d);
unArchiver.setSourceFile(a.getFile());
unArchiver.extract();
result.add(d.getAbsolutePath());
} catch (final NoSuchArchiverException e) {
if (propagateErrors) {
throw new ArtifactResolutionException("Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
}
} catch (final ArchiverException e) {
if (propagateErrors) {
throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
}
}
}
return result;
}
use of org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer in project maven-plugins by apache.
the class AddDependencySetsTask method resolveDependencyArtifacts.
Set<Artifact> resolveDependencyArtifacts(final DependencySet dependencySet) throws InvalidAssemblerConfigurationException {
final Set<Artifact> dependencyArtifacts = new LinkedHashSet<Artifact>();
if (resolvedArtifacts != null) {
dependencyArtifacts.addAll(resolvedArtifacts);
}
if (dependencySet.isUseProjectArtifact()) {
final Artifact projectArtifact = project.getArtifact();
if ((projectArtifact != null) && (projectArtifact.getFile() != null)) {
dependencyArtifacts.add(projectArtifact);
} else {
logger.warn("Cannot include project artifact: " + projectArtifact + "; it doesn't have an associated file or directory.");
}
}
if (dependencySet.isUseProjectAttachments()) {
final List<Artifact> attachments = project.getAttachedArtifacts();
if (attachments != null) {
for (final Artifact attachment : attachments) {
if (attachment.getFile() != null) {
dependencyArtifacts.add(attachment);
} else {
logger.warn("Cannot include attached artifact: " + project.getId() + " for project: " + project.getId() + "; it doesn't have an associated file or directory.");
}
}
}
}
if (dependencySet.isUseTransitiveFiltering()) {
logger.debug("Filtering dependency artifacts USING transitive dependency path information.");
} else {
logger.debug("Filtering dependency artifacts WITHOUT transitive dependency path information.");
}
final ScopeFilter scopeFilter = FilterUtils.newScopeFilter(dependencySet.getScope());
final ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(scopeFilter);
FilterUtils.filterArtifacts(dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(), dependencySet.isUseStrictFiltering(), dependencySet.isUseTransitiveFiltering(), logger, filter);
return dependencyArtifacts;
}
use of org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer 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.transform.ArtifactIncludeFilterTransformer in project maven-plugins by apache.
the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.
private Set<Artifact> getFilteredResolvedArtifacts(MavenProject project, Set<Artifact> artifacts, TransformableFilter filter) {
try {
Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), project.getModel(), filter);
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
for (ArtifactResult artResult : results) {
resolvedArtifacts.add(artResult.getArtifact());
}
return resolvedArtifacts;
} catch (DependencyResolverException e) {
getLog().info("Unable to resolve all dependencies for : " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
}
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
// purge anyway
for (Artifact artifact : artifacts) {
if (artifactFilter.include(artifact)) {
try {
ArtifactResult artifactResult = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
resolvedArtifacts.add(artifactResult.getArtifact());
} catch (ArtifactResolverException e) {
getLog().debug("Unable to resolve artifact: " + artifact);
}
}
}
return resolvedArtifacts;
}
Aggregations