1 package org.apache.maven.archiva.dependency.graph.tasks;
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.commons.collections.iterators.ReverseListIterator;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
25 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
26 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
27 import org.apache.maven.archiva.model.ArtifactReference;
28 import org.apache.maven.archiva.model.Dependency;
29 import org.apache.maven.archiva.model.Exclusion;
31 import java.util.HashMap;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.List;
37 import java.util.Stack;
40 * DependencyManagementStack
44 public class DependencyManagementStack
48 public ArtifactReference artifact;
52 public Set exclusions = new HashSet();
54 public void addAllExclusions( List depExclusions )
56 Iterator it = depExclusions.iterator();
57 while ( it.hasNext() )
59 Exclusion ref = (Exclusion) it.next();
60 String key = DependencyGraphKeys.toManagementKey( ref );
61 exclusions.add( key );
66 private Stack depmanStack = new Stack();
68 private Map depMap = new HashMap();
70 private void generateDepMap()
74 // Using a reverse iterator to ensure that we read the
75 // stack from last in to first in
76 ReverseListIterator it = new ReverseListIterator( depmanStack );
77 while ( it.hasNext() )
79 DependencyGraphNode node = (DependencyGraphNode) it.next();
81 addDependencies( node.getDependencyManagement() );
85 private void addDependencies( List dependencies )
87 Iterator it = dependencies.iterator();
88 while ( it.hasNext() )
90 Dependency dep = (Dependency) it.next();
91 String key = DependencyGraphKeys.toManagementKey( dep );
93 Rules merged = (Rules) depMap.get( key );
98 merged.artifact = new ArtifactReference();
99 merged.artifact.setGroupId( dep.getGroupId() );
100 merged.artifact.setArtifactId( dep.getArtifactId() );
101 merged.artifact.setClassifier( dep.getClassifier() );
102 merged.artifact.setType( dep.getType() );
105 merged.artifact.setVersion( dep.getVersion() );
106 if ( StringUtils.isNotBlank( dep.getScope() ) )
108 merged.scope = dep.getScope();
111 merged.addAllExclusions( dep.getExclusions() );
113 depMap.put( key, merged );
117 public Rules getRules( DependencyGraphEdge edge )
119 return getRules( edge.getNodeTo() );
122 public Rules getRules( DependencyGraphNode node )
124 return getRules( node.getArtifact() );
127 public Rules getRules( ArtifactReference ref )
129 String key = DependencyGraphKeys.toManagementKey( ref );
130 return (Rules) depMap.get( key );
133 public void push( DependencyGraphNode node )
135 depmanStack.push( node );
139 public DependencyGraphNode pop()
141 DependencyGraphNode node = (DependencyGraphNode) depmanStack.pop();