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.DefaultRepositorySystemSession;
26 import org.eclipse.aether.RepositorySystem;
27 import org.eclipse.aether.artifact.Artifact;
28 import org.eclipse.aether.artifact.DefaultArtifact;
29 import org.eclipse.aether.collection.CollectRequest;
30 import org.eclipse.aether.collection.CollectResult;
31 import org.eclipse.aether.repository.RemoteRepository;
32 import org.eclipse.aether.repository.RepositoryPolicy;
33 import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
34 import org.eclipse.aether.resolution.ArtifactDescriptorResult;
35 import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
36 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
37
38
39
40
41
42
43
44
45 public class DependencyHierarchyWithRanges {
46
47
48
49
50 public static void main(String[] args) throws Exception {
51 System.out.println("------------------------------------------------------------");
52 System.out.println(DependencyHierarchyWithRanges.class.getSimpleName());
53
54 RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args));
55
56 DefaultRepositorySystemSession session = Booter.newRepositorySystemSession(system);
57
58 session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
59 session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
60 session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
61
62
63 Artifact artifact = new DefaultArtifact("org.apache.maven.resolver.demo.mresolver345:a:1.0");
64
65 File remoteRepoBasedir = new File("src/main/remote-repository");
66
67 ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
68 descriptorRequest.setArtifact(artifact);
69 descriptorRequest.setRepositories(Collections.singletonList(new RemoteRepository.Builder(
70 "remote", "default", remoteRepoBasedir.toURI().toASCIIString())
71 .build()));
72 ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
73
74 CollectRequest collectRequest = new CollectRequest();
75 collectRequest.setRootArtifact(descriptorResult.getArtifact());
76 collectRequest.setDependencies(descriptorResult.getDependencies());
77 collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
78 collectRequest.setRepositories(descriptorRequest.getRepositories());
79
80 CollectResult collectResult = system.collectDependencies(session, collectRequest);
81
82 collectResult.getRoot().accept(Booter.DUMPER_SOUT);
83 }
84 }