use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-archetype by apache.
the class DefaultDownloader method downloadOld.
public File downloadOld(String groupId, String artifactId, String version, ArtifactRepository archetypeRepository, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ProjectBuildingRequest buildingRequest) throws DownloadException, DownloadNotFoundException {
DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
jarCoordinate.setGroupId(groupId);
jarCoordinate.setArtifactId(artifactId);
jarCoordinate.setVersion(version);
try {
return artifactResolver.resolveArtifact(buildingRequest, jarCoordinate).getArtifact().getFile();
} catch (ArtifactResolverException e) {
throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
}
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class AbstractChangesReport method getSkinArtifactFile.
private File getSkinArtifactFile() throws MojoExecutionException {
Skin skin = Skin.getDefaultSkin();
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(skin.getGroupId());
coordinate.setArtifactId(skin.getArtifactId());
coordinate.setVersion(skin.getVersion());
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(mavenSession.getProjectBuildingRequest());
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
try {
return resolver.resolveArtifact(pbr, coordinate).getArtifact().getFile();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't resolve the skin.", 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, List<Dependency> dependencies, 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());
for (Dependency dependency : dependencies) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(dependency.getGroupId());
coordinate.setArtifactId(dependency.getArtifactId());
coordinate.setVersion(dependency.getVersion());
coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
try {
Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
if (artifactFilter.include(artifact)) {
resolvedArtifacts.add(artifact);
}
} catch (ArtifactResolverException e) {
getLog().debug("Unable to resolve artifact: " + coordinate);
}
}
return resolvedArtifacts;
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.
the class AbstractFromConfigurationMojo method getArtifact.
/**
* Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
* from the dependency list or from the DependencyManagement section of the pom.
*
* @param artifactItem containing information about artifact from plugin configuration.
* @return Artifact object representing the specified file.
* @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
Artifact artifact;
try {
// mdep-50 - rolledback for now because it's breaking some functionality.
/*
* List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
* ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
* .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
* artifactMetadataSource, null, listeners ); Iterator iter =
* artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
* ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
*/
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
if (localRepositoryDirectory != null) {
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
}
// Map dependency to artifact coordinate
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifactItem.getGroupId());
coordinate.setArtifactId(artifactItem.getArtifactId());
coordinate.setVersion(artifactItem.getVersion());
coordinate.setClassifier(artifactItem.getClassifier());
final String extension;
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
if (artifactHandler != null) {
extension = artifactHandler.getExtension();
} else {
extension = artifactItem.getType();
}
coordinate.setExtension(extension);
artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Unable to find/resolve artifact.", e);
}
return artifact;
}
use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins 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