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.ConfigurableVersionSelector;
43 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
44 import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
45 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
46 import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
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.setSystemProperties(System.getProperties());
73 session.setDependencyTraverser(getDependencyTraverser());
74 session.setDependencyManager(getDependencyManager());
75 session.setDependencySelector(getDependencySelector());
76 session.setDependencyGraphTransformer(getDependencyGraphTransformer());
77 session.setArtifactTypeRegistry(getArtifactTypeRegistry());
78 session.setArtifactDescriptorPolicy(getArtifactDescriptorPolicy());
79 }
80
81 protected DependencyTraverser getDependencyTraverser() {
82 return new FatArtifactTraverser();
83 }
84
85 protected DependencyManager getDependencyManager() {
86 return new ClassicDependencyManager(false, null);
87 }
88
89 protected DependencySelector getDependencySelector() {
90 return new AndDependencySelector(
91 ScopeDependencySelector.legacy(null, Arrays.asList(JavaScopes.TEST, JavaScopes.PROVIDED)),
92 OptionalDependencySelector.fromDirect(),
93 new ExclusionDependencySelector());
94 }
95
96 protected DependencyGraphTransformer getDependencyGraphTransformer() {
97 return new ChainedDependencyGraphTransformer(
98 new ConflictResolver(
99 new ConfigurableVersionSelector(), new JavaScopeSelector(),
100 new SimpleOptionalitySelector(), new JavaScopeDeriver()),
101 new JavaDependencyContextRefiner());
102 }
103
104 protected ArtifactTypeRegistry getArtifactTypeRegistry() {
105 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
106 stereotypes.add(new DefaultArtifactType("pom"));
107 stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
108 stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
109 stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
110 stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
111 stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
112 stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
113 stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
114 stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
115 stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
116 stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
117 stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
118 return stereotypes;
119 }
120
121 protected ArtifactDescriptorPolicy getArtifactDescriptorPolicy() {
122 return new SimpleArtifactDescriptorPolicy(true, true);
123 }
124
125
126
127
128
129
130
131
132
133
134
135 @Override
136 public SessionBuilder get() {
137 SessionBuilder builder = repositorySystem.createSessionBuilder();
138 configureSessionBuilder(builder);
139 return builder;
140 }
141 }