1 package org.apache.maven.shared.dependency.graph.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
23 import org.apache.maven.project.MavenProject;
24 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
25 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
26 import org.apache.maven.shared.dependency.graph.DependencyNode;
27 import org.codehaus.plexus.PlexusConstants;
28 import org.codehaus.plexus.PlexusContainer;
29 import org.codehaus.plexus.component.annotations.Component;
30 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
31 import org.codehaus.plexus.context.Context;
32 import org.codehaus.plexus.context.ContextException;
33 import org.codehaus.plexus.logging.AbstractLogEnabled;
34 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
35
36
37
38
39
40
41
42
43
44
45 @Component( role = DependencyGraphBuilder.class )
46 public class DefaultDependencyGraphBuilder
47 extends AbstractLogEnabled
48 implements DependencyGraphBuilder, Contextualizable
49 {
50 protected PlexusContainer container;
51
52 public DependencyNode buildDependencyGraph( MavenProject project, ArtifactFilter filter )
53 throws DependencyGraphBuilderException
54 {
55 try
56 {
57 String hint = isMaven2x() ? "maven2" : "maven3";
58 getLogger().debug( "building " + hint + " dependency graph for " + project.getId() );
59
60 DependencyGraphBuilder effectiveGraphBuilder =
61 (DependencyGraphBuilder) container.lookup( DependencyGraphBuilder.class.getCanonicalName(), hint );
62
63 return effectiveGraphBuilder.buildDependencyGraph( project, filter );
64 }
65 catch ( ComponentLookupException e )
66 {
67 throw new DependencyGraphBuilderException( e.getMessage(), e );
68 }
69 }
70
71
72
73
74 protected static boolean isMaven2x()
75 {
76 try
77 {
78 Class.forName( "org.apache.maven.project.DependencyResolutionRequest" );
79
80 return false;
81 }
82 catch ( ClassNotFoundException e )
83 {
84 return true;
85 }
86 }
87
88 public void contextualize( Context context )
89 throws ContextException
90 {
91 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
92 }
93 }