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