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 = plexus.lookup( ClasspathTransformation.class );
67 conflictResolver = 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.graph ) )
123 {
124 return getGraph();
125 }
126 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.versionedGraph ) )
127 {
128 return new MetadataGraph( getTree(), true, false );
129 }
130 else if ( requestType.equals( MetadataResolutionRequestTypeEnum.scopedGraph ) )
131 {
132 return new MetadataGraph( getTree(), true, true );
133 }
134 return null;
135 }
136
137 public ClasspathContainer getClasspath( ArtifactScopeEnum scope )
138 throws MetadataGraphTransformationException, MetadataResolutionException
139 {
140 if ( classpathTransformation == null )
141 {
142 return null;
143 }
144
145 MetadataGraph dirtyGraph = getGraph();
146 if ( dirtyGraph == null )
147 {
148 return null;
149 }
150
151 return classpathTransformation.transform( dirtyGraph, scope, false );
152 }
153
154
155 public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope )
156 throws MetadataGraphTransformationException, MetadataResolutionException
157 {
158 ClasspathContainer cpc = getClasspath( scope );
159 if ( cpc == null )
160 {
161 return null;
162 }
163
164 return cpc.getClasspathAsTree();
165 }
166
167
168 }