Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.8.x][MNG-7349] Limit relocation warning message to direct dependencies only #657

Merged
merged 5 commits into from Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -108,6 +108,18 @@ public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, Rep

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 )
{
Expand Down
Expand Up @@ -181,6 +181,22 @@ public DependencyResolutionResult resolve( DependencyResolutionRequest request )

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 ) );
Expand Down
Expand Up @@ -68,8 +68,6 @@
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
Expand All @@ -79,8 +77,6 @@
public class DefaultArtifactDescriptorReader
implements ArtifactDescriptorReader, Service
{
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultArtifactDescriptorReader.class );

private RemoteRepositoryManager remoteRepositoryManager;

private VersionResolver versionResolver;
Expand Down Expand Up @@ -320,20 +316,10 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques
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
{
Expand Down
Expand Up @@ -29,7 +29,7 @@
/**
* @author Benjamin Bentmann
*/
final class RelocatedArtifact
public final class RelocatedArtifact
hboutemy marked this conversation as resolved.
Show resolved Hide resolved
extends AbstractArtifact
{

Expand All @@ -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()
Expand Down Expand Up @@ -95,7 +98,7 @@ public Artifact setVersion( String version )
{
return this;
}
return new RelocatedArtifact( artifact, groupId, artifactId, version );
return new RelocatedArtifact( artifact, groupId, artifactId, version, message );
}

@Override
Expand All @@ -106,7 +109,7 @@ public Artifact setFile( File file )
{
return this;
}
return new RelocatedArtifact( artifact.setFile( file ), groupId, artifactId, version );
return new RelocatedArtifact( artifact.setFile( file ), groupId, artifactId, version, message );
}

@Override
Expand All @@ -117,7 +120,7 @@ public Artifact setProperties( Map<String, String> properties )
{
return this;
}
return new RelocatedArtifact( artifact.setProperties( properties ), groupId, artifactId, version );
return new RelocatedArtifact( artifact.setProperties( properties ), groupId, artifactId, version, message );
}

public String getClassifier()
Expand Down Expand Up @@ -145,4 +148,8 @@ public Map<String, String> getProperties()
return artifact.getProperties();
}

public String getMessage()
{
return message;
}
}