diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java index d5bcde3dba..51b6b11582 100644 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java @@ -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 ) { diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index b0f847fc8c..9d873cd273 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -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 ); 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 001923df00..f782e7595d 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 @@ -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 ) { 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 aa99af4cfd..c15cc69dbc 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 @@ -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; } 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 index 85900ff155..ece74c3933 100644 --- 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 @@ -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 ) + { + } } 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 14eec8c274..a179696c06 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 @@ -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 ); } 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 b4e0294b71..3f2ace50e4 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 @@ -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 ); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java index 2e4974773c..3453171ffe 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -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; + } } diff --git a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java index d6cad94f58..c3f639ffe7 100644 --- a/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java +++ b/maven-plugins/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java @@ -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 ); diff --git a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java index 375269d433..120902269b 100644 --- a/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java +++ b/maven-plugins/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java @@ -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 ); } } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 70b4bf2809..6dd464c42e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -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" ); diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index d7570803f9..5c7038d1a6 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -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;