From 6354dad32e8e6e446c8785ee53544624e5cc8f12 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Gonzalez Date: Tue, 24 Jan 2006 21:47:10 +0000 Subject: [PATCH] Refactor PR: MNG-1895 git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@372027 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/DefaultArtifactCollector.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index ccc62acb16..c467098dec 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -185,26 +185,30 @@ public class DefaultArtifactCollector // TODO: should this be part of mediation? // previous one is more dominant + ResolutionNode nearest, farthest; if ( previous.getDepth() <= node.getDepth() ) { - checkScopeUpdate( node, previous, listeners ); + nearest = previous; + farthest = node; } else { - checkScopeUpdate( previous, node, listeners ); + nearest = node; + farthest = previous; } - if ( previous.getDepth() <= node.getDepth() ) + /* if we need to update scope of nearest to use farthest scope */ + if ( checkScopeUpdate( farthest, nearest, listeners ) ) { - // previous was nearer - fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, node, previous.getArtifact() ); - node.disable(); - } - else - { - fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, previous, node.getArtifact() ); - previous.disable(); + fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthest.getArtifact() ); + + // previously we cloned the artifact, but it is more effecient to just update the scope + // if problems are later discovered that the original object needs its original scope value, cloning may + // again be appropriate + nearest.getArtifact().setScope( farthest.getArtifact().getScope() ); } + fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, farthest, nearest.getArtifact() ); + farthest.disable(); } } } @@ -316,13 +320,13 @@ public class DefaultArtifactCollector } /** - * Check if the scope needs to be updated. + * Check if the scope of the nearest needs to be updated with the scope of the farthest. * More info. * @param farthest farthest resolution node * @param nearest nearest resolution node * @param listeners */ - void checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners ) + private boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners ) { boolean updateScope = false; Artifact farthestArtifact = farthest.getArtifact(); @@ -349,15 +353,7 @@ public class DefaultArtifactCollector fireEvent( ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact ); } - if ( updateScope ) - { - fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthestArtifact ); - - // previously we cloned the artifact, but it is more effecient to just update the scope - // if problems are later discovered that the original object needs its original scope value, cloning may - // again be appropriate - nearestArtifact.setScope( farthestArtifact.getScope() ); - } + return updateScope; } private void fireEvent( int event, List listeners, ResolutionNode node )