use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class CopyDependenciesMojo method doExecute.
/**
* Main entry into mojo. Gets the list of dependencies and iterates through calling copyArtifact.
*
* @throws MojoExecutionException with a message if an error occurs.
* @see #getDependencySets(boolean, boolean)
* @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean)
*/
@Override
protected void doExecute() throws MojoExecutionException {
DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms);
Set<Artifact> artifacts = dss.getResolvedDependencies();
if (!useRepositoryLayout) {
for (Artifact artifact : artifacts) {
copyArtifact(artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, this.stripClassifier);
}
} else {
ProjectBuildingRequest buildingRequest = getRepositoryManager().setLocalRepositoryBasedir(session.getProjectBuildingRequest(), outputDirectory);
for (Artifact artifact : artifacts) {
installArtifact(artifact, buildingRequest);
}
}
Set<Artifact> skippedArtifacts = dss.getSkippedDependencies();
for (Artifact artifact : skippedArtifacts) {
getLog().info(artifact.getId() + " already exists in destination.");
}
if (isCopyPom() && !useRepositoryLayout) {
copyPoms(getOutputDirectory(), artifacts, this.stripVersion);
// Artifacts
copyPoms(getOutputDirectory(), skippedArtifacts, this.stripVersion, this.stripClassifier);
// that already
// exist may
// not yet have
// poms
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class AbstractResolveMojo method resolveArtifactDependencies.
/**
* This method resolves all transitive dependencies of an artifact.
*
* @param artifact the artifact used to retrieve dependencies
* @return resolved set of dependencies
* @throws DependencyResolverException in case of error while resolving artifacts.
*/
protected Set<Artifact> resolveArtifactDependencies(final DependableCoordinate artifact) throws DependencyResolverException {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
Iterable<ArtifactResult> artifactResults = getDependencyResolver().resolveDependencies(buildingRequest, artifact, null);
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
for (final ArtifactResult artifactResult : artifactResults) {
artifacts.add(artifactResult.getArtifact());
}
return artifacts;
}
use of org.apache.maven.project.ProjectBuildingRequest 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.project.ProjectBuildingRequest 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;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-dependency-plugin by apache.
the class AbstractDependencyMojo method newResolveArtifactProjectBuildingRequest.
/**
* @return Returns a new ProjectBuildingRequest populated from the current session and the current project remote
* repositories, used to resolve artifacts.
*/
public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
return buildingRequest;
}
Aggregations