* under the License.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.archiva.dependency.graph.GraphListener;
import org.apache.maven.archiva.model.DependencyScope;
import org.apache.maven.archiva.model.VersionedReference;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
/**
* DependencyGraphFactory
*
private ReduceScopeTask taskReduceScope;
- private List listeners;
+ private List<GraphListener> listeners;
private DependencyGraphBuilder graphBuilder;
- private List tasks;
+ private List<GraphTask> tasks;
public DependencyGraphFactory()
{
- listeners = new ArrayList();
+ listeners = new ArrayList<GraphListener>();
taskFlagCyclicEdges = new FlagCyclicEdgesTask();
taskPopulateGraph = new PopulateGraphMasterTask();
taskReduceScope = new ReduceScopeTask( DependencyScope.TEST );
- tasks = new ArrayList();
+ tasks = new ArrayList<GraphTask>();
/* Take the basic graph, and expand the nodes fully, including depman.
*/
triggerGraphPhase( GraphPhaseEvent.GRAPH_NEW, null, graph );
- Iterator it = this.tasks.iterator();
- while ( it.hasNext() )
+ for ( GraphTask task : this.tasks )
{
- GraphTask task = (GraphTask) it.next();
try
{
triggerGraphPhase( GraphPhaseEvent.GRAPH_TASK_PRE, task, graph );
private void triggerGraphError( GraphTaskException e, DependencyGraph graph )
{
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
+ for ( GraphListener listener : listeners )
{
- GraphListener listener = (GraphListener) it.next();
listener.graphError( e, graph );
}
}
{
GraphPhaseEvent evt = new GraphPhaseEvent( type, task, graph );
- Iterator it = listeners.iterator();
- while ( it.hasNext() )
+ for ( GraphListener listener : listeners )
{
- GraphListener listener = (GraphListener) it.next();
listener.graphPhaseEvent( evt );
}
}
private DependencyGraphNode rootNode;
- private Set edges = new HashSet();
+ private Set<DependencyGraphEdge> edges = new HashSet<DependencyGraphEdge>();
private ListOrderedMap nodes = new ListOrderedMap();
this.rootNode = root;
}
- public Collection getEdges()
+ public Collection<DependencyGraphEdge> getEdges()
{
return edges;
}
- public Collection getNodes()
+ @SuppressWarnings("unchecked")
+ public Collection<DependencyGraphNode> getNodes()
{
return nodes.values();
}
* @param node the node to use as the 'from' side of an edge.
* @return the edges from the provided node.
*/
- public List getEdgesFrom( DependencyGraphNode node )
+ public List<DependencyGraphEdge> getEdgesFrom( DependencyGraphNode node )
{
- List ret = new ArrayList();
+ List<DependencyGraphEdge> ret = new ArrayList<DependencyGraphEdge>();
CollectionUtils.select( this.edges, new EdgeFromPredicate( node.getArtifact() ), ret );
return ret;
}
* @param node the node to use as the 'to' side of an edge.
* @return the edges to the provided node.
*/
- public List getEdgesTo( DependencyGraphNode node )
+ public List<DependencyGraphEdge> getEdgesTo( DependencyGraphNode node )
{
- List ret = new ArrayList();
+ List<DependencyGraphEdge> ret = new ArrayList<DependencyGraphEdge>();
CollectionUtils.select( this.edges, new EdgeToPredicate( node.getArtifact() ), ret );
return ret;
}
public void removeNode( DependencyGraphNode node )
{
- List edges = getEdgesFrom( node );
+ List<DependencyGraphEdge> edges = getEdgesFrom( node );
if ( !edges.isEmpty() )
{
System.out.println( "Removing node left <" + edges + "> hanging <from> edges." );
/**
* The project level dependency management section for this artifact.
*/
- private List dependencyManagement = new ArrayList();
+ private List<Dependency> dependencyManagement = new ArrayList<Dependency>();
/**
* The list of excluded groupId:artifactId for this node's sub-nodes.
*/
- private Set excludes = new HashSet();
+ private Set<String> excludes = new HashSet<String>();
/**
* Flag indicating that this node has been resolved from disk.
return artifact;
}
- public List getDependencyManagement()
+ public List<Dependency> getDependencyManagement()
{
return dependencyManagement;
}
- public Set getExcludes()
+ public Set<String> getExcludes()
{
return excludes;
}
this.conflicted = conflicted;
}
- public void setDependencyManagement( List dependencyManagement )
+ public void setDependencyManagement( List<Dependency> dependencyManagement )
{
this.dependencyManagement = dependencyManagement;
}
- public void setExcludes( Set excludes )
+ public void setExcludes( Set<String> excludes )
{
this.excludes = excludes;
}
* under the License.
*/
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.functors.AndPredicate;
import org.apache.maven.archiva.model.Exclusion;
import org.apache.maven.archiva.model.VersionedReference;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
/**
* Utilities for manipulating the DependencyGraph.
*
boolean isRootNode = graph.getRootNode().equals( fromNode );
- Iterator it;
-
if ( CollectionUtils.isNotEmpty( model.getDependencyManagement() ) )
{
- it = model.getDependencyManagement().iterator();
- while ( it.hasNext() )
+ for ( Dependency dependency : model.getDependencyManagement() )
{
- Dependency dependency = (Dependency) it.next();
fromNode.addDependencyManagement( dependency );
}
}
if ( CollectionUtils.isNotEmpty( model.getDependencies() ) )
{
- it = model.getDependencies().iterator();
- while ( it.hasNext() )
+ for ( Dependency dependency : model.getDependencies() )
{
- Dependency dependency = (Dependency) it.next();
-
String scope = dependency.getScope();
// Test scopes *NOT* from root node can be skipped.
if ( CollectionUtils.isNotEmpty( dependency.getExclusions() ) )
{
- Iterator itexclusion = dependency.getExclusions().iterator();
- while ( itexclusion.hasNext() )
+ for ( Exclusion exclusion : dependency.getExclusions() )
{
- Exclusion exclusion = (Exclusion) itexclusion.next();
toNode.addExclude( exclusion );
}
}
}
// Remove edges FROM orphaned node.
- List edgesFrom = graph.getEdgesFrom( orphanedNode );
-
- Iterator it = edgesFrom.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : graph.getEdgesFrom( orphanedNode ) )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
graph.removeEdge( edge );
}
*/
public static void collapseNodes( DependencyGraph graph, DependencyGraphNode nodeFROM, DependencyGraphNode nodeTO )
{
- Iterator it;
-
- Set edgesToRemove = new HashSet();
+ Set<DependencyGraphEdge> edgesToRemove = new HashSet<DependencyGraphEdge>();
// 1) Remove all of the edge.from references from nodeFROM
- List fromEdges = graph.getEdgesFrom( nodeFROM );
+ List<DependencyGraphEdge> fromEdges = graph.getEdgesFrom( nodeFROM );
if ( CollectionUtils.isNotEmpty( fromEdges ) )
{
edgesToRemove.addAll( fromEdges );
// 2) Swing all of the edge.to references from nodeFROM to nodeTO.
// System.out.println( "Swinging incoming edges from " + nodeFROM );
// System.out.println( " to " + nodeTO );
- List toEdges = graph.getEdgesTo( nodeFROM );
- it = toEdges.iterator();
- while ( it.hasNext() )
+ List<DependencyGraphEdge> toEdges = graph.getEdgesTo( nodeFROM );
+ for ( DependencyGraphEdge edge : toEdges )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
-
// Identify old edge to remove.
edgesToRemove.add( edge );
}
// Actually remove the old edges.
- it = edgesToRemove.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : edgesToRemove )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
graph.removeEdge( edge );
}
* under the License.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.model.VersionedReference;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
/**
* Takes a stack of DependencyManagement objects and applies them to the node in question.
* This merely sets the version / scope / and exclusions on the nodes, as defined by DependencyManagement.
* Performing graph changes of this scope during a walk of graph is hazardous,
* as you will be moving nodes around, mergeing nodes, dropping edges, etc.
*/
- private Map nodeVersionChanges = new HashMap();
+ private Map<ArtifactReference, String> nodeVersionChanges = new HashMap<ArtifactReference, String>();
private int nodesAdded = 0;
depStack.push( node );
- List edgesFrom = graph.getEdgesFrom( node );
- Iterator it = edgesFrom.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : graph.getEdgesFrom( node ) )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
Rules rules = depStack.getRules( edge );
if ( rules == null )
{
super.finishGraph( graph );
- Iterator it = this.nodeVersionChanges.keySet().iterator();
- while ( it.hasNext() )
+ for ( ArtifactReference ref : this.nodeVersionChanges.keySet() )
{
- ArtifactReference ref = (ArtifactReference) it.next();
- String toVersion = (String) this.nodeVersionChanges.get( ref );
+ String toVersion = this.nodeVersionChanges.get( ref );
collapseVersions( graph, ref, ref.getVersion(), toVersion );
}
* under the License.
*/
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
import org.apache.commons.collections.iterators.ReverseListIterator;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.Exclusion;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Stack;
-
/**
* DependencyManagementStack
*
public String scope;
- public Set exclusions = new HashSet();
+ public Set<String> exclusions = new HashSet<String>();
- public void addAllExclusions( List depExclusions )
+ public void addAllExclusions( List<Exclusion> depExclusions )
{
- Iterator it = depExclusions.iterator();
- while ( it.hasNext() )
+ for ( Exclusion ref : depExclusions )
{
- Exclusion ref = (Exclusion) it.next();
String key = DependencyGraphKeys.toManagementKey( ref );
exclusions.add( key );
}
}
}
- private Stack depmanStack = new Stack();
+ private Stack<DependencyGraphNode> depmanStack = new Stack<DependencyGraphNode>();
- private Map depMap = new HashMap();
+ private Map<String, Rules> depMap = new HashMap<String, Rules>();
private void generateDepMap()
{
}
}
- private void addDependencies( List dependencies )
+ private void addDependencies( List<Dependency> dependencies )
{
- Iterator it = dependencies.iterator();
- while ( it.hasNext() )
+ for ( Dependency dep : dependencies )
{
- Dependency dep = (Dependency) it.next();
String key = DependencyGraphKeys.toManagementKey( dep );
Rules merged = (Rules) depMap.get( key );
{
private DependencyGraphWalker walker;
- private Set cyclicEdges = new HashSet();
+ private Set<DependencyGraphEdge> cyclicEdges = new HashSet<DependencyGraphEdge>();
public FlagCyclicEdgesVisitor( DependencyGraphWalker walker )
{
}
}
- public Set getCyclicEdges()
+ public Set<DependencyGraphEdge> getCyclicEdges()
{
return cyclicEdges;
}
* under the License.
*/
+import java.util.Stack;
+
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
import org.apache.maven.archiva.model.ArtifactReference;
-import java.util.Iterator;
-import java.util.Stack;
-
/**
* FlagExcludedEdgesVisitor
*
extends BaseVisitor
implements DependencyGraphVisitor
{
- private Stack nodePath = new Stack();
+ private Stack<DependencyGraphNode> nodePath = new Stack<DependencyGraphNode>();
public void discoverEdge( DependencyGraphEdge edge )
{
// Process for excluded edges.
String toKey = DependencyGraphKeys.toManagementKey( artifact );
- Iterator it = this.nodePath.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphNode pathNode : this.nodePath )
{
- DependencyGraphNode pathNode = (DependencyGraphNode) it.next();
-
// Process dependency declared exclusions.
if ( pathNode.getExcludes().contains( toKey ) )
{
* under the License.
*/
-import org.apache.maven.archiva.dependency.graph.DependencyGraph;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
-import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
-import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.maven.archiva.dependency.graph.DependencyGraph;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
+import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
+import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
+
/**
* Perform a transitive reduction of the graph.
*
}
class EdgeInfoDepthComparator
- implements Comparator
+ implements Comparator<EdgeInfo>
{
- public int compare( Object obj0, Object obj1 )
+ public int compare( EdgeInfo obj0, EdgeInfo obj1 )
{
- EdgeInfo edgeInfo0 = (EdgeInfo) obj0;
- EdgeInfo edgeInfo1 = (EdgeInfo) obj1;
-
- return edgeInfo0.depth - edgeInfo1.depth;
+ return obj0.depth - obj1.depth;
}
}
/**
* A Map of <(Node To) ArtifactReference, Map of <(Node From) ArtifactReference, EdgeInfo>>
*/
- private Map /*<ArtifactReference,<ArtifactReference,EdgeInfo>>*/nodeDistanceMap = new HashMap();
+ private Map<String, Map<String, EdgeInfo>> nodeDistanceMap = new HashMap<String, Map<String, EdgeInfo>>();
private int currentDepth;
String nodeFrom = DependencyGraphKeys.toKey( edge.getNodeFrom() );
// Get sub-map
- Map edgeInfoMap = (Map) nodeDistanceMap.get( nodeTo );
+ Map<String,EdgeInfo> edgeInfoMap = nodeDistanceMap.get( nodeTo );
// Create sub-map if not present (yet)
if ( edgeInfoMap == null )
{
- edgeInfoMap = new HashMap();
+ edgeInfoMap = new HashMap<String,EdgeInfo>();
nodeDistanceMap.put( nodeTo, edgeInfoMap );
}
// Now we prune/remove the edges that are transitive in nature.
- Comparator edgeInfoDepthComparator = new EdgeInfoDepthComparator();
+ Comparator<EdgeInfo> edgeInfoDepthComparator = new EdgeInfoDepthComparator();
- Iterator it = nodeDistanceMap.values().iterator();
- while ( it.hasNext() )
+ for ( Map<String, EdgeInfo> edgeInfoMap : nodeDistanceMap.values() )
{
- Map edgeInfoMap = (Map) it.next();
-
if ( edgeInfoMap.size() > 1 )
{
- List edgeInfos = new ArrayList();
+ List<EdgeInfo> edgeInfos = new ArrayList<EdgeInfo>();
edgeInfos.addAll( edgeInfoMap.values() );
Collections.sort( edgeInfos, edgeInfoDepthComparator );
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.MultiValueMap;
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker;
import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
/**
* RefineConflictsTask
*
implements GraphTask, PotentialCyclicEdgeProducer
{
+ @SuppressWarnings("unchecked")
public void executeTask( DependencyGraph graph )
{
- Iterator it;
DependencyGraphWalker walker = new WalkDepthFirstSearch();
RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor();
MultiValueMap depMap = new MultiValueMap();
// Identify deps that need to be resolved.
- it = graph.getNodes().iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphNode node : graph.getNodes() )
{
- DependencyGraphNode node = (DependencyGraphNode) it.next();
String key = DependencyGraphKeys.toManagementKey( node.getArtifact() );
// This will add this node to the specified key, not replace a previous one.
depMap.put( key, node );
// Process those depMap entries with more than 1 value.
ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer();
- it = depMap.entrySet().iterator();
+ Iterator<Map.Entry<String,Collection<DependencyGraphNode>>> it = depMap.entrySet().iterator();
while ( it.hasNext() )
{
- Map.Entry entry = (Entry) it.next();
- Collection nodes = (Collection) entry.getValue();
+ Map.Entry<String,Collection<DependencyGraphNode>> entry = it.next();
+ Collection<DependencyGraphNode> nodes = entry.getValue();
if ( nodes.size() > 1 )
{
- List conflictingArtifacts = new ArrayList();
+ List<DependencyGraphNode> conflictingArtifacts = new ArrayList<DependencyGraphNode>();
conflictingArtifacts.addAll( nodes );
CollectionUtils.transform( conflictingArtifacts, nodeToArtifact );
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections.Predicate;
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor;
import org.apache.maven.archiva.model.ArtifactReference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
/**
* RefineConflictsVisitor
*
implements DependencyGraphVisitor
{
class DepthComparator
- implements Comparator
+ implements Comparator<NodeLocation>
{
- public int compare( Object obj0, Object obj1 )
+ public int compare( NodeLocation obj0, NodeLocation obj1 )
{
- NodeLocation nodeLoc0 = (NodeLocation) obj0;
- NodeLocation nodeLoc1 = (NodeLocation) obj1;
-
- return nodeLoc0.depth - nodeLoc1.depth;
+ return obj0.depth - obj1.depth;
}
}
}
class NodeLocationVersionComparator
- implements Comparator
+ implements Comparator<NodeLocation>
{
- public int compare( Object o1, Object o2 )
+ public int compare( NodeLocation o1, NodeLocation o2 )
{
if ( o1 == null && o2 == null )
{
return -1;
}
- if ( ( o1 instanceof NodeLocation ) && ( o2 instanceof NodeLocation ) )
- {
- String version1 = ( (NodeLocation) o1 ).artifact.getVersion();
- String version2 = ( (NodeLocation) o2 ).artifact.getVersion();
-
- VersionComparator.getInstance().compare( version1, version2 );
- }
+ String version1 = o1.artifact.getVersion();
+ String version2 = o2.artifact.getVersion();
- return 0;
+ return VersionComparator.getInstance().compare( version1, version2 );
}
}
}
}
- private List conflictingArtifacts;
+ private List<DependencyGraphNode> conflictingArtifacts;
- private Map foundNodesMap = new HashMap();
+ private Map<String,NodeLocation> foundNodesMap = new HashMap<String, NodeLocation>();
private int currentDepth = 0;
private DependencyGraph currentGraph;
+ @SuppressWarnings("unchecked")
public RefineConflictsVisitor()
{
- conflictingArtifacts = TypedList.decorate( new ArrayList(), ArtifactReference.class );
+ conflictingArtifacts = TypedList.decorate( new ArrayList<ArtifactReference>(), ArtifactReference.class );
}
public void discoverGraph( DependencyGraph graph )
currentDepth++;
- List edgesFrom = currentGraph.getEdgesFrom( node );
- Iterator it = edgesFrom.iterator();
- while ( it.hasNext() )
+ List<DependencyGraphEdge> edgesFrom = currentGraph.getEdgesFrom( node );
+ for ( DependencyGraphEdge edge : edgesFrom )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
if ( this.conflictingArtifacts.contains( edge.getNodeTo() ) )
{
String nodeKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
// Check for existing NodeLocation with same key
- NodeLocation nodeloc = (NodeLocation) this.foundNodesMap.get( nodeKey );
+ NodeLocation nodeloc = this.foundNodesMap.get( nodeKey );
if ( ( nodeloc == null ) || ( currentDepth < nodeloc.depth ) )
{
DependencyGraphNode winningNode = graph.getNode( winningArtifact );
// Gather up Losing Nodes.
- Set losingNodes = new HashSet();
+ Set<NodeLocation> losingNodes = new HashSet<NodeLocation>();
Predicate losersPredicate = NotPredicate.getInstance( new NodeLocationPredicate( winningArtifact ) );
CollectionUtils.select( this.foundNodesMap.values(), losersPredicate, losingNodes );
// Swing losing nodes to winning node.
- Iterator it = losingNodes.iterator();
- while ( it.hasNext() )
+ for ( NodeLocation losingNodeLoc : losingNodes )
{
- NodeLocation losingNodeLoc = (NodeLocation) it.next();
DependencyGraphNode losingNode = graph.getNode( losingNodeLoc.artifact );
DependencyGraphUtils.collapseNodes( graph, losingNode, winningNode );
}
}
- private ArtifactReference findWinningArtifact( Collection nodes )
+ @SuppressWarnings("unchecked")
+ private ArtifactReference findWinningArtifact( Collection<NodeLocation> nodes )
{
- List remainingNodes = new ArrayList();
+ List<NodeLocation> remainingNodes = new ArrayList<NodeLocation>();
remainingNodes.addAll( nodes );
/* .\ Filter by Depth \.____________________________________________________ */
Collections.sort( remainingNodes, new DepthComparator() );
// Determine 'closest' node depth.
- NodeLocation nearestNode = (NodeLocation) remainingNodes.get( 0 );
+ NodeLocation nearestNode = remainingNodes.get( 0 );
int nearest = nearestNode.depth;
// Filter out distant nodes.
if ( remainingNodes.size() == 1 )
{
// A winner!
- NodeLocation nodeloc = (NodeLocation) remainingNodes.get( 0 );
+ NodeLocation nodeloc = remainingNodes.get( 0 );
return nodeloc.artifact;
}
// Determine which one is 'newest' based on version id.
Collections.sort( remainingNodes, new ReverseComparator( new NodeLocationVersionComparator() ) );
- NodeLocation nodeloc = (NodeLocation) remainingNodes.get( 0 );
+ NodeLocation nodeloc = remainingNodes.get( 0 );
return nodeloc.artifact;
}
currentDepth--;
}
- public List getConflictingArtifacts()
+ public List<DependencyGraphNode> getConflictingArtifacts()
{
return conflictingArtifacts;
}
- public void addAllConflictingArtifacts( Collection nodes )
+ public void addAllConflictingArtifacts( Collection<DependencyGraphNode> nodes )
{
this.conflictingArtifacts.addAll( nodes );
}
extends BaseVisitor
implements DependencyGraphVisitor
{
- private Stack scopeStack;
+ private Stack<String> scopeStack;
private Predicate rootEdgePredicate;
public UpdateScopesVisitor()
{
- scopeStack = new Stack();
+ scopeStack = new Stack<String>();
// Default setting.
scopeStack.add( DependencyScope.COMPILE );
}
* under the License.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.functors.NotPredicate;
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.functors.EdgeDisabledPredicate;
import org.apache.maven.archiva.model.ArtifactReference;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
/**
* WalkBreadthFirstSearch
*
public class WalkBreadthFirstSearch
implements DependencyGraphWalker
{
- private Map nodeVisitStates = new HashMap();
+ private Map<ArtifactReference, Integer> nodeVisitStates = new HashMap<ArtifactReference, Integer>();
private Predicate edgePredicate;
visitor.discoverNode( node );
- Iterator edges;
// First dive down edges.
- edges = graph.getEdgesFrom( node ).iterator();
- while ( edges.hasNext() )
+ for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
{
- DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
if ( this.edgePredicate.evaluate( e ) )
{
visitEdge( graph, e, visitor );
}
// Next move down edges.
- edges = graph.getEdgesFrom( node ).iterator();
- while ( edges.hasNext() )
+ for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
{
- DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
-
if ( this.edgePredicate.evaluate( e ) )
{
DependencyGraphNode nodeTo = graph.getNode( e.getNodeTo() );
{
nodeVisitStates.clear();
- Iterator nodes = graph.getNodes().iterator();
- while ( nodes.hasNext() )
+ for ( DependencyGraphNode node : graph.getNodes() )
{
- setNodeVisitState( (DependencyGraphNode) nodes.next(), UNSEEN );
+ setNodeVisitState( node, UNSEEN );
}
visitor.discoverGraph( graph );
* under the License.
*/
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.functors.NotPredicate;
import org.apache.maven.archiva.dependency.graph.DependencyGraph;
import org.apache.maven.archiva.dependency.graph.functors.EdgeDisabledPredicate;
import org.apache.maven.archiva.model.ArtifactReference;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
/**
* Perform a walk of the graph using the DepthFirstSearch algorithm.
*
public class WalkDepthFirstSearch
implements DependencyGraphWalker
{
- private Map nodeVisitStates = new HashMap();
+ private Map<ArtifactReference, Integer> nodeVisitStates = new HashMap<ArtifactReference, Integer>();
private Predicate edgePredicate;
visitor.discoverNode( node );
- Iterator edges = graph.getEdgesFrom( node ).iterator();
- while ( edges.hasNext() )
+ for ( DependencyGraphEdge e : graph.getEdgesFrom( node ) )
{
- DependencyGraphEdge e = (DependencyGraphEdge) edges.next();
if ( this.edgePredicate.evaluate( e ) )
{
visitEdge( graph, e, visitor );
{
nodeVisitStates.clear();
- Iterator nodes = graph.getNodes().iterator();
- while ( nodes.hasNext() )
+ for ( DependencyGraphNode node : graph.getNodes() )
{
- setNodeVisitState( (DependencyGraphNode) nodes.next(), UNSEEN );
+ setNodeVisitState( node, UNSEEN );
}
visitor.discoverGraph( graph );
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.collections.functors.AndPredicate;
import org.apache.maven.archiva.model.VersionedReference;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
/**
* AbstractDependencyGraphFactoryTestCase
*
}
}
- protected void assertDirectNodes( DependencyGraph graph, List expectedNodes, String scope )
+ @SuppressWarnings("unchecked")
+ protected void assertDirectNodes( DependencyGraph graph, List<DependencyGraphNode> expectedNodes, String scope )
{
- Iterator it;
DependencyGraphNode rootNode = graph.getRootNode();
- List rootEdges = graph.getEdgesFrom( rootNode );
- List actualEdges = new ArrayList();
+ List<DependencyGraphEdge> rootEdges = graph.getEdgesFrom( rootNode );
+ List<DependencyGraphEdge> actualEdges = new ArrayList<DependencyGraphEdge>();
Predicate directDep = NotPredicate.getInstance( new NodeFromParentPredicate() );
Predicate scopedDirectDeps = AndPredicate.getInstance( new EdgeExactScopePredicate( scope ), directDep );
CollectionUtils.transform( actualEdges, new ToKeyTransformer() );
- Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
- it = missingActualKeys.iterator();
- while ( it.hasNext() )
+ Collection<String> missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
+ for ( String key : missingActualKeys )
{
- sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Actual) " ).append( key );
}
- Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
- it = missingExpectedKeys.iterator();
- while ( it.hasNext() )
+ Collection<String> missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
+ for ( String key : missingExpectedKeys )
{
- sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Expected) " ).append( key );
}
fail( sb.toString() );
}
- it = actualEdges.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : actualEdges )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
String actualKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
assertTrue( "Direct <" + scope + "> node To [" + actualKey + "] exists in expectedNodes.", expectedNodes
.contains( actualKey ) );
}
}
- protected void assertEdges( DependencyGraph graph, List expectedEdges )
+ protected void assertEdges( DependencyGraph graph, List<ExpectedEdge> expectedEdges )
{
assertNotNull( "Graph.edges should never be null.", graph.getEdges() );
assertEquals( "Graph.edges.size()", expectedEdges.size(), graph.getEdges().size() );
- Iterator it = expectedEdges.iterator();
- while ( it.hasNext() )
+ for ( ExpectedEdge expectedEdge : expectedEdges )
{
- ExpectedEdge expectedEdge = (ExpectedEdge) it.next();
Predicate edgePredicate = new GraphEdgePredicate( expectedEdge.from, expectedEdge.to );
DependencyGraphEdge edge = (DependencyGraphEdge) CollectionUtils.find( graph.getEdges(), edgePredicate );
}
}
+ @SuppressWarnings("unchecked")
protected void assertGraph( DependencyGraph graph, String rootRefKey, List expectedNodeKeys )
{
assertNotNull( "Graph.nodes should never be null.", graph.getNodes() );
assertEquals( "Graph.root", rootRefKey, actualRootRef.toString() );
- Iterator it;
- List actualNodes = new ArrayList();
+ List<DependencyGraphNode> actualNodes = new ArrayList<DependencyGraphNode>();
Predicate notRootNode = NotPredicate.getInstance( new NodePredicate( graph.getRootNode() ) );
CollectionUtils.select( graph.getNodes(), notRootNode, actualNodes );
CollectionUtils.transform( actualNodes, new ToKeyTransformer() );
- Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
- it = missingActualKeys.iterator();
- while ( it.hasNext() )
+ Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
+ for ( DependencyGraphNode key : missingActualKeys )
{
- sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Actual) " ).append( key );
fail = true;
}
- Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
- it = missingExpectedKeys.iterator();
- while ( it.hasNext() )
+ Collection<DependencyGraphNode> missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
+ for ( DependencyGraphNode key : missingExpectedKeys )
{
- sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Expected) " ).append( key );
fail = true;
}
*/
}
- protected void assertNodes( DependencyGraph graph, List expectedNodeKeys )
+ @SuppressWarnings("unchecked")
+ protected void assertNodes( DependencyGraph graph, List<String> expectedNodeKeys )
{
assertNotNull( "Graph.nodes should never be null.", graph.getNodes() );
assertTrue( "Graph.nodes.size() should always be 1 or better.", graph.getNodes().size() >= 1 );
// assertEquals( "Graph.nodes.size()", expectedNodeKeys.size(), graph.getNodes().size() );
- Iterator it;
- List actualNodes = new ArrayList();
+ List<DependencyGraphNode> actualNodes = new ArrayList<DependencyGraphNode>();
actualNodes.addAll( graph.getNodes() );
if ( expectedNodeKeys.size() != actualNodes.size() )
CollectionUtils.transform( actualNodes, new ToKeyTransformer() );
- Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
- it = missingActualKeys.iterator();
- while ( it.hasNext() )
+ Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys );
+ for ( DependencyGraphNode key : missingActualKeys )
{
- sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Actual) " ).append( key );
}
- Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
- it = missingExpectedKeys.iterator();
- while ( it.hasNext() )
+ Collection<String> missingExpectedKeys = CollectionUtils.subtract( expectedNodeKeys, actualNodes );
+ for ( String key : missingExpectedKeys )
{
- sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Expected) " ).append( key );
}
fail( sb.toString() );
}
- it = graph.getNodes().iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphNode node : graph.getNodes() )
{
- DependencyGraphNode node = (DependencyGraphNode) it.next();
assertNotNull( "Artifact reference in node should not be null.", node.getArtifact() );
String key = ArtifactReference.toKey( node.getArtifact() );
assertTrue( "Artifact reference [" + key + "] should be in expectedNodeKeys.", expectedNodeKeys
assertEquals( "Root Node", expectedKey, actualKey );
}
- protected void assertTransientNodes( DependencyGraph graph, List expectedNodes, String scope )
+ @SuppressWarnings("unchecked")
+ protected void assertTransientNodes( DependencyGraph graph, List<DependencyGraphNode> expectedNodes, String scope )
{
- Iterator it;
-
// Gather up the transient nodes from the DependencyGraph.
- List actualEdges = new ArrayList();
+ ArrayList<DependencyGraphEdge> actualEdges = new ArrayList<DependencyGraphEdge>();
DependencyGraphNode rootNode = graph.getRootNode();
CollectionUtils.transform( actualEdges, new ToKeyTransformer() );
- Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
- it = missingActualKeys.iterator();
- while ( it.hasNext() )
+ Collection<DependencyGraphNode> missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes );
+ for ( DependencyGraphNode key : missingActualKeys )
{
- sb.append( "\n (Extra Actual) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Actual) " ).append( key );
}
- Collection missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
- it = missingExpectedKeys.iterator();
- while ( it.hasNext() )
+ Collection<DependencyGraphNode> missingExpectedKeys = CollectionUtils.subtract( expectedNodes, actualEdges );
+ for ( DependencyGraphNode key : missingExpectedKeys )
{
- sb.append( "\n (Extra Expected) " ).append( (String) it.next() );
+ sb.append( "\n (Extra Expected) " ).append( key );
}
fail( sb.toString() );
}
- it = actualEdges.iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : actualEdges )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
String actualKey = DependencyGraphKeys.toKey( edge.getNodeTo() );
assertTrue( "Transient Node To [" + actualKey + "] exists in expectedNodes.", expectedNodes
.contains( actualKey ) );
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.model.Dependency;
-import org.apache.maven.archiva.model.Exclusion;
-import org.apache.maven.archiva.model.Keys;
-import org.apache.maven.archiva.model.VersionedReference;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.Dependency;
+import org.apache.maven.archiva.model.Exclusion;
+import org.apache.maven.archiva.model.Keys;
+import org.apache.maven.archiva.model.VersionedReference;
+
/**
* AbstractMemoryRepository
*
public abstract class AbstractMemoryRepository
implements MemoryRepository
{
- private Map modelMap = new HashMap();
+ private Map<String,ArchivaProjectModel> modelMap = new HashMap<String, ArchivaProjectModel>();
public AbstractMemoryRepository()
{
protected ArchivaProjectModel toModel( String key )
{
- return toModel( key, Collections.EMPTY_LIST );
+ return toModel( key, Collections.<Dependency>emptyList() );
}
- protected ArchivaProjectModel toModel( String key, Dependency deps[] )
+ protected ArchivaProjectModel toModel( String key, Dependency[] deps )
{
- List depList = new ArrayList();
+ List<Dependency> depList = new ArrayList<Dependency>();
if ( deps != null )
{
return toModel( key, depList );
}
- protected ArchivaProjectModel toModel( String key, List deps )
+ protected ArchivaProjectModel toModel( String key, List<Dependency> deps )
{
String parts[] = StringUtils.splitPreserveAllTokens( key, ':' );
model.setOrigin( "testcase" );
model.setPackaging( "jar" );
- Iterator it = deps.iterator();
- while ( it.hasNext() )
+ for ( Dependency dep : deps )
{
- Dependency dep = (Dependency) it.next();
model.addDependency( dep );
}
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "org.apache.maven.archiva:archiva-common:1.0-alpha-2-SNAPSHOT";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "org.apache.maven.archiva:archiva-webapp:1.0-alpha-2-SNAPSHOT";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "org.apache.maven.archiva:archiva-xml-tools:1.0-alpha-2-SNAPSHOT";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "org.apache.maven.continuum:continuum-store:1.1-SNAPSHOT";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "net.example.depman.deepversion:A:1.0";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
* under the License.
*/
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
import junit.framework.Assert;
+
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.model.DependencyScope;
import org.apache.maven.archiva.model.VersionedReference;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.List;
-
/**
* GraphvizDotTool - testing utility to help understand the graph.
*
dot.println( " fontsize=\"11\"," );
dot.println( " ];" );
- Iterator it;
-
- it = graph.getNodes().iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphNode node : graph.getNodes() )
{
- DependencyGraphNode node = (DependencyGraphNode) it.next();
-
writeNode( dot, graph, node );
}
- it = graph.getEdges().iterator();
- while ( it.hasNext() )
+ for ( DependencyGraphEdge edge : graph.getEdges() )
{
- DependencyGraphEdge edge = (DependencyGraphEdge) it.next();
-
DependencyGraphNode from = graph.getNode( edge.getNodeFrom() );
DependencyGraphNode to = graph.getNode( edge.getNodeTo() );
dot.println( " \"" + toId( node ) + "\" [" );
dot.println( " label=\"" + toLabel( node ) + "\"," );
- List edgesTo = graph.getEdgesTo( node );
- boolean orphan = CollectionUtils.isEmpty( edgesTo );
+ boolean orphan = CollectionUtils.isEmpty( graph.getEdgesTo( node ) );
if ( node.isFromParent() )
{
* under the License.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.maven.archiva.dependency.DependencyGraphFactory;
import org.apache.maven.archiva.model.DependencyScope;
import org.apache.maven.archiva.model.VersionedReference;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* SimpleDependencyGraphTest
*
// Test the results.
assertNotNull( "Graph shouldn't be null.", graph );
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
expectedNodes.add( "org.apache.maven.archiva:archiva-commons:1.0::pom" );
expectedNodes.add( "org.codehaus.plexus:plexus-digest:1.0::jar" );
expectedNodes.add( "junit:junit:3.8.1::jar" );
assertNodes( graph, expectedNodes );
- List expectedEdges = new ArrayList();
+ List<ExpectedEdge> expectedEdges = new ArrayList<ExpectedEdge>();
expectedEdges.add( new ExpectedEdge( "org.apache.maven.archiva:archiva-commons:1.0::pom",
"org.codehaus.plexus:plexus-digest:1.0::jar" ) );
expectedEdges.add( new ExpectedEdge( "org.codehaus.plexus:plexus-digest:1.0::jar", "junit:junit:3.8.1::jar" ) );
assertNotNull( "Graph shouldn't be null.", graph );
String expectedRootRef = "org.apache.maven.wagon:wagon-manager:2.0-SNAPSHOT";
- List expectedNodes = new ArrayList();
+ List<String> expectedNodes = new ArrayList<String>();
// Check for all nodes, regardless of scope.
expectedNodes.clear();
}
}
- private void assertPath( String[] expectedPath, List collectedPath )
+ private void assertPath( String[] expectedPath, List<String> collectedPath )
{
assertEquals( "Path.length", expectedPath.length, collectedPath.size() );
for ( int i = 0; i < expectedPath.length; i++ )
{
- assertEquals( "Walk path[" + i + "]", expectedPath[i], (String) collectedPath.get( i ) );
+ assertEquals( "Walk path[" + i + "]", expectedPath[i], collectedPath.get( i ) );
}
}
class WalkCollector
implements DependencyGraphVisitor
{
- private List walkPath = new ArrayList();
+ private List<String> walkPath = new ArrayList<String>();
private int countDiscoverGraph = 0;
countFinishNode++;
}
- public List getCollectedPath()
+ public List<String> getCollectedPath()
{
return walkPath;
}