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.artifact.DefaultArtifactType;
23 import org.eclipse.aether.collection.DependencyGraphTransformer;
24 import org.eclipse.aether.collection.DependencyManager;
25 import org.eclipse.aether.collection.DependencySelector;
26 import org.eclipse.aether.collection.DependencyTraverser;
27 import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
28 import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
29 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
30 import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
31 import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
32 import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
33 import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
34 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
35 import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
36 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
37 import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
38 import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
39 import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
40 import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
41 import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
42
43
44
45
46
47
48
49
50 public final class MavenRepositorySystemUtils {
51
52 private MavenRepositorySystemUtils() {
53
54 }
55
56
57
58
59
60
61
62
63
64 public static DefaultRepositorySystemSession newSession() {
65 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
66
67 DependencyTraverser depTraverser = new FatArtifactTraverser();
68 session.setDependencyTraverser(depTraverser);
69
70 DependencyManager depManager = new ClassicDependencyManager();
71 session.setDependencyManager(depManager);
72
73 DependencySelector depFilter = new AndDependencySelector(
74 new ScopeDependencySelector("test", "provided"),
75 new OptionalDependencySelector(),
76 new ExclusionDependencySelector());
77 session.setDependencySelector(depFilter);
78
79 DependencyGraphTransformer transformer = new ConflictResolver(
80 new NearestVersionSelector(), new JavaScopeSelector(),
81 new SimpleOptionalitySelector(), new JavaScopeDeriver());
82 transformer = new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
83 session.setDependencyGraphTransformer(transformer);
84
85 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
86 stereotypes.add(new DefaultArtifactType("pom"));
87 stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
88 stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
89 stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
90 stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
91 stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
92 stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
93 stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
94 stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
95 stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
96 stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
97 stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
98 session.setArtifactTypeRegistry(stereotypes);
99
100 session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
101
102 return session;
103 }
104 }