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.impl.ArtifactDescriptorReader;
28 import org.eclipse.aether.impl.DefaultServiceLocator;
29 import org.eclipse.aether.impl.MetadataGeneratorFactory;
30 import org.eclipse.aether.impl.VersionRangeResolver;
31 import org.eclipse.aether.impl.VersionResolver;
32 import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
33 import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
34 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
35 import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
36 import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
37 import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
38 import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
39 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
40 import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
41 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
42 import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
43 import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
44 import org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector;
45 import org.eclipse.aether.util.graph.traverser.FatArtifactTraverser;
46 import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
47
48
49
50
51
52
53
54
55 public final class MavenRepositorySystemUtils {
56
57 private MavenRepositorySystemUtils() {
58
59 }
60
61
62
63
64
65
66
67
68 @Deprecated
69 public static DefaultServiceLocator newServiceLocator() {
70 DefaultServiceLocator locator = new DefaultServiceLocator();
71 locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
72 locator.addService(VersionResolver.class, DefaultVersionResolver.class);
73 locator.addService(VersionRangeResolver.class, DefaultVersionRangeResolver.class);
74 locator.addService(MetadataGeneratorFactory.class, SnapshotMetadataGeneratorFactory.class);
75 locator.addService(MetadataGeneratorFactory.class, VersionsMetadataGeneratorFactory.class);
76 locator.addService(ModelCacheFactory.class, DefaultModelCacheFactory.class);
77 return locator;
78 }
79
80
81
82
83
84
85
86
87
88 public static DefaultRepositorySystemSession newSession() {
89 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
90
91 DependencyTraverser depTraverser = new FatArtifactTraverser();
92 session.setDependencyTraverser(depTraverser);
93
94 DependencyManager depManager = new ClassicDependencyManager();
95 session.setDependencyManager(depManager);
96
97 DependencySelector depFilter = new AndDependencySelector(
98 new ScopeDependencySelector("test", "provided"),
99 new OptionalDependencySelector(),
100 new ExclusionDependencySelector());
101 session.setDependencySelector(depFilter);
102
103 DependencyGraphTransformer transformer = new ConflictResolver(
104 new NearestVersionSelector(), new JavaScopeSelector(),
105 new SimpleOptionalitySelector(), new JavaScopeDeriver());
106 transformer = new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
107 session.setDependencyGraphTransformer(transformer);
108
109 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
110 stereotypes.add(new DefaultArtifactType("pom"));
111 stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
112 stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
113 stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
114 stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
115 stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
116 stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
117 stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
118 stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
119 stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
120 stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
121 stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
122 session.setArtifactTypeRegistry(stereotypes);
123
124 session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
125
126 return session;
127 }
128 }