1 package org.apache.maven.archiva.repository.project.dependencies;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
34 * ProjectModelBasedGraphBuilder
39 * role="org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder"
40 * role-hint="project-model"
42 public class ProjectModelBasedGraphBuilder
43 implements DependencyGraphBuilder
48 private ProjectModelResolverFactory resolverFactory;
52 * role="org.apache.maven.archiva.repository.project.ProjectModelFilter"
53 * role-hint="effective"
55 private EffectiveProjectModelFilter effectiveFilter = new EffectiveProjectModelFilter();
57 public DependencyGraph createGraph( VersionedReference versionedProjectReference )
59 String groupId = versionedProjectReference.getGroupId();
60 String artifactId = versionedProjectReference.getArtifactId();
61 String version = versionedProjectReference.getVersion();
63 DependencyGraph graph = new DependencyGraph( groupId, artifactId, version );
67 public void resolveNode( DependencyGraph graph, DependencyGraphNode fromNode,
68 VersionedReference versionedProjectReference )
70 ArchivaProjectModel model = resolveModel( fromNode.getArtifact() );
72 DependencyGraphUtils.addNodeFromModel( model, graph, fromNode );
75 private ArchivaProjectModel resolveModel( ArtifactReference reference )
77 VersionedReference projectRef = new VersionedReference();
79 projectRef.setGroupId( reference.getGroupId() );
80 projectRef.setArtifactId( reference.getArtifactId() );
81 projectRef.setVersion( reference.getVersion() );
83 ArchivaProjectModel model = resolverFactory.getCurrentResolverStack().findProject( projectRef );
87 return createDefaultModel( reference );
92 ArchivaProjectModel processedModel = effectiveFilter.filter( model );
94 return processedModel;
96 catch ( ProjectModelException e )
98 e.printStackTrace( System.err );
99 return createDefaultModel( reference );
103 private ArchivaProjectModel createDefaultModel( ArtifactReference reference )
105 ArchivaProjectModel model = new ArchivaProjectModel();
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() );