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.nio.file.Path;
22 import java.nio.file.Paths;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26
27 import org.eclipse.aether.RepositorySystem;
28 import org.eclipse.aether.RepositorySystemSession;
29 import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
30 import org.eclipse.aether.repository.RemoteRepository;
31 import org.eclipse.aether.supplier.SessionBuilderSupplier;
32 import org.eclipse.aether.util.graph.visitor.DependencyGraphDumper;
33
34
35
36
37 public class Booter {
38 public static final String SUPPLIER = "supplier";
39
40 public static final String SISU = "sisu";
41
42 public static final DependencyGraphDumper DUMPER_SOUT = new DependencyGraphDumper(System.out::println);
43
44 public static String selectFactory(String[] args) {
45 if (args == null || args.length == 0) {
46 return SUPPLIER;
47 } else {
48 return args[0];
49 }
50 }
51
52 public static RepositorySystem newRepositorySystem(final String factory) {
53 switch (factory) {
54 case SUPPLIER:
55 return org.apache.maven.resolver.examples.supplier.SupplierRepositorySystemFactory
56 .newRepositorySystem();
57 case SISU:
58 return org.apache.maven.resolver.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
59 default:
60 throw new IllegalArgumentException("Unknown factory: " + factory);
61 }
62 }
63
64 public static SessionBuilder newRepositorySystemSession(RepositorySystem system) {
65 Path localRepo = Paths.get("target/local-repo");
66
67 return new SessionBuilderSupplier(system)
68 .get()
69
70 .withLocalRepositoryBaseDirectories(localRepo)
71 .setRepositoryListener(new ConsoleRepositoryListener())
72 .setTransferListener(new ConsoleTransferListener())
73 .setConfigProperty("aether.generator.gpg.enabled", Boolean.TRUE.toString())
74 .setConfigProperty(
75 "aether.generator.gpg.keyFilePath",
76 Paths.get("src/main/resources/alice.key")
77 .toAbsolutePath()
78 .toString())
79 .setConfigProperty("aether.syncContext.named.factory", "noop");
80
81
82
83
84
85
86
87
88
89
90 }
91
92 public static List<RemoteRepository> newRepositories(RepositorySystem system, RepositorySystemSession session) {
93 return new ArrayList<>(Collections.singletonList(newCentralRepository()));
94 }
95
96 private static RemoteRepository newCentralRepository() {
97 return new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2/").build();
98 }
99 }