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