1 package org.apache.maven.repository.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Properties;
23
24 import org.eclipse.aether.DefaultRepositorySystemSession;
25 import org.eclipse.aether.artifact.DefaultArtifactType;
26 import org.eclipse.aether.collection.DependencyGraphTransformer;
27 import org.eclipse.aether.collection.DependencyManager;
28 import org.eclipse.aether.collection.DependencySelector;
29 import org.eclipse.aether.collection.DependencyTraverser;
30 import org.eclipse.aether.impl.ArtifactDescriptorReader;
31 import org.eclipse.aether.impl.DefaultServiceLocator;
32 import org.eclipse.aether.impl.MetadataGeneratorFactory;
33 import org.eclipse.aether.impl.VersionRangeResolver;
34 import org.eclipse.aether.impl.VersionResolver;
35 import org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry;
36 import org.eclipse.aether.util.graph.manager.ClassicDependencyManager;
37 import org.eclipse.aether.util.graph.selector.AndDependencySelector;
38 import org.eclipse.aether.util.graph.selector.ExclusionDependencySelector;
39 import org.eclipse.aether.util.graph.selector.OptionalDependencySelector;
40 import org.eclipse.aether.util.graph.selector.ScopeDependencySelector;
41 import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
42 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
43 import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
44 import org.eclipse.aether.util.graph.transformer.JavaScopeDeriver;
45 import org.eclipse.aether.util.graph.transformer.JavaScopeSelector;
46 import org.eclipse.aether.util.graph.transformer.NearestVersionSelector;
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
52
53
54
55
56
57
58 public final class MavenRepositorySystemUtils
59 {
60
61 private MavenRepositorySystemUtils()
62 {
63
64 }
65
66
67
68
69
70
71
72 public static DefaultServiceLocator newServiceLocator()
73 {
74 DefaultServiceLocator locator = new DefaultServiceLocator();
75 locator.addService( ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class );
76 locator.addService( VersionResolver.class, DefaultVersionResolver.class );
77 locator.addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
78 locator.addService( MetadataGeneratorFactory.class, SnapshotMetadataGeneratorFactory.class );
79 locator.addService( MetadataGeneratorFactory.class, VersionsMetadataGeneratorFactory.class );
80 return locator;
81 }
82
83
84
85
86
87
88
89
90
91 public static DefaultRepositorySystemSession newSession()
92 {
93 DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
94
95 DependencyTraverser depTraverser = new FatArtifactTraverser();
96 session.setDependencyTraverser( depTraverser );
97
98 DependencyManager depManager = new ClassicDependencyManager();
99 session.setDependencyManager( depManager );
100
101 DependencySelector depFilter =
102 new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ),
103 new OptionalDependencySelector(), new ExclusionDependencySelector() );
104 session.setDependencySelector( depFilter );
105
106 DependencyGraphTransformer transformer =
107 new ConflictResolver( new NearestVersionSelector(), new JavaScopeSelector(),
108 new SimpleOptionalitySelector(), new JavaScopeDeriver() );
109 new ChainedDependencyGraphTransformer( transformer, new JavaDependencyContextRefiner() );
110 session.setDependencyGraphTransformer( transformer );
111
112 DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
113 stereotypes.add( new DefaultArtifactType( "pom" ) );
114 stereotypes.add( new DefaultArtifactType( "maven-plugin", "jar", "", "java" ) );
115 stereotypes.add( new DefaultArtifactType( "jar", "jar", "", "java" ) );
116 stereotypes.add( new DefaultArtifactType( "ejb", "jar", "", "java" ) );
117 stereotypes.add( new DefaultArtifactType( "ejb-client", "jar", "client", "java" ) );
118 stereotypes.add( new DefaultArtifactType( "test-jar", "jar", "tests", "java" ) );
119 stereotypes.add( new DefaultArtifactType( "javadoc", "jar", "javadoc", "java" ) );
120 stereotypes.add( new DefaultArtifactType( "java-source", "jar", "sources", "java", false, false ) );
121 stereotypes.add( new DefaultArtifactType( "war", "war", "", "java", false, true ) );
122 stereotypes.add( new DefaultArtifactType( "ear", "ear", "", "java", false, true ) );
123 stereotypes.add( new DefaultArtifactType( "rar", "rar", "", "java", false, true ) );
124 stereotypes.add( new DefaultArtifactType( "par", "par", "", "java", false, true ) );
125 session.setArtifactTypeRegistry( stereotypes );
126
127 session.setArtifactDescriptorPolicy( new SimpleArtifactDescriptorPolicy( true, true ) );
128
129
130 Properties sysProps = new Properties();
131 for ( String key : System.getProperties().stringPropertyNames() )
132 {
133 sysProps.put( key, System.getProperty( key ) );
134 }
135 session.setSystemProperties( sysProps );
136 session.setConfigProperties( sysProps );
137
138 return session;
139 }
140
141 }