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 SERVICE_LOCATOR = "serviceLocator";
38
39 public static final String SUPPLIER = "supplier";
40
41 public static final String GUICE = "guice";
42
43 public static final String SISU = "sisu";
44
45 public static final DependencyGraphDumper DUMPER_SOUT = new DependencyGraphDumper(System.out::println);
46
47 public static String selectFactory(String[] args) {
48 if (args == null || args.length == 0) {
49 return SUPPLIER;
50 } else {
51 return args[0];
52 }
53 }
54
55 public static RepositorySystem newRepositorySystem(final String factory) {
56 switch (factory) {
57 case SERVICE_LOCATOR:
58 return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
59 case SUPPLIER:
60 return org.apache.maven.resolver.examples.supplier.SupplierRepositorySystemFactory
61 .newRepositorySystem();
62 case GUICE:
63 return org.apache.maven.resolver.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
64 case SISU:
65 return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
66 default:
67 throw new IllegalArgumentException("Unknown factory: " + factory);
68 }
69 }
70
71 public static DefaultRepositorySystemSession newRepositorySystemSession(RepositorySystem system) {
72 DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
73
74 LocalRepository localRepo = new LocalRepository("target/local-repo");
75 session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
76
77 session.setTransferListener(new ConsoleTransferListener());
78 session.setRepositoryListener(new ConsoleRepositoryListener());
79
80
81
82
83 return session;
84 }
85
86 public static List<RemoteRepository> newRepositories(RepositorySystem system, RepositorySystemSession session) {
87 return new ArrayList<>(Collections.singletonList(newCentralRepository()));
88 }
89
90 private static RemoteRepository newCentralRepository() {
91 return new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/").build();
92 }
93 }