use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins 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;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class GetMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
if (coordinate.getArtifactId() == null && artifact == null) {
throw new MojoFailureException("You must specify an artifact, " + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0");
}
if (artifact != null) {
String[] tokens = StringUtils.split(artifact, ":");
if (tokens.length < 3 || tokens.length > 5) {
throw new MojoFailureException("Invalid artifact, you must specify " + "groupId:artifactId:version[:packaging[:classifier]] " + artifact);
}
coordinate.setGroupId(tokens[0]);
coordinate.setArtifactId(tokens[1]);
coordinate.setVersion(tokens[2]);
if (tokens.length >= 4) {
coordinate.setType(tokens[3]);
}
if (tokens.length == 5) {
coordinate.setClassifier(tokens[4]);
}
}
ArtifactRepositoryPolicy always = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
List<ArtifactRepository> repoList = new ArrayList<ArtifactRepository>();
if (pomRemoteRepositories != null) {
repoList.addAll(pomRemoteRepositories);
}
if (remoteRepositories != null) {
// Use the same format as in the deploy plugin id::layout::url
List<String> repos = Arrays.asList(StringUtils.split(remoteRepositories, ","));
for (String repo : repos) {
repoList.add(parseRepository(repo, always));
}
}
try {
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(repoList);
if (transitive) {
getLog().info("Resolving " + coordinate + " with transitive dependencies");
dependencyResolver.resolveDependencies(buildingRequest, coordinate, null);
} else {
getLog().info("Resolving " + coordinate);
artifactResolver.resolveArtifact(buildingRequest, toArtifactCoordinate(coordinate));
}
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
} catch (DependencyResolverException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
}
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class DefaultDependencyResolverTest method test_getDependencySetResolutionRequirements.
public void test_getDependencySetResolutionRequirements() throws DependencyResolutionException {
final DependencySet ds1 = new DependencySet();
ds1.setScope(Artifact.SCOPE_COMPILE);
ds1.setUseTransitiveDependencies(false);
final DependencySet ds2 = new DependencySet();
ds2.setScope(Artifact.SCOPE_SYSTEM);
ds2.setUseTransitiveDependencies(false);
final MavenProject project = createMavenProject("main-group", "main-artifact", "1", null);
final ResolutionManagementInfo info = new ResolutionManagementInfo(project);
final Assembly assembly = new Assembly();
ProjectBuildingRequest buildingRequest = newMavenSession(project).getProjectBuildingRequest();
resolver.updateDependencySetResolutionRequirements(ds1, info, AssemblyId.createAssemblyId(assembly), buildingRequest, project);
assertTrue(info.isResolutionRequired());
assertFalse(info.isResolvedTransitively());
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_COMPILE));
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_SYSTEM));
assertTrue(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_PROVIDED));
assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_RUNTIME));
assertFalse(info.getScopeFilter().getIncluded().contains(Artifact.SCOPE_TEST));
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class CopyDependenciesMojo method getResolvedPomArtifact.
protected Artifact getResolvedPomArtifact(Artifact artifact) {
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifact.getGroupId());
coordinate.setArtifactId(artifact.getArtifactId());
coordinate.setVersion(artifact.getVersion());
coordinate.setExtension("pom");
Artifact pomArtifact = null;
// Resolve the pom artifact using repos
try {
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
pomArtifact = getArtifactResolver().resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
getLog().info(e.getMessage());
}
return pomArtifact;
}
use of org.apache.maven.project.ProjectBuildingRequest in project maven-plugins by apache.
the class TreeMojo method execute.
// Mojo methods -----------------------------------------------------------
/*
* @see org.apache.maven.plugin.Mojo#execute()
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().info("Skipping plugin execution");
return;
}
try {
String dependencyTreeString;
// TODO: note that filter does not get applied due to MSHARED-4
ArtifactFilter artifactFilter = createResolvingArtifactFilter();
if (verbose) {
// To fix we probably need a different DependencyCollector in Aether, which doesn't remove nodes which
// have already been resolved.
getLog().info("Verbose not supported since maven-dependency-plugin 3.0");
}
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setProject(project);
// non-verbose mode use dependency graph component, which gives consistent results with Maven version
// running
rootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, artifactFilter, reactorProjects);
dependencyTreeString = serializeDependencyTree(rootNode);
if (outputFile != null) {
DependencyUtil.write(dependencyTreeString, outputFile, this.appendOutput, getLog());
getLog().info("Wrote dependency tree to: " + outputFile);
} else {
DependencyUtil.log(dependencyTreeString, getLog());
}
} catch (DependencyGraphBuilderException exception) {
throw new MojoExecutionException("Cannot build project dependency graph", exception);
} catch (IOException exception) {
throw new MojoExecutionException("Cannot serialise project dependency graph", exception);
}
}
Aggregations