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 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ResolutionListener;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.tools.ant.Project;
/**
@ -54,39 +55,45 @@ public void endProcessChildren( 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 )
{
project.log( indent + omitted.getId() + " (removed - nearer found: " + kept.getVersion() + ")" );
project.log( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
}
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 )
{
project.log( indent + artifact.getId() + " (setting scope to: " + scope + ")" );
project.log( indent + artifact + " (setting scope to: " + scope + ")" );
}
public void updateScopeCurrentPom( Artifact artifact, String scope )
{
project.log( indent + artifact.getId() + " (not setting scope to: " + scope + "; local scope " +
artifact.getScope() + " wins)" );
project.log( indent + artifact + " (not setting scope to: " + scope + "; local scope " + artifact.getScope() +
" wins)" );
}
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() + ")" );
}
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 )
{
String msg = indent + artifact.getId();
String msg = indent + artifact;
msg += " (";
if ( replacement.getVersion() != null )
{

View File

@ -59,10 +59,10 @@ public void deploy( File source, Artifact artifact, ArtifactRepository deploymen
{
if ( !wagonManager.isOnline() )
{
getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact.getId() + "." );
getLogger().warn( "System is offline. Cannot deploy artifact: " + artifact + "." );
return;
}
try
{
transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );

View File

@ -17,6 +17,7 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.logging.Logger;
/**
@ -53,39 +54,45 @@ public void endProcessChildren( 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 )
{
logger.debug( indent + omitted.getId() + " (removed - nearer found: " + kept.getVersion() + ")" );
logger.debug( indent + omitted + " (removed - nearer found: " + kept.getVersion() + ")" );
}
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 )
{
logger.debug( indent + artifact.getId() + " (not setting scope to: " + scope + "; local scope " +
artifact.getScope() + " wins)" );
logger.debug( indent + artifact + " (not setting scope to: " + scope + "; local scope " + artifact.getScope() +
" wins)" );
}
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 )
{
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() + ")" );
}
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 )
{
String msg = indent + artifact.getId();
String msg = indent + artifact;
msg += " (";
if ( replacement.getVersion() != null )
{

View File

@ -83,7 +83,7 @@ private void resolve( Artifact artifact, List remoteRepositories, ArtifactReposi
if ( !systemFile.exists() )
{
throw new ArtifactNotFoundException(
"System artifact: " + artifact.getId() + " not found in path: " + systemFile, artifact );
"System artifact: " + artifact + " not found in path: " + systemFile, artifact );
}
else
{
@ -117,7 +117,7 @@ else if ( !artifact.isResolved() )
{
if ( !wagonManager.isOnline() )
{
getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact.getId() + "." );
getLogger().debug( "System is offline. Cannot resolve artifact: " + artifact + "." );
return;
}

View File

@ -17,6 +17,7 @@
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.codehaus.plexus.logging.Logger;
import java.util.HashSet;
@ -69,7 +70,7 @@ public void updateScopeCurrentPom( Artifact artifact, String scope )
// TODO: better way than static? this might hide messages in a reactor
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" +
"\tgiven by a dependency. If this is not intended, modify or remove the local scope.\n" );
ignoredArtifacts.add( artifact );
@ -87,4 +88,8 @@ public void manageArtifact( Artifact artifact, Artifact replacement )
public void selectVersionFromRange( Artifact artifact )
{
}
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
{
}
}

View File

@ -148,7 +148,14 @@ else if ( currentRange == null )
{
// TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
// 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 ) );
}
@ -317,6 +324,12 @@ private void fireEvent( int event, List listeners, ResolutionNode node )
}
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(); )
{
@ -337,7 +350,12 @@ private void fireEvent( int event, List listeners, ResolutionNode node, Artifact
listener.includeArtifact( node.getArtifact() );
break;
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;
case ResolutionListener.OMIT_FOR_CYCLE:
listener.omitForCycle( node.getArtifact() );
@ -354,6 +372,13 @@ private void fireEvent( int event, List listeners, ResolutionNode node, Artifact
case ResolutionListener.SELECT_VERSION_FROM_RANGE:
listener.selectVersionFromRange( node.getArtifact() );
break;
case ResolutionListener.RESTRICT_RANGE:
if ( node.getArtifact().getVersionRange().hasRestrictions() ||
replacement.getVersionRange().hasRestrictions() )
{
listener.restrictRange( node.getArtifact(), replacement, newRange );
}
break;
default:
throw new IllegalStateException( "Unknown event: " + event );
}

View File

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

View File

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

View File

@ -130,7 +130,7 @@ public void execute()
if ( !sourceFile.isFile() )
{
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 );

View File

@ -636,7 +636,7 @@ private void checkForPresenceOfSnapshots( MavenProject project )
message.append( " " );
message.append( artifact.getId() );
message.append( artifact );
message.append( "\n" );
}
@ -901,8 +901,8 @@ else if ( finalName.indexOf( "SNAPSHOT" ) > -1 )
if ( ArtifactUtils.isSnapshot( version ) )
{
throw new MojoExecutionException( "Unresolved SNAPSHOT version of: " +
artifact.getId() + ". Cannot proceed with release." );
throw new MojoExecutionException(
"Unresolved SNAPSHOT version of: " + artifact + ". Cannot proceed with release." );
}
}
@ -1155,7 +1155,7 @@ private String resolveVersion( Artifact artifact, String artifactUsage, List plu
}
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 MavenProject buildFromRepository( Artifact artifact, List remoteArtifactR
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, null,
null );
return build( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null );
}
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
@ -451,7 +450,7 @@ else if ( allowStubModel )
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.setModelVersion( "4.0.0" );

View File

@ -109,7 +109,7 @@ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepo
}
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." );
project = null;