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 public final class MavenRepositorySystemUtils {
50
51 private MavenRepositorySystemUtils() {
52
53 }
54
55
56
57
58
59
60
61
62
63 public static DefaultRepositorySystemSession newSession() {
64 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
65
66 DependencyTraverser depTraverser = new FatArtifactTraverser();
67 session.setDependencyTraverser(depTraverser);
68
69 DependencyManager depManager = new ClassicDependencyManager();
70 session.setDependencyManager(depManager);
71
72 DependencySelector depFilter = new AndDependencySelector(
73 new ScopeDependencySelector("test", "provided"),
74 new OptionalDependencySelector(),
75 new ExclusionDependencySelector());
76 session.setDependencySelector(depFilter);
77
78 DependencyGraphTransformer transformer = new ConflictResolver(
79 new NearestVersionSelector(), new JavaScopeSelector(),
80 new SimpleOptionalitySelector(), new JavaScopeDeriver());
81 transformer = new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
82 session.setDependencyGraphTransformer(transformer);
83
84 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
85 stereotypes.add(new DefaultArtifactType("pom"));
86 stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
87 stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
88 stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
89 stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
90 stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
91 stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
92 stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
93 stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
94 stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
95 stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
96 stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
97 session.setArtifactTypeRegistry(stereotypes);
98
99 session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
100
101 return session;
102 }
103 }