From c5d079a9a4ffda20611efee6260bbc3179769829 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 17 Mar 2009 15:18:35 +0000 Subject: [PATCH] clean warnings from dependency-graph git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755277 13f79535-47bb-0310-9956-ffa450edef68 --- .../dependency/DependencyGraphFactory.java | 27 ++--- .../dependency/graph/DependencyGraph.java | 17 +-- .../dependency/graph/DependencyGraphNode.java | 12 +- .../graph/DependencyGraphUtils.java | 47 +++----- .../tasks/DependencyManagementApplier.java | 21 ++-- .../tasks/DependencyManagementStack.java | 33 +++--- .../graph/tasks/FlagCyclicEdgesVisitor.java | 4 +- .../graph/tasks/FlagExcludedEdgesVisitor.java | 12 +- .../tasks/ReduceTransitiveEdgesVisitor.java | 37 +++--- .../graph/tasks/RefineConflictsTask.java | 27 ++--- .../graph/tasks/RefineConflictsVisitor.java | 81 ++++++------- .../graph/tasks/UpdateScopesVisitor.java | 4 +- .../graph/walk/WalkBreadthFirstSearch.java | 24 ++-- .../graph/walk/WalkDepthFirstSearch.java | 18 ++- ...bstractDependencyGraphFactoryTestCase.java | 108 ++++++++---------- .../graph/AbstractMemoryRepository.java | 29 +++-- .../ArchivaCommonDependencyGraphTest.java | 2 +- .../ArchivaWebappDependencyGraphTest.java | 2 +- .../ArchivaXmlToolsDependencyGraphTest.java | 2 +- .../ContinuumStoreDependencyGraphTest.java | 2 +- .../DepManDeepVersionDependencyGraphTest.java | 2 +- .../dependency/graph/GraphvizDotTool.java | 28 ++--- .../graph/SimpleDependencyGraphTest.java | 10 +- .../WagonManagerDependencyGraphTest.java | 2 +- .../graph/walk/DependencyGraphWalkerTest.java | 4 +- .../dependency/graph/walk/WalkCollector.java | 4 +- 26 files changed, 226 insertions(+), 333 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/DependencyGraphFactory.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/DependencyGraphFactory.java index daae2e29f..90d8dfdb2 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/DependencyGraphFactory.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/DependencyGraphFactory.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency; * 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; @@ -37,10 +40,6 @@ import org.apache.maven.archiva.dependency.graph.tasks.UpdateScopesTask; 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 * @@ -54,21 +53,21 @@ public class DependencyGraphFactory private ReduceScopeTask taskReduceScope; - private List listeners; + private List listeners; private DependencyGraphBuilder graphBuilder; - private List tasks; + private List tasks; public DependencyGraphFactory() { - listeners = new ArrayList(); + listeners = new ArrayList(); taskFlagCyclicEdges = new FlagCyclicEdgesTask(); taskPopulateGraph = new PopulateGraphMasterTask(); taskReduceScope = new ReduceScopeTask( DependencyScope.TEST ); - tasks = new ArrayList(); + tasks = new ArrayList(); /* Take the basic graph, and expand the nodes fully, including depman. */ @@ -124,10 +123,8 @@ public class DependencyGraphFactory 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 ); @@ -174,10 +171,8 @@ public class DependencyGraphFactory 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 ); } } @@ -186,10 +181,8 @@ public class DependencyGraphFactory { 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 ); } } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraph.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraph.java index 404d30027..bf8fac55f 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraph.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraph.java @@ -50,7 +50,7 @@ public class DependencyGraph private DependencyGraphNode rootNode; - private Set edges = new HashSet(); + private Set edges = new HashSet(); private ListOrderedMap nodes = new ListOrderedMap(); @@ -71,12 +71,13 @@ public class DependencyGraph this.rootNode = root; } - public Collection getEdges() + public Collection getEdges() { return edges; } - public Collection getNodes() + @SuppressWarnings("unchecked") + public Collection getNodes() { return nodes.values(); } @@ -172,9 +173,9 @@ public class DependencyGraph * @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 getEdgesFrom( DependencyGraphNode node ) { - List ret = new ArrayList(); + List ret = new ArrayList(); CollectionUtils.select( this.edges, new EdgeFromPredicate( node.getArtifact() ), ret ); return ret; } @@ -185,9 +186,9 @@ public class DependencyGraph * @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 getEdgesTo( DependencyGraphNode node ) { - List ret = new ArrayList(); + List ret = new ArrayList(); CollectionUtils.select( this.edges, new EdgeToPredicate( node.getArtifact() ), ret ); return ret; } @@ -210,7 +211,7 @@ public class DependencyGraph public void removeNode( DependencyGraphNode node ) { - List edges = getEdgesFrom( node ); + List edges = getEdgesFrom( node ); if ( !edges.isEmpty() ) { System.out.println( "Removing node left <" + edges + "> hanging edges." ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphNode.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphNode.java index dfddd3fa9..98cd2d6e0 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphNode.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphNode.java @@ -43,12 +43,12 @@ public class DependencyGraphNode /** * The project level dependency management section for this artifact. */ - private List dependencyManagement = new ArrayList(); + private List dependencyManagement = new ArrayList(); /** * The list of excluded groupId:artifactId for this node's sub-nodes. */ - private Set excludes = new HashSet(); + private Set excludes = new HashSet(); /** * Flag indicating that this node has been resolved from disk. @@ -115,12 +115,12 @@ public class DependencyGraphNode return artifact; } - public List getDependencyManagement() + public List getDependencyManagement() { return dependencyManagement; } - public Set getExcludes() + public Set getExcludes() { return excludes; } @@ -158,12 +158,12 @@ public class DependencyGraphNode this.conflicted = conflicted; } - public void setDependencyManagement( List dependencyManagement ) + public void setDependencyManagement( List dependencyManagement ) { this.dependencyManagement = dependencyManagement; } - public void setExcludes( Set excludes ) + public void setExcludes( Set excludes ) { this.excludes = excludes; } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphUtils.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphUtils.java index d66027234..beb2071fe 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphUtils.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/DependencyGraphUtils.java @@ -19,6 +19,10 @@ package org.apache.maven.archiva.dependency.graph; * 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; @@ -33,11 +37,6 @@ import org.apache.maven.archiva.model.DependencyScope; 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. * @@ -99,25 +98,18 @@ public class DependencyGraphUtils 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. @@ -138,10 +130,8 @@ public class DependencyGraphUtils 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 ); } } @@ -198,12 +188,8 @@ public class DependencyGraphUtils } // 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 ); } @@ -226,12 +212,10 @@ public class DependencyGraphUtils */ public static void collapseNodes( DependencyGraph graph, DependencyGraphNode nodeFROM, DependencyGraphNode nodeTO ) { - Iterator it; - - Set edgesToRemove = new HashSet(); + Set edgesToRemove = new HashSet(); // 1) Remove all of the edge.from references from nodeFROM - List fromEdges = graph.getEdgesFrom( nodeFROM ); + List fromEdges = graph.getEdgesFrom( nodeFROM ); if ( CollectionUtils.isNotEmpty( fromEdges ) ) { edgesToRemove.addAll( fromEdges ); @@ -240,12 +224,9 @@ public class DependencyGraphUtils // 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 toEdges = graph.getEdgesTo( nodeFROM ); + for ( DependencyGraphEdge edge : toEdges ) { - DependencyGraphEdge edge = (DependencyGraphEdge) it.next(); - // Identify old edge to remove. edgesToRemove.add( edge ); @@ -258,10 +239,8 @@ public class DependencyGraphUtils } // Actually remove the old edges. - it = edgesToRemove.iterator(); - while ( it.hasNext() ) + for ( DependencyGraphEdge edge : edgesToRemove ) { - DependencyGraphEdge edge = (DependencyGraphEdge) it.next(); graph.removeEdge( edge ); } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementApplier.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementApplier.java index 35bc3aa0b..10750e43e 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementApplier.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementApplier.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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; @@ -31,11 +34,6 @@ import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor; 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. @@ -58,7 +56,7 @@ public class DependencyManagementApplier * 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 nodeVersionChanges = new HashMap(); private int nodesAdded = 0; @@ -76,11 +74,8 @@ public class DependencyManagementApplier 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 ) @@ -137,11 +132,9 @@ public class DependencyManagementApplier { 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 ); } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementStack.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementStack.java index 5f9d0a2da..45c523399 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementStack.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/DependencyManagementStack.java @@ -19,6 +19,13 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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; @@ -28,14 +35,6 @@ import org.apache.maven.archiva.model.ArtifactReference; 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 * @@ -49,23 +48,21 @@ public class DependencyManagementStack public String scope; - public Set exclusions = new HashSet(); + public Set exclusions = new HashSet(); - public void addAllExclusions( List depExclusions ) + public void addAllExclusions( List 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 depmanStack = new Stack(); - private Map depMap = new HashMap(); + private Map depMap = new HashMap(); private void generateDepMap() { @@ -82,12 +79,10 @@ public class DependencyManagementStack } } - private void addDependencies( List dependencies ) + private void addDependencies( List 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 ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagCyclicEdgesVisitor.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagCyclicEdgesVisitor.java index f49f8cb5f..df3d5e810 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagCyclicEdgesVisitor.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagCyclicEdgesVisitor.java @@ -40,7 +40,7 @@ public class FlagCyclicEdgesVisitor { private DependencyGraphWalker walker; - private Set cyclicEdges = new HashSet(); + private Set cyclicEdges = new HashSet(); public FlagCyclicEdgesVisitor( DependencyGraphWalker walker ) { @@ -62,7 +62,7 @@ public class FlagCyclicEdgesVisitor } } - public Set getCyclicEdges() + public Set getCyclicEdges() { return cyclicEdges; } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagExcludedEdgesVisitor.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagExcludedEdgesVisitor.java index 804cdc304..a8829377e 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagExcludedEdgesVisitor.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/FlagExcludedEdgesVisitor.java @@ -19,6 +19,8 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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; @@ -27,9 +29,6 @@ import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor; 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 * @@ -39,7 +38,7 @@ public class FlagExcludedEdgesVisitor extends BaseVisitor implements DependencyGraphVisitor { - private Stack nodePath = new Stack(); + private Stack nodePath = new Stack(); public void discoverEdge( DependencyGraphEdge edge ) { @@ -47,11 +46,8 @@ public class FlagExcludedEdgesVisitor // 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 ) ) { diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/ReduceTransitiveEdgesVisitor.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/ReduceTransitiveEdgesVisitor.java index 9d753965d..fe5c5d233 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/ReduceTransitiveEdgesVisitor.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/ReduceTransitiveEdgesVisitor.java @@ -19,20 +19,19 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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. * @@ -50,21 +49,18 @@ public class ReduceTransitiveEdgesVisitor } class EdgeInfoDepthComparator - implements Comparator + implements Comparator { - 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 /*>*/nodeDistanceMap = new HashMap(); + private Map> nodeDistanceMap = new HashMap>(); private int currentDepth; @@ -87,12 +83,12 @@ public class ReduceTransitiveEdgesVisitor String nodeFrom = DependencyGraphKeys.toKey( edge.getNodeFrom() ); // Get sub-map - Map edgeInfoMap = (Map) nodeDistanceMap.get( nodeTo ); + Map edgeInfoMap = nodeDistanceMap.get( nodeTo ); // Create sub-map if not present (yet) if ( edgeInfoMap == null ) { - edgeInfoMap = new HashMap(); + edgeInfoMap = new HashMap(); nodeDistanceMap.put( nodeTo, edgeInfoMap ); } @@ -136,16 +132,13 @@ public class ReduceTransitiveEdgesVisitor // Now we prune/remove the edges that are transitive in nature. - Comparator edgeInfoDepthComparator = new EdgeInfoDepthComparator(); + Comparator edgeInfoDepthComparator = new EdgeInfoDepthComparator(); - Iterator it = nodeDistanceMap.values().iterator(); - while ( it.hasNext() ) + for ( Map edgeInfoMap : nodeDistanceMap.values() ) { - Map edgeInfoMap = (Map) it.next(); - if ( edgeInfoMap.size() > 1 ) { - List edgeInfos = new ArrayList(); + List edgeInfos = new ArrayList(); edgeInfos.addAll( edgeInfoMap.values() ); Collections.sort( edgeInfos, edgeInfoDepthComparator ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsTask.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsTask.java index 0c59fb4fa..6c08d4fca 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsTask.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsTask.java @@ -19,6 +19,12 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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; @@ -30,13 +36,6 @@ import org.apache.maven.archiva.dependency.graph.functors.ToArtifactReferenceTra 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 * @@ -46,19 +45,17 @@ public class 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 ); @@ -67,14 +64,14 @@ public class RefineConflictsTask // Process those depMap entries with more than 1 value. ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer(); - it = depMap.entrySet().iterator(); + Iterator>> it = depMap.entrySet().iterator(); while ( it.hasNext() ) { - Map.Entry entry = (Entry) it.next(); - Collection nodes = (Collection) entry.getValue(); + Map.Entry> entry = it.next(); + Collection nodes = entry.getValue(); if ( nodes.size() > 1 ) { - List conflictingArtifacts = new ArrayList(); + List conflictingArtifacts = new ArrayList(); conflictingArtifacts.addAll( nodes ); CollectionUtils.transform( conflictingArtifacts, nodeToArtifact ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsVisitor.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsVisitor.java index b149ded6f..158edaa59 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsVisitor.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/RefineConflictsVisitor.java @@ -19,6 +19,16 @@ package org.apache.maven.archiva.dependency.graph.tasks; * 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; @@ -35,17 +45,6 @@ import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor; 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 * @@ -56,14 +55,11 @@ public class RefineConflictsVisitor implements DependencyGraphVisitor { class DepthComparator - implements Comparator + implements Comparator { - 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; } } @@ -114,9 +110,9 @@ public class RefineConflictsVisitor } class NodeLocationVersionComparator - implements Comparator + implements Comparator { - public int compare( Object o1, Object o2 ) + public int compare( NodeLocation o1, NodeLocation o2 ) { if ( o1 == null && o2 == null ) { @@ -133,15 +129,10 @@ public class RefineConflictsVisitor 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 ); } } @@ -169,17 +160,18 @@ public class RefineConflictsVisitor } } - private List conflictingArtifacts; + private List conflictingArtifacts; - private Map foundNodesMap = new HashMap(); + private Map foundNodesMap = new HashMap(); private int currentDepth = 0; private DependencyGraph currentGraph; + @SuppressWarnings("unchecked") public RefineConflictsVisitor() { - conflictingArtifacts = TypedList.decorate( new ArrayList(), ArtifactReference.class ); + conflictingArtifacts = TypedList.decorate( new ArrayList(), ArtifactReference.class ); } public void discoverGraph( DependencyGraph graph ) @@ -195,16 +187,14 @@ public class RefineConflictsVisitor currentDepth++; - List edgesFrom = currentGraph.getEdgesFrom( node ); - Iterator it = edgesFrom.iterator(); - while ( it.hasNext() ) + List 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 ) ) { @@ -229,23 +219,22 @@ public class RefineConflictsVisitor DependencyGraphNode winningNode = graph.getNode( winningArtifact ); // Gather up Losing Nodes. - Set losingNodes = new HashSet(); + Set losingNodes = new HashSet(); 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 nodes ) { - List remainingNodes = new ArrayList(); + List remainingNodes = new ArrayList(); remainingNodes.addAll( nodes ); /* .\ Filter by Depth \.____________________________________________________ */ @@ -254,7 +243,7 @@ public class RefineConflictsVisitor 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. @@ -265,7 +254,7 @@ public class RefineConflictsVisitor if ( remainingNodes.size() == 1 ) { // A winner! - NodeLocation nodeloc = (NodeLocation) remainingNodes.get( 0 ); + NodeLocation nodeloc = remainingNodes.get( 0 ); return nodeloc.artifact; } @@ -275,7 +264,7 @@ public class RefineConflictsVisitor // 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; } @@ -285,12 +274,12 @@ public class RefineConflictsVisitor currentDepth--; } - public List getConflictingArtifacts() + public List getConflictingArtifacts() { return conflictingArtifacts; } - public void addAllConflictingArtifacts( Collection nodes ) + public void addAllConflictingArtifacts( Collection nodes ) { this.conflictingArtifacts.addAll( nodes ); } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/UpdateScopesVisitor.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/UpdateScopesVisitor.java index d4affcefa..88951decf 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/UpdateScopesVisitor.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/tasks/UpdateScopesVisitor.java @@ -38,13 +38,13 @@ public class UpdateScopesVisitor extends BaseVisitor implements DependencyGraphVisitor { - private Stack scopeStack; + private Stack scopeStack; private Predicate rootEdgePredicate; public UpdateScopesVisitor() { - scopeStack = new Stack(); + scopeStack = new Stack(); // Default setting. scopeStack.add( DependencyScope.COMPILE ); } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkBreadthFirstSearch.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkBreadthFirstSearch.java index 967994963..60650c35c 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkBreadthFirstSearch.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkBreadthFirstSearch.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.walk; * 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; @@ -27,10 +30,6 @@ import org.apache.maven.archiva.dependency.graph.DependencyGraphNode; 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 * @@ -39,7 +38,7 @@ import java.util.Map; public class WalkBreadthFirstSearch implements DependencyGraphWalker { - private Map nodeVisitStates = new HashMap(); + private Map nodeVisitStates = new HashMap(); private Predicate edgePredicate; @@ -98,12 +97,9 @@ public class WalkBreadthFirstSearch 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 ); @@ -111,11 +107,8 @@ public class WalkBreadthFirstSearch } // 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() ); @@ -141,10 +134,9 @@ public class WalkBreadthFirstSearch { 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 ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkDepthFirstSearch.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkDepthFirstSearch.java index d542819dc..603ec09e4 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkDepthFirstSearch.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/main/java/org/apache/maven/archiva/dependency/graph/walk/WalkDepthFirstSearch.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.dependency.graph.walk; * 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; @@ -27,10 +30,6 @@ import org.apache.maven.archiva.dependency.graph.DependencyGraphNode; 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. * @@ -41,7 +40,7 @@ import java.util.Map; public class WalkDepthFirstSearch implements DependencyGraphWalker { - private Map nodeVisitStates = new HashMap(); + private Map nodeVisitStates = new HashMap(); private Predicate edgePredicate; @@ -105,10 +104,8 @@ public class WalkDepthFirstSearch 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 ); @@ -129,10 +126,9 @@ public class WalkDepthFirstSearch { 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 ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractDependencyGraphFactoryTestCase.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractDependencyGraphFactoryTestCase.java index 8bc4b7bfd..1413b36ce 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractDependencyGraphFactoryTestCase.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractDependencyGraphFactoryTestCase.java @@ -19,6 +19,10 @@ package org.apache.maven.archiva.dependency.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; @@ -35,11 +39,6 @@ import org.apache.maven.archiva.model.Dependency; 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 * @@ -91,12 +90,12 @@ public abstract class AbstractDependencyGraphFactoryTestCase } } - protected void assertDirectNodes( DependencyGraph graph, List expectedNodes, String scope ) + @SuppressWarnings("unchecked") + protected void assertDirectNodes( DependencyGraph graph, List expectedNodes, String scope ) { - Iterator it; DependencyGraphNode rootNode = graph.getRootNode(); - List rootEdges = graph.getEdgesFrom( rootNode ); - List actualEdges = new ArrayList(); + List rootEdges = graph.getEdgesFrom( rootNode ); + List actualEdges = new ArrayList(); Predicate directDep = NotPredicate.getInstance( new NodeFromParentPredicate() ); Predicate scopedDirectDeps = AndPredicate.getInstance( new EdgeExactScopePredicate( scope ), directDep ); @@ -114,42 +113,36 @@ public abstract class AbstractDependencyGraphFactoryTestCase CollectionUtils.transform( actualEdges, new ToKeyTransformer() ); - Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes ); - it = missingActualKeys.iterator(); - while ( it.hasNext() ) + Collection 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 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 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 ); @@ -160,6 +153,7 @@ public abstract class AbstractDependencyGraphFactoryTestCase } } + @SuppressWarnings("unchecked") protected void assertGraph( DependencyGraph graph, String rootRefKey, List expectedNodeKeys ) { assertNotNull( "Graph.nodes should never be null.", graph.getNodes() ); @@ -173,8 +167,7 @@ public abstract class AbstractDependencyGraphFactoryTestCase assertEquals( "Graph.root", rootRefKey, actualRootRef.toString() ); - Iterator it; - List actualNodes = new ArrayList(); + List actualNodes = new ArrayList(); Predicate notRootNode = NotPredicate.getInstance( new NodePredicate( graph.getRootNode() ) ); CollectionUtils.select( graph.getNodes(), notRootNode, actualNodes ); @@ -192,19 +185,17 @@ public abstract class AbstractDependencyGraphFactoryTestCase CollectionUtils.transform( actualNodes, new ToKeyTransformer() ); - Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys ); - it = missingActualKeys.iterator(); - while ( it.hasNext() ) + Collection 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 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; } @@ -226,14 +217,14 @@ public abstract class AbstractDependencyGraphFactoryTestCase */ } - protected void assertNodes( DependencyGraph graph, List expectedNodeKeys ) + @SuppressWarnings("unchecked") + protected void assertNodes( DependencyGraph graph, List 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 actualNodes = new ArrayList(); actualNodes.addAll( graph.getNodes() ); if ( expectedNodeKeys.size() != actualNodes.size() ) @@ -246,27 +237,23 @@ public abstract class AbstractDependencyGraphFactoryTestCase CollectionUtils.transform( actualNodes, new ToKeyTransformer() ); - Collection missingActualKeys = CollectionUtils.subtract( actualNodes, expectedNodeKeys ); - it = missingActualKeys.iterator(); - while ( it.hasNext() ) + Collection 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 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 @@ -282,12 +269,11 @@ public abstract class AbstractDependencyGraphFactoryTestCase assertEquals( "Root Node", expectedKey, actualKey ); } - protected void assertTransientNodes( DependencyGraph graph, List expectedNodes, String scope ) + @SuppressWarnings("unchecked") + protected void assertTransientNodes( DependencyGraph graph, List expectedNodes, String scope ) { - Iterator it; - // Gather up the transient nodes from the DependencyGraph. - List actualEdges = new ArrayList(); + ArrayList actualEdges = new ArrayList(); DependencyGraphNode rootNode = graph.getRootNode(); @@ -308,27 +294,23 @@ public abstract class AbstractDependencyGraphFactoryTestCase CollectionUtils.transform( actualEdges, new ToKeyTransformer() ); - Collection missingActualKeys = CollectionUtils.subtract( actualEdges, expectedNodes ); - it = missingActualKeys.iterator(); - while ( it.hasNext() ) + Collection 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 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 ) ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractMemoryRepository.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractMemoryRepository.java index f1671aa83..9dbd4af82 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractMemoryRepository.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/AbstractMemoryRepository.java @@ -19,21 +19,20 @@ package org.apache.maven.archiva.dependency.graph; * 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 * @@ -42,7 +41,7 @@ import java.util.Map; public abstract class AbstractMemoryRepository implements MemoryRepository { - private Map modelMap = new HashMap(); + private Map modelMap = new HashMap(); public AbstractMemoryRepository() { @@ -112,12 +111,12 @@ public abstract class AbstractMemoryRepository protected ArchivaProjectModel toModel( String key ) { - return toModel( key, Collections.EMPTY_LIST ); + return toModel( key, Collections.emptyList() ); } - protected ArchivaProjectModel toModel( String key, Dependency deps[] ) + protected ArchivaProjectModel toModel( String key, Dependency[] deps ) { - List depList = new ArrayList(); + List depList = new ArrayList(); if ( deps != null ) { @@ -127,7 +126,7 @@ public abstract class AbstractMemoryRepository return toModel( key, depList ); } - protected ArchivaProjectModel toModel( String key, List deps ) + protected ArchivaProjectModel toModel( String key, List deps ) { String parts[] = StringUtils.splitPreserveAllTokens( key, ':' ); @@ -144,10 +143,8 @@ public abstract class AbstractMemoryRepository 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 ); } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaCommonDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaCommonDependencyGraphTest.java index 26a598127..5f79f40c5 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaCommonDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaCommonDependencyGraphTest.java @@ -60,7 +60,7 @@ public class ArchivaCommonDependencyGraphTest 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 expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaWebappDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaWebappDependencyGraphTest.java index b3bb2a1fa..eef773295 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaWebappDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaWebappDependencyGraphTest.java @@ -60,7 +60,7 @@ public class ArchivaWebappDependencyGraphTest 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 expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaXmlToolsDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaXmlToolsDependencyGraphTest.java index 6733b8900..ceed2135d 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaXmlToolsDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ArchivaXmlToolsDependencyGraphTest.java @@ -60,7 +60,7 @@ public class ArchivaXmlToolsDependencyGraphTest 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 expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ContinuumStoreDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ContinuumStoreDependencyGraphTest.java index e55bf17d1..13715e0bc 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ContinuumStoreDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/ContinuumStoreDependencyGraphTest.java @@ -60,7 +60,7 @@ public class ContinuumStoreDependencyGraphTest assertNotNull( "Graph shouldn't be null.", graph ); String expectedRootRef = "org.apache.maven.continuum:continuum-store:1.1-SNAPSHOT"; - List expectedNodes = new ArrayList(); + List expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/DepManDeepVersionDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/DepManDeepVersionDependencyGraphTest.java index fa5b32f11..1d043e9ea 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/DepManDeepVersionDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/DepManDeepVersionDependencyGraphTest.java @@ -58,7 +58,7 @@ public class DepManDeepVersionDependencyGraphTest assertNotNull( "Graph shouldn't be null.", graph ); String expectedRootRef = "net.example.depman.deepversion:A:1.0"; - List expectedNodes = new ArrayList(); + List expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/GraphvizDotTool.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/GraphvizDotTool.java index 3e7d29e10..f9bdb884f 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/GraphvizDotTool.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/GraphvizDotTool.java @@ -19,7 +19,13 @@ package org.apache.maven.archiva.dependency.graph; * 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; @@ -27,13 +33,6 @@ import org.apache.maven.archiva.dependency.DependencyGraphFactory; 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. * @@ -178,21 +177,13 @@ public class GraphvizDotTool 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() ); @@ -250,8 +241,7 @@ public class GraphvizDotTool 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() ) { diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/SimpleDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/SimpleDependencyGraphTest.java index b11c78c40..dd084e31d 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/SimpleDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/SimpleDependencyGraphTest.java @@ -19,13 +19,13 @@ package org.apache.maven.archiva.dependency.graph; * 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 * @@ -54,13 +54,13 @@ public class SimpleDependencyGraphTest // Test the results. assertNotNull( "Graph shouldn't be null.", graph ); - List expectedNodes = new ArrayList(); + List expectedNodes = new ArrayList(); 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 expectedEdges = new ArrayList(); 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" ) ); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/WagonManagerDependencyGraphTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/WagonManagerDependencyGraphTest.java index 3fcc04c4f..432b2a43c 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/WagonManagerDependencyGraphTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/WagonManagerDependencyGraphTest.java @@ -60,7 +60,7 @@ public class WagonManagerDependencyGraphTest assertNotNull( "Graph shouldn't be null.", graph ); String expectedRootRef = "org.apache.maven.wagon:wagon-manager:2.0-SNAPSHOT"; - List expectedNodes = new ArrayList(); + List expectedNodes = new ArrayList(); // Check for all nodes, regardless of scope. expectedNodes.clear(); diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/DependencyGraphWalkerTest.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/DependencyGraphWalkerTest.java index 3026ed02d..7c2d41286 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/DependencyGraphWalkerTest.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/DependencyGraphWalkerTest.java @@ -175,13 +175,13 @@ public class DependencyGraphWalkerTest } } - private void assertPath( String[] expectedPath, List collectedPath ) + private void assertPath( String[] expectedPath, List 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 ) ); } } diff --git a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/WalkCollector.java b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/WalkCollector.java index c07f1a7cb..ff3a69c6f 100644 --- a/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/WalkCollector.java +++ b/archiva-modules/archiva-base/archiva-dependency-graph/src/test/java/org/apache/maven/archiva/dependency/graph/walk/WalkCollector.java @@ -30,7 +30,7 @@ import java.util.List; class WalkCollector implements DependencyGraphVisitor { - private List walkPath = new ArrayList(); + private List walkPath = new ArrayList(); private int countDiscoverGraph = 0; @@ -75,7 +75,7 @@ class WalkCollector countFinishNode++; } - public List getCollectedPath() + public List getCollectedPath() { return walkPath; } -- 2.39.5