]> source.dussan.org Git - archiva.git/blob
cc47e1aa69ecb4d23f2574250c966a075eccb7ad
[archiva.git] /
1 package org.apache.maven.archiva.repository.project.dependencies;
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.archiva.dependency.graph.DependencyGraph;
23 import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
24 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
25 import org.apache.maven.archiva.dependency.graph.DependencyGraphUtils;
26 import org.apache.maven.archiva.model.ArchivaProjectModel;
27 import org.apache.maven.archiva.model.ArtifactReference;
28 import org.apache.maven.archiva.model.VersionedReference;
29 import org.apache.maven.archiva.repository.project.ProjectModelException;
30 import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory;
31 import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelFilter;
32
33 /**
34  * ProjectModelBasedGraphBuilder 
35  *
36  * @version $Id$
37  * 
38  * @plexus.component 
39  *              role="org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder"
40  *              role-hint="project-model"
41  */
42 public class ProjectModelBasedGraphBuilder
43     implements DependencyGraphBuilder
44 {
45     /**
46      * @plexus.requirement
47      */
48     private ProjectModelResolverFactory resolverFactory;
49
50     /**
51      * @plexus.requirement 
52      *          role="org.apache.maven.archiva.repository.project.ProjectModelFilter"
53      *          role-hint="effective"
54      */
55     private EffectiveProjectModelFilter effectiveFilter = new EffectiveProjectModelFilter();
56
57     public DependencyGraph createGraph( VersionedReference versionedProjectReference )
58     {
59         String groupId = versionedProjectReference.getGroupId();
60         String artifactId = versionedProjectReference.getArtifactId();
61         String version = versionedProjectReference.getVersion();
62
63         DependencyGraph graph = new DependencyGraph( groupId, artifactId, version );
64         return graph;
65     }
66
67     public void resolveNode( DependencyGraph graph, DependencyGraphNode fromNode,
68                              VersionedReference versionedProjectReference )
69     {
70         ArchivaProjectModel model = resolveModel( fromNode.getArtifact() );
71
72         DependencyGraphUtils.addNodeFromModel( model, graph, fromNode );
73     }
74
75     private ArchivaProjectModel resolveModel( ArtifactReference reference )
76     {
77         VersionedReference projectRef = new VersionedReference();
78
79         projectRef.setGroupId( reference.getGroupId() );
80         projectRef.setArtifactId( reference.getArtifactId() );
81         projectRef.setVersion( reference.getVersion() );
82
83         ArchivaProjectModel model = resolverFactory.getCurrentResolverStack().findProject( projectRef );
84
85         if ( model == null )
86         {
87             return createDefaultModel( reference );
88         }
89
90         try
91         {
92             ArchivaProjectModel processedModel = effectiveFilter.filter( model );
93
94             return processedModel;
95         }
96         catch ( ProjectModelException e )
97         {
98             e.printStackTrace( System.err );
99             return createDefaultModel( reference );
100         }
101     }
102
103     private ArchivaProjectModel createDefaultModel( ArtifactReference reference )
104     {
105         ArchivaProjectModel model = new ArchivaProjectModel();
106
107         // Create default (dummy) model
108         model = new ArchivaProjectModel();
109         model.setGroupId( reference.getGroupId() );
110         model.setArtifactId( reference.getArtifactId() );
111         model.setVersion( reference.getVersion() );
112         model.setPackaging( reference.getType() );
113         return model;
114     }
115 }