001 package org.apache.maven.repository.metadata;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import org.apache.maven.artifact.ArtifactScopeEnum;
023 import org.codehaus.plexus.PlexusContainer;
024 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
025
026 /**
027 * This object is tinted with ClasspathTransformation and GraphConflictResolver.
028 * Get rid of them after debugging
029 *
030 * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
031 */
032 public class MetadataResolutionResult
033 {
034 MetadataTreeNode treeRoot;
035
036 /**
037 * these components are are initialized on demand by
038 * explicit call of the initTreeProcessing()
039 */
040 ClasspathTransformation classpathTransformation;
041 GraphConflictResolver conflictResolver;
042
043 //----------------------------------------------------------------------------
044 public MetadataResolutionResult( )
045 {
046 }
047 //----------------------------------------------------------------------------
048 public MetadataResolutionResult( MetadataTreeNode root )
049 {
050 this.treeRoot = root;
051 }
052 //----------------------------------------------------------------------------
053 public MetadataTreeNode getTree()
054 {
055 return treeRoot;
056 }
057 //----------------------------------------------------------------------------
058 public void setTree( MetadataTreeNode root )
059 {
060 this.treeRoot = root;
061 }
062
063 public void initTreeProcessing( PlexusContainer plexus )
064 throws ComponentLookupException
065 {
066 classpathTransformation = (ClasspathTransformation) plexus.lookup( ClasspathTransformation.class );
067 conflictResolver = (GraphConflictResolver) plexus.lookup( GraphConflictResolver.class );
068 }
069 //----------------------------------------------------------------------------
070 public MetadataGraph getGraph()
071 throws MetadataResolutionException
072 {
073 return treeRoot == null ? null : new MetadataGraph( treeRoot );
074 }
075 //----------------------------------------------------------------------------
076 public MetadataGraph getGraph( ArtifactScopeEnum scope )
077 throws MetadataResolutionException, GraphConflictResolutionException
078 {
079 if ( treeRoot == null )
080 {
081 return null;
082 }
083
084 if ( conflictResolver == null )
085 {
086 return null;
087 }
088
089 return conflictResolver.resolveConflicts( getGraph(), scope );
090 }
091 //----------------------------------------------------------------------------
092 public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType )
093 throws MetadataResolutionException, GraphConflictResolutionException
094 {
095 if ( requestType == null )
096 {
097 return null;
098 }
099
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 }