View Javadoc
1   package org.apache.maven.repository.metadata;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * This object is tinted with ClasspathTransformation and GraphConflictResolver.
28   * Get rid of them after debugging
29   *
30   * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
31   */
32  public class MetadataResolutionResult
33  {
34      MetadataTreeNode treeRoot;
35  
36      /**
37       * these components are are initialized on demand by
38       * explicit call of the initTreeProcessing()
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.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 }