Search in sources :

Example 36 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class DependencyGraphParserTest method assertNodeProperties.

private void assertNodeProperties(DependencyNode node, String suffix) {
    assertNotNull(node);
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    if (!"".equals(dependency.getScope())) {
        assertEquals("scope" + suffix, dependency.getScope());
    }
    Artifact artifact = dependency.getArtifact();
    assertNotNull(artifact);
    assertEquals("gid" + suffix, artifact.getGroupId());
    assertEquals("aid" + suffix, artifact.getArtifactId());
    assertEquals("ext" + suffix, artifact.getExtension());
    assertEquals("ver" + suffix, artifact.getVersion());
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 37 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class ConflictMarker method mark.

private Map<DependencyNode, Object> mark(Collection<DependencyNode> nodes, Map<Object, ConflictGroup> groups) {
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>(nodes.size() + 1);
    for (DependencyNode node : nodes) {
        Dependency dependency = node.getDependency();
        if (dependency != null) {
            Object key = toKey(dependency.getArtifact());
            conflictIds.put(node, groups.get(key).keys);
        }
    }
    return conflictIds;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency)

Example 38 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class JavaDependencyContextRefiner method getClasspathScope.

private String getClasspathScope(DependencyNode node) {
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        return null;
    }
    String scope = dependency.getScope();
    if (JavaScopes.COMPILE.equals(scope) || JavaScopes.SYSTEM.equals(scope) || JavaScopes.PROVIDED.equals(scope)) {
        return JavaScopes.COMPILE;
    } else if (JavaScopes.RUNTIME.equals(scope)) {
        return JavaScopes.RUNTIME;
    } else if (JavaScopes.TEST.equals(scope)) {
        return JavaScopes.TEST;
    }
    return null;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency)

Example 39 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class GetDependencyTree method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDependencyTree.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.apache.maven:maven-aether-provider:3.0.2");
    RemoteRepository repo = Booter.newCentralRepository();
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.addRepository(repo);
    CollectResult collectResult = system.collectDependencies(session, collectRequest);
    collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ConsoleDependencyGraphDumper(demo.util.ConsoleDependencyGraphDumper) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 40 with Dependency

use of org.sonatype.aether.graph.Dependency 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;
}
Also used : DependencyManager(org.sonatype.aether.collection.DependencyManager) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) DependencyTraverser(org.sonatype.aether.collection.DependencyTraverser) Version(org.sonatype.aether.version.Version) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) VersionRangeRequest(org.sonatype.aether.resolution.VersionRangeRequest) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) VersionRangeResolutionException(org.sonatype.aether.resolution.VersionRangeResolutionException) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) CollectResult(org.sonatype.aether.collection.CollectResult) RepositoryException(org.sonatype.aether.RepositoryException) Dependency(org.sonatype.aether.graph.Dependency) DependencySelector(org.sonatype.aether.collection.DependencySelector) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException)

Aggregations

Dependency (org.sonatype.aether.graph.Dependency)45 Artifact (org.sonatype.aether.artifact.Artifact)22 Test (org.junit.Test)14 CollectRequest (org.sonatype.aether.collection.CollectRequest)14 DependencyNode (org.sonatype.aether.graph.DependencyNode)14 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 Exclusion (org.sonatype.aether.graph.Exclusion)9 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)9 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)7 ArrayList (java.util.ArrayList)5 RepositorySystem (org.sonatype.aether.RepositorySystem)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)4 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)4 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)4 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)4 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)4 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 HashMap (java.util.HashMap)2