1 package org.apache.maven.repository.metadata;
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.ArtifactScopeEnum;
23 import org.codehaus.plexus.PlexusContainer;
24 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
25
26
27
28
29
30
31
32 public class MetadataResolutionResult
33 {
34 MetadataTreeNode treeRoot;
35
36
37
38
39
40 ClasspathTransformation classpathTransformation;
41 GraphConflictResolver conflictResolver;
42
43
44 public MetadataResolutionResult( )
45 {
46 }
47
48 public MetadataResolutionResult( MetadataTreeNode root )
49 {
50 this.treeRoot = root;
51 }
52
53 public MetadataTreeNode getTree()
54 {
55 return treeRoot;
56 }
57
58 public void setTree( MetadataTreeNode root )
59 {
60 this.treeRoot = root;
61 }
62
63 public void initTreeProcessing( PlexusContainer plexus )
64 throws ComponentLookupException
65 {
66 classpathTransformation = (ClasspathTransformation) plexus.lookup( ClasspathTransformation.class );
67 conflictResolver = (GraphConflictResolver) plexus.lookup( GraphConflictResolver.class );
68 }
69
70 public MetadataGraph getGraph()
71 throws MetadataResolutionException
72 {
73 return treeRoot == null ? null : new MetadataGraph( treeRoot );
74 }
75
76 public MetadataGraph getGraph( ArtifactScopeEnum scope )
77 throws MetadataResolutionException, GraphConflictResolutionException
78 {
79 if ( treeRoot == null )
80 {
81 return null;
82 }
83
84 if ( conflictResolver == null )
85 {
86 return null;
87 }
88
89 return conflictResolver.resolveConflicts( getGraph(), scope );
90 }
91
92 public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType )
93 throws MetadataResolutionException, GraphConflictResolutionException
94 {
95 if ( requestType == null )
96 {
97 return null;
98 }
99
100 if ( treeRoot == null )
101 {
102 return null;
103 }
104
105 if ( conflictResolver == null )
106 {
107 return null;
108 }
109
110 if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathCompile ) )
111 {
112 return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.compile );
113 }
114 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
115 {
116 return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.runtime );
117 }
118 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
119 {
120 return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
121 }
122 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) )
123 {
124 return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
125 }
126 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.graph ) )
127 {
128 return getGraph();
129 }
130 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.versionedGraph ) )
131 {
132 return new MetadataGraph( getTree(), true, false );
133 }
134 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.scopedGraph ) )
135 {
136 return new MetadataGraph( getTree(), true, true );
137 }
138 return null;
139 }
140
141 public ClasspathContainer getClasspath( ArtifactScopeEnum scope )
142 throws MetadataGraphTransformationException, MetadataResolutionException
143 {
144 if ( classpathTransformation == null )
145 {
146 return null;
147 }
148
149 MetadataGraph dirtyGraph = getGraph();
150 if ( dirtyGraph == null )
151 {
152 return null;
153 }
154
155 return classpathTransformation.transform( dirtyGraph, scope, false );
156 }
157
158
159 public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope )
160 throws MetadataGraphTransformationException, MetadataResolutionException
161 {
162 ClasspathContainer cpc = getClasspath( scope );
163 if ( cpc == null )
164 {
165 return null;
166 }
167
168 return cpc.getClasspathAsTree();
169 }
170
171
172 }