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.util;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
26 import org.eclipse.aether.DefaultRepositorySystemSession;
27 import org.eclipse.aether.RepositorySystem;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.repository.LocalRepository;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.eclipse.aether.util.graph.visitor.DependencyGraphDumper;
32
33
34
35
36 public class Booter {
37 public static final String SUPPLIER = "supplier";
38
39 public static final String SISU = "sisu";
40
41 public static final DependencyGraphDumper DUMPER_SOUT = new DependencyGraphDumper(System.out::println);
42
43 public static String selectFactory(String[] args) {
44 if (args == null || args.length == 0) {
45 return SUPPLIER;
46 } else {
47 return args[0];
48 }
49 }
50
51 public static RepositorySystem newRepositorySystem(final String factory) {
52 switch (factory) {
53 case SUPPLIER:
54 return org.apache.maven.resolver.examples.supplier.SupplierRepositorySystemFactory
55 .newRepositorySystem();
56 case SISU:
57 return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
58 default:
59 throw new IllegalArgumentException("Unknown factory: " + factory);
60 }
61 }
62
63 public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
64 DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
65
66 LocalRepository localRepo = new LocalRepository("target/local-repo");
67 session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
68
69 session.setTransferListener(new ConsoleTransferListener());
70 session.setRepositoryListener(new ConsoleRepositoryListener());
71
72
73
74
75 return session;
76 }
77
78 public static List<RemoteRepository> newRepositories(RepositorySystem system, RepositorySystemSession session) {
79 return new ArrayList<>(Collections.singletonList(newCentralRepository()));
80 }
81
82 private static RemoteRepository newCentralRepository() {
83 return new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/").build();
84 }
85 }