1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.supplier;
20
21 import java.util.function.Supplier;
22
23 import org.eclipse.aether.RepositorySystem;
24 import org.eclipse.aether.RepositorySystemSession.CloseableSession;
25 import org.eclipse.aether.RepositorySystemSession.SessionBuilder;
26 import org.eclipse.aether.artifact.ArtifactTypeRegistry;
27 import org.eclipse.aether.artifact.DefaultArtifactType;
28 import org.eclipse.aether.collection.DependencyGraphTransformer;
29 import org.eclipse.aether.collection.DependencyManager;
30 import org.eclipse.aether.collection.DependencySelector;
31 import org.eclipse.aether.collection.DependencyTraverser;
32 import org.eclipse.aether.resolution.ArtifactDescriptorPolicy;
33 import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
34 import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
35 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
36 import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
37 import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
38 import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
39 import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
40 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
41 import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
42 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
43 import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
44 import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
45 import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
46 import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
47 import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
48
49 import static java.util.Objects.requireNonNull;
50
51
52
53
54
55
56
57
58
59
60 public class SessionBuilderSupplier implements Supplier<SessionBuilder> {
61 protected final RepositorySystem repositorySystem;
62
63 public SessionBuilderSupplier(RepositorySystem repositorySystem) {
64 this.repositorySystem = requireNonNull(repositorySystem);
65 }
66
67 protected void configureSessionBuilder(SessionBuilder session) {
68 session.setDependencyTraverser(getDependencyTraverser());
69 session.setDependencyManager(getDependencyManager());
70 session.setDependencySelector(getDependencySelector());
71 session.setDependencyGraphTransformer(getDependencyGraphTransformer());
72 session.setArtifactTypeRegistry(getArtifactTypeRegistry());
73 session.setArtifactDescriptorPolicy(getArtifactDescriptorPolicy());
74 }
75
76 protected DependencyTraverser getDependencyTraverser() {
77 return new FatArtifactTraverser();
78 }
79
80 protected DependencyManager getDependencyManager() {
81 return new ClassicDependencyManager();
82 }
83
84 protected DependencySelector getDependencySelector() {
85 return new AndDependencySelector(
86 new ScopeDependencySelector("test", "provided"),
87 new OptionalDependencySelector(),
88 new ExclusionDependencySelector());
89 }
90
91 protected DependencyGraphTransformer getDependencyGraphTransformer() {
92 return new ChainedDependencyGraphTransformer(
93 new ConflictResolver(
94 new NearestVersionSelector(), new JavaScopeSelector(),
95 new SimpleOptionalitySelector(), new JavaScopeDeriver()),
96 new JavaDependencyContextRefiner());
97 }
98
99 protected ArtifactTypeRegistry getArtifactTypeRegistry() {
100 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
101 stereotypes.add(new DefaultArtifactType("pom"));
102 stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
103 stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
104 stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
105 stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
106 stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
107 stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
108 stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
109 stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
110 stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
111 stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
112 stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
113 return stereotypes;
114 }
115
116 protected ArtifactDescriptorPolicy getArtifactDescriptorPolicy() {
117 return new SimpleArtifactDescriptorPolicy(true, true);
118 }
119
120
121
122
123
124
125
126
127
128
129
130 @Override
131 public SessionBuilder get() {
132 SessionBuilder builder = repositorySystem.createSessionBuilder();
133 configureSessionBuilder(builder);
134 return builder;
135 }
136 }