use of org.sonatype.aether.collection.DependencyCollectionException in project karaf by apache.
the class Dependency30Helper method getDependencyTree.
private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
try {
CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
session.setDependencyGraphTransformer(transformer);
CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
return result.getRoot();
} catch (DependencyCollectionException e) {
throw new MojoExecutionException("Cannot build project dependency tree", e);
}
}
use of org.sonatype.aether.collection.DependencyCollectionException in project archiva by apache.
the class Maven3DependencyTreeBuilder method resolve.
private void resolve(ResolveRequest resolveRequest) {
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system, resolveRequest.localRepoDir);
org.sonatype.aether.artifact.Artifact artifact = new DefaultArtifact(resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
// add remote repositories
for (RemoteRepository remoteRepository : resolveRequest.remoteRepositories) {
collectRequest.addRepository(new org.sonatype.aether.repository.RemoteRepository(remoteRepository.getId(), "default", remoteRepository.getUrl()));
}
collectRequest.setRequestContext("project");
try {
CollectResult collectResult = system.collectDependencies(session, collectRequest);
collectResult.getRoot().accept(resolveRequest.dependencyVisitor);
log.debug("test");
} catch (DependencyCollectionException e) {
log.error(e.getMessage(), e);
}
}
use of org.sonatype.aether.collection.DependencyCollectionException in project sonatype-aether by sonatype.
the class DefaultDependencyCollector method collectDependencies.
public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException {
session = optimizeSession(session);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
CollectResult result = new CollectResult(request);
DependencySelector depSelector = session.getDependencySelector();
DependencyManager depManager = session.getDependencyManager();
DependencyTraverser depTraverser = session.getDependencyTraverser();
Dependency root = request.getRoot();
List<RemoteRepository> repositories = request.getRepositories();
List<Dependency> dependencies = request.getDependencies();
List<Dependency> managedDependencies = request.getManagedDependencies();
GraphEdge edge = null;
if (root != null) {
VersionRangeResult rangeResult;
try {
VersionRangeRequest rangeRequest = new VersionRangeRequest(root.getArtifact(), request.getRepositories(), request.getRequestContext());
rangeRequest.setTrace(trace);
rangeResult = versionRangeResolver.resolveVersionRange(session, rangeRequest);
if (rangeResult.getVersions().isEmpty()) {
throw new VersionRangeResolutionException(rangeResult, "No versions available for " + root.getArtifact() + " within specified range");
}
} catch (VersionRangeResolutionException e) {
result.addException(e);
throw new DependencyCollectionException(result);
}
Version version = rangeResult.getVersions().get(rangeResult.getVersions().size() - 1);
root = root.setArtifact(root.getArtifact().setVersion(version.toString()));
ArtifactDescriptorResult descriptorResult;
try {
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(root.getArtifact());
descriptorRequest.setRepositories(request.getRepositories());
descriptorRequest.setRequestContext(request.getRequestContext());
descriptorRequest.setTrace(trace);
if (isLackingDescriptor(root.getArtifact())) {
descriptorResult = new ArtifactDescriptorResult(descriptorRequest);
} else {
descriptorResult = descriptorReader.readArtifactDescriptor(session, descriptorRequest);
}
} catch (ArtifactDescriptorException e) {
result.addException(e);
throw new DependencyCollectionException(result);
}
root = root.setArtifact(descriptorResult.getArtifact());
repositories = remoteRepositoryManager.aggregateRepositories(session, repositories, descriptorResult.getRepositories(), true);
dependencies = mergeDeps(dependencies, descriptorResult.getDependencies());
managedDependencies = mergeDeps(managedDependencies, descriptorResult.getManagedDependencies());
GraphNode node = new GraphNode();
node.setAliases(descriptorResult.getAliases());
node.setRepositories(request.getRepositories());
edge = new GraphEdge(node);
edge.setDependency(root);
edge.setRequestContext(request.getRequestContext());
edge.setRelocations(descriptorResult.getRelocations());
edge.setVersionConstraint(rangeResult.getVersionConstraint());
edge.setVersion(version);
} else {
edge = new GraphEdge(new GraphNode());
}
result.setRoot(edge);
boolean traverse = (root == null) || depTraverser.traverseDependency(root);
if (traverse && !dependencies.isEmpty()) {
DataPool pool = new DataPool(session);
EdgeStack edges = new EdgeStack();
edges.push(edge);
DefaultDependencyCollectionContext context = new DefaultDependencyCollectionContext(session, root, managedDependencies);
Args args = new Args(result, session, trace, pool, edges, context);
process(args, dependencies, repositories, depSelector.deriveChildSelector(context), depManager.deriveChildManager(context), depTraverser.deriveChildTraverser(context));
}
DependencyGraphTransformer transformer = session.getDependencyGraphTransformer();
try {
DefaultDependencyGraphTransformationContext context = new DefaultDependencyGraphTransformationContext(session);
result.setRoot(transformer.transformGraph(edge, context));
} catch (RepositoryException e) {
result.addException(e);
}
if (!result.getExceptions().isEmpty()) {
throw new DependencyCollectionException(result);
}
return result;
}
use of org.sonatype.aether.collection.DependencyCollectionException in project sonatype-aether by sonatype.
the class DefaultRepositorySystem method resolveDependencies.
public DependencyResult resolveDependencies(RepositorySystemSession session, DependencyRequest request) throws DependencyResolutionException {
validateSession(session);
RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
DependencyResult result = new DependencyResult(request);
DependencyCollectionException dce = null;
ArtifactResolutionException are = null;
if (request.getRoot() != null) {
result.setRoot(request.getRoot());
} else if (request.getCollectRequest() != null) {
CollectResult collectResult;
try {
request.getCollectRequest().setTrace(trace);
collectResult = dependencyCollector.collectDependencies(session, request.getCollectRequest());
} catch (DependencyCollectionException e) {
dce = e;
collectResult = e.getResult();
}
result.setRoot(collectResult.getRoot());
result.setCollectExceptions(collectResult.getExceptions());
} else {
throw new IllegalArgumentException("dependency node or collect request missing");
}
ArtifactRequestBuilder builder = new ArtifactRequestBuilder(trace);
DependencyFilter filter = request.getFilter();
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
visitor = new TreeDependencyVisitor(visitor);
result.getRoot().accept(visitor);
List<ArtifactRequest> requests = builder.getRequests();
List<ArtifactResult> results;
try {
results = artifactResolver.resolveArtifacts(session, requests);
} catch (ArtifactResolutionException e) {
are = e;
results = e.getResults();
}
result.setArtifactResults(results);
updateNodesWithResolvedArtifacts(results);
if (dce != null) {
throw new DependencyResolutionException(result, dce);
} else if (are != null) {
throw new DependencyResolutionException(result, are);
}
return result;
}
use of org.sonatype.aether.collection.DependencyCollectionException in project sonatype-aether by sonatype.
the class DefaultDependencyCollectorTest method testMissingDependencyDescription.
@Test
public void testMissingDependencyDescription() throws IOException {
DependencyNode root = parser.parseLiteral("missing:description:ext:ver");
CollectRequest request = new CollectRequest(root.getDependency(), Arrays.asList(repository));
try {
collector.collectDependencies(session, request);
fail("expected exception");
} catch (DependencyCollectionException e) {
CollectResult result = e.getResult();
assertSame(request, result.getRequest());
assertNotNull(result.getExceptions());
assertEquals(1, result.getExceptions().size());
assertTrue(result.getExceptions().get(0) instanceof ArtifactDescriptorException);
assertEquals(request.getRoot(), result.getRoot().getDependency());
}
}
Aggregations