PR: MNG-616

improve version logging, use artifact.toString for textual logging

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-08 16:30:28 +00:00
parent ce8f50cc0a
commit f8cbb08498
12 changed files with 92 additions and 33 deletions

View File

@ -18,6 +18,7 @@ package org.apache.maven.artifact.ant;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ResolutionListener; import org.apache.maven.artifact.resolver.ResolutionListener;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
/** /**
@ -54,39 +55,45 @@ public class AntResolutionListener
public void includeArtifact( Artifact artifact ) public void includeArtifact( Artifact artifact )
{ {
project.log( indent + artifact.getId() + " (selected)" ); project.log( indent + artifact + " (selected)" );
} }
public void omitForNearer( Artifact omitted, Artifact kept ) public void omitForNearer( Artifact omitted, Artifact kept )
{ {
project.log( indent + omitted.getId() + " (removed - nearer found: " + kept.getVersion() + ")" ); project.log( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
} }
public void omitForCycle( Artifact omitted ) public void omitForCycle( Artifact omitted )
{ {
project.log( indent + omitted.getId() + " (removed - causes a cycle in the graph)" ); project.log( indent + omitted + " (removed - causes a cycle in the graph)" );
} }
public void updateScope( Artifact artifact, String scope ) public void updateScope( Artifact artifact, String scope )
{ {
project.log( indent + artifact.getId() + " (setting scope to: " + scope + ")" ); project.log( indent + artifact + " (setting scope to: " + scope + ")" );
} }
public void updateScopeCurrentPom( Artifact artifact, String scope ) public void updateScopeCurrentPom( Artifact artifact, String scope )
{ {
project.log( indent + artifact.getId() + " (not setting scope to: " + scope + "; local scope " + project.log( indent + artifact + " (not setting scope to: " + scope + "; local scope " + artifact.getScope() +
artifact.getScope() + " wins)" ); " wins)" );
} }
public void selectVersionFromRange( Artifact artifact ) public void selectVersionFromRange( Artifact artifact )
{ {
project.log( indent + artifact.getId() + " (setting version to: " + artifact.getVersion() + " from range: " + project.log( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: " +
artifact.getVersionRange() + ")" ); artifact.getVersionRange() + ")" );
} }
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
{
project.log( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: " +
replacement.getVersionRange() + " to: " + newRange + " )" );
}
public void manageArtifact( Artifact artifact, Artifact replacement ) public void manageArtifact( Artifact artifact, Artifact replacement )
{ {
String msg = indent + artifact.getId(); String msg = indent + artifact;
msg += " ("; msg += " (";
if ( replacement.getVersion() != null ) if ( replacement.getVersion() != null )
{ {

View File

@ -59,7 +59,7 @@ public class DefaultArtifactDeployer
{ {
if ( !wagonManager.isOnline() ) if ( !wagonManager.isOnline() )
{ {
getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact.getId() + "." ); getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact + "." );
return; return;
} }

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.resolver;
*/ */
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
/** /**
@ -53,39 +54,45 @@ public class DebugResolutionListener
public void includeArtifact( Artifact artifact ) public void includeArtifact( Artifact artifact )
{ {
logger.debug( indent + artifact.getId() + " (selected for " + artifact.getScope() + ")" ); logger.debug( indent + artifact + " (selected for " + artifact.getScope() + ")" );
} }
public void omitForNearer( Artifact omitted, Artifact kept ) public void omitForNearer( Artifact omitted, Artifact kept )
{ {
logger.debug( indent + omitted.getId() + " (removed - nearer found: " + kept.getVersion() + ")" ); logger.debug( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
} }
public void omitForCycle( Artifact omitted ) public void omitForCycle( Artifact omitted )
{ {
logger.debug( indent + omitted.getId() + " (removed - causes a cycle in the graph)" ); logger.debug( indent + omitted + " (removed - causes a cycle in the graph)" );
} }
public void updateScopeCurrentPom( Artifact artifact, String scope ) public void updateScopeCurrentPom( Artifact artifact, String scope )
{ {
logger.debug( indent + artifact.getId() + " (not setting scope to: " + scope + "; local scope " + logger.debug( indent + artifact + " (not setting scope to: " + scope + "; local scope " + artifact.getScope() +
artifact.getScope() + " wins)" ); " wins)" );
} }
public void updateScope( Artifact artifact, String scope ) public void updateScope( Artifact artifact, String scope )
{ {
logger.debug( indent + artifact.getId() + " (setting scope to: " + scope + ")" ); logger.debug( indent + artifact + " (setting scope to: " + scope + ")" );
} }
public void selectVersionFromRange( Artifact artifact ) public void selectVersionFromRange( Artifact artifact )
{ {
logger.debug( indent + artifact.getId() + " (setting version to: " + artifact.getVersion() + " from range: " + logger.debug( indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: " +
artifact.getVersionRange() + ")" ); artifact.getVersionRange() + ")" );
} }
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
{
logger.debug( indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: " +
replacement.getVersionRange() + " to: " + newRange + " )" );
}
public void manageArtifact( Artifact artifact, Artifact replacement ) public void manageArtifact( Artifact artifact, Artifact replacement )
{ {
String msg = indent + artifact.getId(); String msg = indent + artifact;
msg += " ("; msg += " (";
if ( replacement.getVersion() != null ) if ( replacement.getVersion() != null )
{ {

View File

@ -83,7 +83,7 @@ public class DefaultArtifactResolver
if ( !systemFile.exists() ) if ( !systemFile.exists() )
{ {
throw new ArtifactNotFoundException( throw new ArtifactNotFoundException(
"System artifact: " + artifact.getId() + " not found in path: " + systemFile, artifact ); "System artifact: " + artifact + " not found in path: " + systemFile, artifact );
} }
else else
{ {
@ -117,7 +117,7 @@ public class DefaultArtifactResolver
{ {
if ( !wagonManager.isOnline() ) if ( !wagonManager.isOnline() )
{ {
getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact.getId() + "." ); getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact + "." );
return; return;
} }

View File

@ -17,6 +17,7 @@ package org.apache.maven.artifact.resolver;
*/ */
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import java.util.HashSet; import java.util.HashSet;
@ -69,7 +70,7 @@ public class WarningResolutionListener
// TODO: better way than static? this might hide messages in a reactor // TODO: better way than static? this might hide messages in a reactor
if ( !ignoredArtifacts.contains( artifact ) ) if ( !ignoredArtifacts.contains( artifact ) )
{ {
logger.warn( "\n\tArtifact " + artifact.getId() + " retains local scope '" + artifact.getScope() + logger.warn( "\n\tArtifact " + artifact + " retains local scope '" + artifact.getScope() +
"' overriding broader scope '" + scope + "'\n" + "' overriding broader scope '" + scope + "'\n" +
"\tgiven by a dependency. If this is not intended, modify or remove the local scope.\n" ); "\tgiven by a dependency. If this is not intended, modify or remove the local scope.\n" );
ignoredArtifacts.add( artifact ); ignoredArtifacts.add( artifact );
@ -87,4 +88,8 @@ public class WarningResolutionListener
public void selectVersionFromRange( Artifact artifact ) public void selectVersionFromRange( Artifact artifact )
{ {
} }
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
{
}
} }

View File

@ -148,7 +148,14 @@ public class DefaultArtifactCollector
{ {
// TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended // TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
// version but the restriction is identical // version but the restriction is identical
previous.getArtifact().setVersionRange( previousRange.restrict( currentRange ) ); VersionRange newRange = previousRange.restrict( currentRange );
// TODO: ick. this forces the OCE that should have come from the previous call. It is still correct
if ( newRange.isSelectedVersionKnown( previous.getArtifact() ) )
{
fireEvent( ResolutionListener.RESTRICT_RANGE, listeners, node, previous.getArtifact(),
newRange );
}
previous.getArtifact().setVersionRange( newRange );
node.getArtifact().setVersionRange( currentRange.restrict( previousRange ) ); node.getArtifact().setVersionRange( currentRange.restrict( previousRange ) );
} }
@ -317,6 +324,12 @@ public class DefaultArtifactCollector
} }
private void fireEvent( int event, List listeners, ResolutionNode node, Artifact replacement ) private void fireEvent( int event, List listeners, ResolutionNode node, Artifact replacement )
{
fireEvent( event, listeners, node, replacement, null );
}
private void fireEvent( int event, List listeners, ResolutionNode node, Artifact replacement,
VersionRange newRange )
{ {
for ( Iterator i = listeners.iterator(); i.hasNext(); ) for ( Iterator i = listeners.iterator(); i.hasNext(); )
{ {
@ -337,7 +350,12 @@ public class DefaultArtifactCollector
listener.includeArtifact( node.getArtifact() ); listener.includeArtifact( node.getArtifact() );
break; break;
case ResolutionListener.OMIT_FOR_NEARER: case ResolutionListener.OMIT_FOR_NEARER:
listener.omitForNearer( node.getArtifact(), replacement ); String version = node.getArtifact().getVersion();
String replacementVersion = replacement.getVersion();
if ( version != null ? !version.equals( replacementVersion ) : replacementVersion != null )
{
listener.omitForNearer( node.getArtifact(), replacement );
}
break; break;
case ResolutionListener.OMIT_FOR_CYCLE: case ResolutionListener.OMIT_FOR_CYCLE:
listener.omitForCycle( node.getArtifact() ); listener.omitForCycle( node.getArtifact() );
@ -354,6 +372,13 @@ public class DefaultArtifactCollector
case ResolutionListener.SELECT_VERSION_FROM_RANGE: case ResolutionListener.SELECT_VERSION_FROM_RANGE:
listener.selectVersionFromRange( node.getArtifact() ); listener.selectVersionFromRange( node.getArtifact() );
break; break;
case ResolutionListener.RESTRICT_RANGE:
if ( node.getArtifact().getVersionRange().hasRestrictions() ||
replacement.getVersionRange().hasRestrictions() )
{
listener.restrictRange( node.getArtifact(), replacement, newRange );
}
break;
default: default:
throw new IllegalStateException( "Unknown event: " + event ); throw new IllegalStateException( "Unknown event: " + event );
} }

View File

@ -1,6 +1,7 @@
package org.apache.maven.artifact.resolver; package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
/* /*
* Copyright 2001-2005 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
@ -48,6 +49,8 @@ public interface ResolutionListener
int SELECT_VERSION_FROM_RANGE = 10; int SELECT_VERSION_FROM_RANGE = 10;
int RESTRICT_RANGE = 11;
void testArtifact( Artifact node ); void testArtifact( Artifact node );
void startProcessChildren( Artifact artifact ); void startProcessChildren( Artifact artifact );
@ -67,4 +70,6 @@ public interface ResolutionListener
void updateScopeCurrentPom( Artifact artifact, String scope ); void updateScopeCurrentPom( Artifact artifact, String scope );
void selectVersionFromRange( Artifact artifact ); void selectVersionFromRange( Artifact artifact );
void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange );
} }

View File

@ -221,11 +221,17 @@ public class VersionRange
} }
} }
} }
else else if ( recommendedVersion != null )
{ {
// no range, so the recommended version is valid // no range, so the recommended version is valid
version = recommendedVersion; version = recommendedVersion;
} }
/* TODO: should throw this immediately, but need artifact
else
{
throw new OverConstrainedVersionException( "Restricting incompatible version ranges" );
}
*/
return new VersionRange( version, restrictions ); return new VersionRange( version, restrictions );
} }
@ -501,4 +507,9 @@ public class VersionRange
} }
return matched; return matched;
} }
public boolean hasRestrictions()
{
return !restrictions.isEmpty() && recommendedVersion == null;
}
} }

View File

@ -130,7 +130,7 @@ public class EarMojo
if ( !sourceFile.isFile() ) if ( !sourceFile.isFile() )
{ {
throw new MojoExecutionException( "Cannot copy a directory: " + sourceFile.getAbsolutePath() + throw new MojoExecutionException( "Cannot copy a directory: " + sourceFile.getAbsolutePath() +
"; Did you package/install " + module.getArtifact().getId() + "?" ); "; Did you package/install " + module.getArtifact() + "?" );
} }
FileUtils.copyFile( module.getArtifact().getFile(), destinationFile ); FileUtils.copyFile( module.getArtifact().getFile(), destinationFile );

View File

@ -636,7 +636,7 @@ public class PrepareReleaseMojo
message.append( " " ); message.append( " " );
message.append( artifact.getId() ); message.append( artifact );
message.append( "\n" ); message.append( "\n" );
} }
@ -901,8 +901,8 @@ public class PrepareReleaseMojo
if ( ArtifactUtils.isSnapshot( version ) ) if ( ArtifactUtils.isSnapshot( version ) )
{ {
throw new MojoExecutionException( "Unresolved SNAPSHOT version of: " + throw new MojoExecutionException(
artifact.getId() + ". Cannot proceed with release." ); "Unresolved SNAPSHOT version of: " + artifact + ". Cannot proceed with release." );
} }
} }
@ -1155,7 +1155,7 @@ public class PrepareReleaseMojo
} }
catch ( ArtifactMetadataRetrievalException e ) catch ( ArtifactMetadataRetrievalException e )
{ {
throw new MojoExecutionException( "Cannot resolve " + artifactUsage + ": " + artifact.getId(), e ); throw new MojoExecutionException( "Cannot resolve " + artifactUsage + ": " + artifact, e );
} }
} }

View File

@ -322,8 +322,7 @@ public class DefaultMavenProjectBuilder
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel ); Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, null, return build( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null );
null );
} }
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
@ -451,7 +450,7 @@ public class DefaultMavenProjectBuilder
private Model createStubModel( Artifact projectArtifact ) private Model createStubModel( Artifact projectArtifact )
{ {
getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" ); getLogger().warn( "\n ***** Using defaults for missing POM " + projectArtifact + " *****\n" );
Model model = new Model(); Model model = new Model();
model.setModelVersion( "4.0.0" ); model.setModelVersion( "4.0.0" );

View File

@ -109,7 +109,7 @@ public class MavenMetadataSource
} }
catch ( InvalidModelException e ) catch ( InvalidModelException e )
{ {
getLogger().warn( "POM for: \'" + pomArtifact.getId() + getLogger().warn( "POM for: \'" + pomArtifact +
"\' does not appear to be valid. Its will be ignored for artifact resolution." ); "\' does not appear to be valid. Its will be ignored for artifact resolution." );
project = null; project = null;