From 3c461ef89d5b06bd26fc782625a9de05ebd2f2cb Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 28 Jul 2005 14:54:04 +0000 Subject: [PATCH] PR: MNG-670 stronger warning if scope gets updated over the root POM git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225788 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/DebugResolutionListener.java | 7 +- .../resolver/DefaultArtifactResolver.java | 2 + .../resolver/WarningResolutionListener.java | 77 +++++++++++++++++++ .../resolver/DefaultArtifactCollector.java | 15 +++- .../artifact/resolver/ResolutionListener.java | 6 +- 5 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java index 528e9e5b36..0eb1d58f2f 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java @@ -66,9 +66,14 @@ public class DebugResolutionListener logger.debug( indent + omitted.getId() + " (removed - causes a cycle in the graph)" ); } + public void updateScopeCurrentPom( Artifact artifact, String scope ) + { + updateScope( artifact, scope ); + } + public void updateScope( Artifact artifact, String scope ) { - logger.debug( indent + artifact.getId() + " (settings scope to: " + scope + ")" ); + logger.debug( indent + artifact.getId() + " (setting scope to: " + scope + ")" ); } public void manageArtifact( Artifact artifact, Artifact replacement ) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 8c83e48ab6..fa1f8f7daa 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -170,6 +170,8 @@ public class DefaultArtifactResolver listeners.add( new DebugResolutionListener( getLogger() ) ); } + listeners.add( new WarningResolutionListener( getLogger() ) ); + return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners ); diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java new file mode 100644 index 0000000000..9cbe7ce1db --- /dev/null +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java @@ -0,0 +1,77 @@ +package org.apache.maven.artifact.resolver; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.Artifact; +import org.codehaus.plexus.logging.Logger; + +/** + * Send resolution warning events to the warning log. + * + * @author Brett Porter + * @version $Id$ + */ +public class WarningResolutionListener + implements ResolutionListener +{ + private Logger logger; + + public WarningResolutionListener( Logger logger ) + { + this.logger = logger; + } + + public void testArtifact( Artifact node ) + { + } + + public void startProcessChildren( Artifact artifact ) + { + } + + public void endProcessChildren( Artifact artifact ) + { + } + + public void includeArtifact( Artifact artifact ) + { + } + + public void omitForNearer( Artifact omitted, Artifact kept ) + { + } + + public void omitForCycle( Artifact omitted ) + { + } + + public void updateScopeCurrentPom( Artifact artifact, String scope ) + { + logger.warn( "\n\tArtifact " + artifact.getId() + " is having scope '" + artifact + "' replaced with '" + + scope + "'\n" + + "\tas a dependency has given a broader scope. If this is not intended, use -X to locate the dependency,\n" + + "\tor force the desired scope using dependencyManagement.\n" ); + } + + public void updateScope( Artifact artifact, String scope ) + { + } + + public void manageArtifact( Artifact artifact, Artifact replacement ) + { + } +} 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 d9c027a0de..13d092eb0a 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 @@ -230,7 +230,17 @@ public class DefaultArtifactCollector if ( updateScope ) { - fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, previous, newArtifact ); + int event; + if ( previous.getDepth() < 2 ) + { + event = ResolutionListener.UPDATE_SCOPE_CURRENT_POM; + } + else + { + event = ResolutionListener.UPDATE_SCOPE; + } + + fireEvent( event, listeners, previous, newArtifact ); // 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 @@ -273,6 +283,9 @@ public class DefaultArtifactCollector case ResolutionListener.UPDATE_SCOPE: listener.updateScope( node.getArtifact(), replacement.getScope() ); break; + case ResolutionListener.UPDATE_SCOPE_CURRENT_POM: + listener.updateScopeCurrentPom( node.getArtifact(), replacement.getScope() ); + break; case ResolutionListener.MANAGE_ARTIFACT: listener.manageArtifact( node.getArtifact(), replacement ); break; diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java index 39693ccb20..f85002d8c8 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionListener.java @@ -19,7 +19,7 @@ import org.apache.maven.artifact.Artifact; */ /** - * TODO: describe + * Listens to the resolution process and handles events. * * @author Brett Porter * @version $Id$ @@ -44,6 +44,8 @@ public interface ResolutionListener int OMIT_FOR_CYCLE = 8; + int UPDATE_SCOPE_CURRENT_POM = 9; + void testArtifact( Artifact node ); void startProcessChildren( Artifact artifact ); @@ -59,4 +61,6 @@ public interface ResolutionListener void manageArtifact( Artifact artifact, Artifact replacement ); void omitForCycle( Artifact artifact ); + + void updateScopeCurrentPom( Artifact artifact, String scope ); }