You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/01/24 06:53:35 UTC
[maven] branch maven-3.8.x updated: [MNG-7349] Limit relocation warning message to direct dependencies only
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch maven-3.8.x
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.8.x by this push:
new 83257bf [MNG-7349] Limit relocation warning message to direct dependencies only
83257bf is described below
commit 83257bfde0dd5b4d391063412494957c1b7e15e8
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jan 24 07:53:26 2022 +0100
[MNG-7349] Limit relocation warning message to direct dependencies only
---
.../internal/DefaultPluginDependenciesResolver.java | 12 ++++++++++++
.../project/DefaultProjectDependenciesResolver.java | 16 ++++++++++++++++
.../internal/DefaultArtifactDescriptorReader.java | 20 +++-----------------
.../maven/repository/internal/RelocatedArtifact.java | 17 ++++++++++++-----
4 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java
index 8d16c61..c4bddc5 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java
@@ -108,6 +108,18 @@ public class DefaultPluginDependenciesResolver
pluginArtifact = result.getArtifact();
+ if ( logger.isWarnEnabled() )
+ {
+ if ( !result.getRelocations().isEmpty() )
+ {
+ String message = pluginArtifact instanceof org.apache.maven.repository.internal.RelocatedArtifact
+ ? ( ( org.apache.maven.repository.internal.RelocatedArtifact ) pluginArtifact ).getMessage()
+ : null;
+ logger.warn( "The artifact " + result.getRelocations().get( 0 ) + " has been relocated to "
+ + pluginArtifact + ( message != null ? ": " + message : "" ) );
+ }
+ }
+
String requiredMavenVersion = (String) result.getProperties().get( "prerequisites.maven" );
if ( requiredMavenVersion != null )
{
diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java
index 3644b67..7ce4906 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java
@@ -181,6 +181,22 @@ public class DefaultProjectDependenciesResolver
depRequest.setRoot( node );
+ if ( logger.isWarnEnabled() )
+ {
+ for ( DependencyNode child : node.getChildren() )
+ {
+ if ( !child.getRelocations().isEmpty() )
+ {
+ org.eclipse.aether.artifact.Artifact relocated = child.getDependency().getArtifact();
+ String message = relocated instanceof org.apache.maven.repository.internal.RelocatedArtifact
+ ? ( ( org.apache.maven.repository.internal.RelocatedArtifact ) relocated ).getMessage()
+ : null;
+ logger.warn( "The artifact " + child.getRelocations().get( 0 ) + " has been relocated to "
+ + relocated + ( message != null ? ": " + message : "" ) );
+ }
+ }
+ }
+
if ( logger.isDebugEnabled() )
{
node.accept( new GraphLogger( project ) );
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
index 888f458..e78c77f 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java
@@ -68,8 +68,6 @@ import org.eclipse.aether.resolution.VersionResult;
import org.eclipse.aether.spi.locator.Service;
import org.eclipse.aether.spi.locator.ServiceLocator;
import org.eclipse.aether.transfer.ArtifactNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* @author Benjamin Bentmann
@@ -79,8 +77,6 @@ import org.slf4j.LoggerFactory;
public class DefaultArtifactDescriptorReader
implements ArtifactDescriptorReader, Service
{
- private static final Logger LOGGER = LoggerFactory.getLogger( DefaultArtifactDescriptorReader.class );
-
private RemoteRepositoryManager remoteRepositoryManager;
private VersionResolver versionResolver;
@@ -320,20 +316,10 @@ public class DefaultArtifactDescriptorReader
if ( relocation != null )
{
result.addRelocation( a );
- Artifact relocatedArtifact =
+ a =
new RelocatedArtifact( a, relocation.getGroupId(), relocation.getArtifactId(),
- relocation.getVersion() );
- if ( LOGGER.isWarnEnabled() )
- {
- String message = "The artifact " + a + " has been relocated to " + relocatedArtifact;
- if ( relocation.getMessage() != null )
- {
- message += ": " + relocation.getMessage();
- }
- LOGGER.warn( message );
- }
- result.setArtifact( relocatedArtifact );
- a = relocatedArtifact;
+ relocation.getVersion(), relocation.getMessage() );
+ result.setArtifact( a );
}
else
{
diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
index 4614ccf..a0a21e9 100644
--- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
+++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
@@ -29,7 +29,7 @@ import org.eclipse.aether.artifact.Artifact;
/**
* @author Benjamin Bentmann
*/
-final class RelocatedArtifact
+public final class RelocatedArtifact
extends AbstractArtifact
{
@@ -41,13 +41,16 @@ final class RelocatedArtifact
private final String version;
- RelocatedArtifact( Artifact artifact, String groupId, String artifactId, String version )
+ private final String message;
+
+ RelocatedArtifact( Artifact artifact, String groupId, String artifactId, String version, String message )
{
this.artifact = Objects.requireNonNull( artifact, "artifact cannot be null" );
// TODO Use StringUtils here
this.groupId = ( groupId != null && groupId.length() > 0 ) ? groupId : null;
this.artifactId = ( artifactId != null && artifactId.length() > 0 ) ? artifactId : null;
this.version = ( version != null && version.length() > 0 ) ? version : null;
+ this.message = ( message != null && message.length() > 0 ) ? message : null;
}
public String getGroupId()
@@ -95,7 +98,7 @@ final class RelocatedArtifact
{
return this;
}
- return new RelocatedArtifact( artifact, groupId, artifactId, version );
+ return new RelocatedArtifact( artifact, groupId, artifactId, version, message );
}
@Override
@@ -106,7 +109,7 @@ final class RelocatedArtifact
{
return this;
}
- return new RelocatedArtifact( artifact.setFile( file ), groupId, artifactId, version );
+ return new RelocatedArtifact( artifact.setFile( file ), groupId, artifactId, version, message );
}
@Override
@@ -117,7 +120,7 @@ final class RelocatedArtifact
{
return this;
}
- return new RelocatedArtifact( artifact.setProperties( properties ), groupId, artifactId, version );
+ return new RelocatedArtifact( artifact.setProperties( properties ), groupId, artifactId, version, message );
}
public String getClassifier()
@@ -145,4 +148,8 @@ final class RelocatedArtifact
return artifact.getProperties();
}
+ public String getMessage()
+ {
+ return message;
+ }
}