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