use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class ResourceResolver method resolveAndUnpack.
/**
* @param artifacts the artifacts to resolve
* @param config the configuration
* @param validClassifiers
* @param propagateErrors
* @return list of <dependencyConflictId, absolutePath>
* @throws ArtifactResolutionException if an exception occurs
* @throws ArtifactNotFoundException if an exception occurs
*/
private Collection<Map.Entry<String, 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<>(artifacts);
final ArtifactFilter filter;
if (config.filter() != null) {
filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
} else {
filter = null;
}
final List<Map.Entry<String, String>> result = new ArrayList<>(artifacts.size());
for (final Artifact a : artifactSet) {
if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
continue;
}
Artifact resolvedArtifact;
try {
resolvedArtifact = resolver.resolveArtifact(config.getBuildingRequest(), a).getArtifact();
} catch (ArtifactResolverException e1) {
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(resolvedArtifact.getFile());
unArchiver.extract();
result.add(new AbstractMap.SimpleEntry<String, String>(a.getDependencyConflictId(), 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.resolve.ArtifactResolverException in project maven-plugins by apache.
the class AbstractJavadocMojo method getArtifactsAbsolutePath.
/**
* Return the Javadoc artifact path and its transitive dependencies path from the local repository
*
* @param javadocArtifact not null
* @return a list of locale artifacts absolute path
* @throws MavenReportException if any
*/
private List<String> getArtifactsAbsolutePath(JavadocPathArtifact javadocArtifact) throws MavenReportException {
if ((StringUtils.isEmpty(javadocArtifact.getGroupId())) && (StringUtils.isEmpty(javadocArtifact.getArtifactId())) && (StringUtils.isEmpty(javadocArtifact.getVersion()))) {
return Collections.emptyList();
}
List<String> path = new ArrayList<String>();
try {
Artifact artifact = createAndResolveArtifact(javadocArtifact);
path.add(artifact.getFile().getAbsolutePath());
DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
coordinate.setGroupId(javadocArtifact.getGroupId());
coordinate.setArtifactId(javadocArtifact.getArtifactId());
coordinate.setVersion(javadocArtifact.getVersion());
Iterable<ArtifactResult> deps = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), coordinate, ScopeFilter.including("compile", "provided"));
for (ArtifactResult a : deps) {
path.add(a.getArtifact().getFile().getAbsolutePath());
}
return path;
} catch (ArtifactResolverException e) {
throw new MavenReportException("Unable to resolve artifact:" + javadocArtifact, e);
} catch (DependencyResolverException e) {
throw new MavenReportException("Unable to resolve dependencies for:" + javadocArtifact, e);
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException 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;
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.
the class AbstractDependencyFilterMojo method addParentArtifacts.
private void addParentArtifacts(MavenProject project, Set<Artifact> artifacts) throws MojoExecutionException {
while (project.hasParent()) {
project = project.getParent();
if (artifacts.contains(project.getArtifact())) {
// artifact already in the set
break;
}
try {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
Artifact resolvedArtifact = artifactResolver.resolveArtifact(buildingRequest, project.getArtifact()).getArtifact();
artifacts.add(resolvedArtifact);
} catch (ArtifactResolverException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.
the class AbstractDependencyFilterMojo method resolve.
/**
* @param coordinates The set of artifact coordinates{@link ArtifactCoordinate}.
* @param stopOnFailure <code>true</code> if we should fail with exception if an artifact couldn't be resolved
* <code>false</code> otherwise.
* @return the resolved artifacts. {@link Artifact}.
* @throws MojoExecutionException in case of error.
*/
protected Set<Artifact> resolve(Set<ArtifactCoordinate> coordinates, boolean stopOnFailure) throws MojoExecutionException {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
for (ArtifactCoordinate coordinate : coordinates) {
try {
Artifact artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
resolvedArtifacts.add(artifact);
} catch (ArtifactResolverException ex) {
// an error occurred during resolution, log it an continue
getLog().debug("error resolving: " + coordinate);
getLog().debug(ex);
if (stopOnFailure) {
throw new MojoExecutionException("error resolving: " + coordinate, ex);
}
}
}
return resolvedArtifacts;
}
Aggregations