1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.examples;
20
21 import java.io.File;
22 import java.util.Collections;
23
24 import org.apache.maven.resolver.examples.util.Booter;
25 import org.eclipse.aether.RepositorySystem;
26 import org.eclipse.aether.RepositorySystemSession.CloseableSession;
27 import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
28 import org.eclipse.aether.artifact.Artifact;
29 import org.eclipse.aether.artifact.DefaultArtifact;
30 import org.eclipse.aether.collection.CollectRequest;
31 import org.eclipse.aether.collection.CollectResult;
32 import org.eclipse.aether.repository.RemoteRepository;
33 import org.eclipse.aether.repository.RepositoryPolicy;
34 import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
35 import org.eclipse.aether.resolution.ArtifactDescriptorResult;
36 import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
37 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
38
39
40
41
42
43
44
45
46 public class DependencyHierarchyWithRanges {
47
48
49
50
51 public static void main(String[] args) throws Exception {
52 System.out.println("------------------------------------------------------------");
53 System.out.println(DependencyHierarchyWithRanges.class.getSimpleName());
54
55 try (RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args))) {
56 SessionBuilder sessionBuilder = Booter.newRepositorySystemSession(system);
57 sessionBuilder.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
58 sessionBuilder.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
59 sessionBuilder.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
60 try (CloseableSession session = sessionBuilder.build()) {
61
62 Artifact artifact = new DefaultArtifact("org.apache.maven.resolver.demo.mresolver345:a:1.0");
63
64 File remoteRepoBasedir = new File("src/main/remote-repository");
65
66 ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
67 descriptorRequest.setArtifact(artifact);
68 descriptorRequest.setRepositories(Collections.singletonList(new RemoteRepository.Builder(
69 "remote", "default", remoteRepoBasedir.toURI().toASCIIString())
70 .build()));
71 ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
72
73 CollectRequest collectRequest = new CollectRequest();
74 collectRequest.setRootArtifact(descriptorResult.getArtifact());
75 collectRequest.setDependencies(descriptorResult.getDependencies());
76 collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
77 collectRequest.setRepositories(descriptorRequest.getRepositories());
78
79 CollectResult collectResult = system.collectDependencies(session, collectRequest);
80
81 collectResult.getRoot().accept(Booter.DUMPER_SOUT);
82 }
83 }
84 }
85 }