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
This commit is contained in:
Brett Leslie Porter 2005-07-28 14:54:04 +00:00
parent 15fef60915
commit 3c461ef89d
5 changed files with 104 additions and 3 deletions

View File

@ -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 )

View File

@ -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 );

View File

@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
* @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 )
{
}
}

View File

@ -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;

View File

@ -19,7 +19,7 @@ import org.apache.maven.artifact.Artifact;
*/
/**
* TODO: describe
* Listens to the resolution process and handles events.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @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 );
}