View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.metadata;
20  
21  import org.apache.maven.artifact.ArtifactScopeEnum;
22  import org.codehaus.plexus.PlexusContainer;
23  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
24  
25  /**
26   * This object is tinted with ClasspathTransformation and GraphConflictResolver.
27   * Get rid of them after debugging
28   *
29   */
30  @Deprecated
31  public class MetadataResolutionResult {
32      MetadataTreeNode treeRoot;
33  
34      /**
35       * these components are initialized on demand by
36       * explicit call of the initTreeProcessing()
37       */
38      ClasspathTransformation classpathTransformation;
39  
40      GraphConflictResolver conflictResolver;
41  
42      // ----------------------------------------------------------------------------
43      public MetadataResolutionResult() {}
44      // ----------------------------------------------------------------------------
45      public MetadataResolutionResult(MetadataTreeNode root) {
46          this.treeRoot = root;
47      }
48      // ----------------------------------------------------------------------------
49      public MetadataTreeNode getTree() {
50          return treeRoot;
51      }
52      // ----------------------------------------------------------------------------
53      public void setTree(MetadataTreeNode root) {
54          this.treeRoot = root;
55      }
56  
57      public void initTreeProcessing(PlexusContainer plexus) throws ComponentLookupException {
58          classpathTransformation = plexus.lookup(ClasspathTransformation.class);
59          conflictResolver = plexus.lookup(GraphConflictResolver.class);
60      }
61      // ----------------------------------------------------------------------------
62      public MetadataGraph getGraph() throws MetadataResolutionException {
63          return treeRoot == null ? null : new MetadataGraph(treeRoot);
64      }
65      // ----------------------------------------------------------------------------
66      public MetadataGraph getGraph(ArtifactScopeEnum scope)
67              throws MetadataResolutionException, GraphConflictResolutionException {
68          if (treeRoot == null) {
69              return null;
70          }
71  
72          if (conflictResolver == null) {
73              return null;
74          }
75  
76          return conflictResolver.resolveConflicts(getGraph(), scope);
77      }
78      // ----------------------------------------------------------------------------
79      public MetadataGraph getGraph(MetadataResolutionRequestTypeEnum requestType)
80              throws MetadataResolutionException, GraphConflictResolutionException {
81          if (requestType == null) {
82              return null;
83          }
84  
85          if (treeRoot == null) {
86              return null;
87          }
88  
89          if (conflictResolver == null) {
90              return null;
91          }
92  
93          if (requestType.equals(MetadataResolutionRequestTypeEnum.classpathCompile)) {
94              return conflictResolver.resolveConflicts(getGraph(), ArtifactScopeEnum.compile);
95          } else if (requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime)) {
96              return conflictResolver.resolveConflicts(getGraph(), ArtifactScopeEnum.runtime);
97          } else if (requestType.equals(MetadataResolutionRequestTypeEnum.classpathTest)) {
98              return conflictResolver.resolveConflicts(getGraph(), ArtifactScopeEnum.test);
99          } else if (requestType.equals(MetadataResolutionRequestTypeEnum.graph)) {
100             return getGraph();
101         } else if (requestType.equals(MetadataResolutionRequestTypeEnum.versionedGraph)) {
102             return new MetadataGraph(getTree(), true, false);
103         } else if (requestType.equals(MetadataResolutionRequestTypeEnum.scopedGraph)) {
104             return new MetadataGraph(getTree(), true, true);
105         }
106         return null;
107     }
108     // ----------------------------------------------------------------------------
109     public ClasspathContainer getClasspath(ArtifactScopeEnum scope)
110             throws MetadataGraphTransformationException, MetadataResolutionException {
111         if (classpathTransformation == null) {
112             return null;
113         }
114 
115         MetadataGraph dirtyGraph = getGraph();
116         if (dirtyGraph == null) {
117             return null;
118         }
119 
120         return classpathTransformation.transform(dirtyGraph, scope, false);
121     }
122 
123     // ----------------------------------------------------------------------------
124     public MetadataTreeNode getClasspathTree(ArtifactScopeEnum scope)
125             throws MetadataGraphTransformationException, MetadataResolutionException {
126         ClasspathContainer cpc = getClasspath(scope);
127         if (cpc == null) {
128             return null;
129         }
130 
131         return cpc.getClasspathAsTree();
132     }
133     // ----------------------------------------------------------------------------
134     // ----------------------------------------------------------------------------
135 }