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