From ab54d17dc2ec355c1e002e8751739edd9a96fcc3 Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Fri, 17 Sep 2021 12:18:27 -0300 Subject: [PATCH] [MNG-7253] Display relocation message defined in model Move logging to DefaultArtifactDescriptorReader This closes #544 --- .../DefaultProjectDependenciesResolver.java | 12 ------------ .../DefaultArtifactDescriptorReader.java | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 14 deletions(-) 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 7500e43d2a..3644b67ef4 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,18 +181,6 @@ public class DefaultProjectDependenciesResolver depRequest.setRoot( node ); - if ( logger.isWarnEnabled() ) - { - for ( DependencyNode child : node.getChildren() ) - { - if ( !child.getRelocations().isEmpty() ) - { - logger.warn( "The artifact " + child.getRelocations().get( 0 ) + " has been relocated to " - + child.getDependency().getArtifact() ); - } - } - } - 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 c2ba0a3d72..888f4581b4 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,6 +68,8 @@ 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 @@ -77,6 +79,8 @@ import org.eclipse.aether.transfer.ArtifactNotFoundException; public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader, Service { + private static final Logger LOGGER = LoggerFactory.getLogger( DefaultArtifactDescriptorReader.class ); + private RemoteRepositoryManager remoteRepositoryManager; private VersionResolver versionResolver; @@ -316,10 +320,20 @@ public class DefaultArtifactDescriptorReader if ( relocation != null ) { result.addRelocation( a ); - a = + Artifact relocatedArtifact = new RelocatedArtifact( a, relocation.getGroupId(), relocation.getArtifactId(), relocation.getVersion() ); - result.setArtifact( a ); + 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; } else {