Skip to content

Commit

Permalink
#704: Removing ArtifactResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Nov 24, 2022
1 parent 44883ad commit 4dde10c
Show file tree
Hide file tree
Showing 50 changed files with 94 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -89,9 +85,12 @@
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.VersionRangeRequest;
import org.eclipse.aether.resolution.VersionRangeResolutionException;

import static org.apache.maven.RepositoryUtils.toArtifact;

/**
* Helper class that provides common functionality required by both the mojos and the reports.
*
Expand All @@ -116,13 +115,6 @@ public class DefaultVersionsHelper
*/
private RuleSet ruleSet;

/**
* The local repository to consult.
*
* @since 1.0-alpha-3
*/
private ArtifactRepository localRepository;

private RepositorySystem repositorySystem;

private org.eclipse.aether.RepositorySystem aetherRepositorySystem;
Expand All @@ -141,13 +133,6 @@ public class DefaultVersionsHelper
*/
private MavenSession mavenSession;

/**
* The artifact resolver.
*
* @since 1.3
*/
private ArtifactResolver artifactResolver;

private MojoExecution mojoExecution;

/**
Expand Down Expand Up @@ -383,7 +368,7 @@ public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePl
return new ArtifactVersions( artifact,
aetherRepositorySystem.resolveVersionRange( mavenSession.getRepositorySession(),
new VersionRangeRequest(
RepositoryUtils.toArtifact( artifact ).setVersion( "(,)" ),
toArtifact( artifact ).setVersion( "(,)" ),
usePluginRepositories
? mavenSession.getCurrentProject().getRemotePluginRepositories()
: mavenSession.getCurrentProject().getRemoteProjectRepositories(),
Expand Down Expand Up @@ -479,13 +464,21 @@ private List<IgnoreVersion> getIgnoredVersions( Artifact artifact )

@Override
public void resolveArtifact( Artifact artifact, boolean usePluginRepositories )
throws ArtifactResolutionException, ArtifactNotFoundException
throws ArtifactResolutionException
{
artifactResolver.resolve( artifact,
usePluginRepositories
? mavenSession.getCurrentProject().getPluginArtifactRepositories()
: mavenSession.getCurrentProject().getRemoteArtifactRepositories(),
localRepository );
try
{
aetherRepositorySystem.resolveArtifact( mavenSession.getRepositorySession(),
new ArtifactRequest( toArtifact( artifact ),
usePluginRepositories
? mavenSession.getCurrentProject().getRemotePluginRepositories()
: mavenSession.getCurrentProject().getRemoteProjectRepositories(),
getClass().getName() ) );
}
catch ( org.eclipse.aether.resolution.ArtifactResolutionException e )
{
throw new ArtifactResolutionException( e.getMessage(), artifact );
}
}

@Override
Expand Down Expand Up @@ -882,8 +875,6 @@ public Dependency interpolateVersion( final Dependency dependency, final MavenPr
public static class Builder
{
private RepositorySystem repositorySystem;
private ArtifactResolver artifactResolver;
private ArtifactRepository localRepository;
private Collection<String> ignoredVersions;
private RuleSet ruleSet;
private WagonManager wagonManager;
Expand All @@ -905,18 +896,6 @@ public Builder withRepositorySystem( RepositorySystem repositorySystem )
return this;
}

public Builder withArtifactResolver( ArtifactResolver artifactResolver )
{
this.artifactResolver = artifactResolver;
return this;
}

public Builder withLocalRepository( ArtifactRepository localRepository )
{
this.localRepository = localRepository;
return this;
}

public Builder withIgnoredVersions( Collection<String> ignoredVersions )
{
this.ignoredVersions = ignoredVersions;
Expand Down Expand Up @@ -986,7 +965,6 @@ public DefaultVersionsHelper build() throws MojoExecutionException
{
DefaultVersionsHelper instance = new DefaultVersionsHelper();
instance.repositorySystem = repositorySystem;
instance.artifactResolver = artifactResolver;
instance.mavenSession = mavenSession;
instance.mojoExecution = mojoExecution;
if ( ruleSet != null )
Expand All @@ -1011,7 +989,6 @@ public DefaultVersionsHelper build() throws MojoExecutionException
instance.ruleSet = enrichRuleSet( ignoredVersions, instance.ruleSet );
}
instance.aetherRepositorySystem = aetherRepositorySystem;
instance.localRepository = localRepository;
instance.log = log;
return instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.model.Dependency;
Expand Down Expand Up @@ -408,12 +407,11 @@ public VersionPropertiesMapRequest build()
*
* @param artifact The artifact to resolve.
* @param usePluginRepositories whether to resolve from the plugin repositories or the regular repositories.
* @throws ArtifactResolutionException if something goes wrong.
* @throws ArtifactNotFoundException if something goes wrong.
* @throws ArtifactResolutionException if resolution is unsuccessful
* @since 1.3
*/
void resolveArtifact( Artifact artifact, boolean usePluginRepositories )
throws ArtifactResolutionException, ArtifactNotFoundException;
throws ArtifactResolutionException;

/**
* Attempts to interpolate the version from model properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
Expand Down Expand Up @@ -234,10 +231,7 @@ private DefaultVersionsHelper createHelper( org.eclipse.aether.RepositorySystem
.thenReturn( emptyList() );
return new DefaultVersionsHelper.Builder()
.withRepositorySystem( lookup( RepositorySystem.class ) )
.withArtifactResolver( new DefaultArtifactResolver() )
.withAetherRepositorySystem( aetherRepositorySystem )
.withLocalRepository( new DefaultArtifactRepository(
"", "", new DefaultRepositoryLayout() ) )
.withWagonManager( lookup( WagonManager.class ) )
.withSettings( new Settings() )
.withServerId( "" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
Expand Down Expand Up @@ -162,11 +161,9 @@ protected AbstractVersionsDependencyUpdaterMojo( RepositorySystem repositorySyst
org.eclipse.aether.RepositorySystem aetherRepositorySystem,
MavenProjectBuilder projectBuilder,
WagonManager wagonManager,
ArtifactResolver artifactResolver,
Map<String, ChangeRecorder> changeRecorders )
{
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver,
changeRecorders );
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, changeRecorders );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.repository.RepositorySystem;
Expand Down Expand Up @@ -89,11 +88,9 @@ protected AbstractVersionsDisplayMojo( RepositorySystem repositorySystem,
org.eclipse.aether.RepositorySystem aetherRepositorySystem,
MavenProjectBuilder projectBuilder,
WagonManager wagonManager,
ArtifactResolver artifactResolver,
Map<String, ChangeRecorder> changeRecorders )
{
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver,
changeRecorders );
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, changeRecorders );
}

@SuppressWarnings( "unchecked" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.doxia.sink.Sink;
Expand Down Expand Up @@ -156,8 +155,6 @@ public abstract class AbstractVersionsReport<T>
@Parameter( defaultValue = "${mojoExecution}", required = true, readonly = true )
private MojoExecution mojoExecution;

protected ArtifactResolver artifactResolver;

/**
* <p>Allows specifying the {@linkplain RuleSet} object describing rules
* on artifact versions to ignore when considering updates.</p>
Expand Down Expand Up @@ -196,14 +193,12 @@ public abstract class AbstractVersionsReport<T>

protected AbstractVersionsReport( I18N i18n, RepositorySystem repositorySystem,
org.eclipse.aether.RepositorySystem aetherRepositorySystem,
ArtifactResolver artifactResolver,
WagonManager wagonManager,
ReportRendererFactory rendererFactory )
{
this.i18n = i18n;
this.repositorySystem = repositorySystem;
this.aetherRepositorySystem = aetherRepositorySystem;
this.artifactResolver = artifactResolver;
this.wagonManager = wagonManager;
this.rendererFactory = rendererFactory;
}
Expand All @@ -217,9 +212,7 @@ public VersionsHelper getHelper()
{
helper = new DefaultVersionsHelper.Builder()
.withRepositorySystem( repositorySystem )
.withArtifactResolver( artifactResolver )
.withAetherRepositorySystem( aetherRepositorySystem )
.withLocalRepository( localRepository )
.withWagonManager( wagonManager )
.withSettings( settings )
.withServerId( serverId )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
Expand Down Expand Up @@ -110,24 +107,6 @@ public abstract class AbstractVersionsUpdaterMojo
@Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
protected List<MavenProject> reactorProjects;

/**
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
protected List<ArtifactRepository> remoteArtifactRepositories;

/**
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true )
protected List<ArtifactRepository> remotePluginRepositories;

/**
* @since 1.0-alpha-1
*/
@Parameter( defaultValue = "${localRepository}", readonly = true )
protected ArtifactRepository localRepository;

/**
* The (injected) {@link WagonManager} instance.
*/
Expand Down Expand Up @@ -189,7 +168,6 @@ public abstract class AbstractVersionsUpdaterMojo
@Parameter( defaultValue = "${mojoExecution}", required = true, readonly = true )
private MojoExecution mojoExecution;

protected ArtifactResolver artifactResolver;
/**
* The format used to record changes. If "none" is specified, no changes are recorded.
*
Expand Down Expand Up @@ -245,14 +223,12 @@ protected AbstractVersionsUpdaterMojo( RepositorySystem repositorySystem,
org.eclipse.aether.RepositorySystem aetherRepositorySystem,
MavenProjectBuilder projectBuilder,
WagonManager wagonManager,
ArtifactResolver artifactResolver,
Map<String, ChangeRecorder> changeRecorders )
{
this.repositorySystem = repositorySystem;
this.aetherRepositorySystem = aetherRepositorySystem;
this.projectBuilder = projectBuilder;
this.wagonManager = wagonManager;
this.artifactResolver = artifactResolver;
this.changeRecorders = changeRecorders;
}

Expand All @@ -262,9 +238,7 @@ public VersionsHelper getHelper() throws MojoExecutionException
{
helper = new DefaultVersionsHelper.Builder()
.withRepositorySystem( repositorySystem )
.withArtifactResolver( artifactResolver )
.withAetherRepositorySystem( aetherRepositorySystem )
.withLocalRepository( localRepository )
.withWagonManager( wagonManager )
.withSettings( settings )
.withServerId( serverId )
Expand Down Expand Up @@ -522,18 +496,13 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
artifact.setVersion( updateVersion.toString() );
try
{
artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository );
getHelper().resolveArtifact( artifact, false );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactResolutionException | MojoExecutionException e )
{
getLog().warn( "Not updating version: could not resolve " + artifact, e );
return false;
}
catch ( ArtifactNotFoundException e )
{
getLog().warn( "Not updating version: could not find " + artifact, e );
return false;
}

if ( currentVersion.equals( updateVersion.toString() ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -130,12 +129,10 @@ public CompareDependenciesMojo( RepositorySystem repositorySystem,
org.eclipse.aether.RepositorySystem aetherRepositorySystem,
MavenProjectBuilder projectBuilder,
WagonManager wagonManager,
ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder,
Map<String, ChangeRecorder> changeRecorders )
{
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver,
changeRecorders );
super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, changeRecorders );
this.mavenProjectBuilder = mavenProjectBuilder;
}

Expand Down Expand Up @@ -177,7 +174,9 @@ protected void update( ModifiedPomXMLEventReader pom )
try
{
remoteMavenProject =
mavenProjectBuilder.buildFromRepository( remoteArtifact, remoteArtifactRepositories, localRepository );
mavenProjectBuilder.buildFromRepository( remoteArtifact,
session.getCurrentProject().getRemoteArtifactRepositories(),
session.getLocalRepository() );
}
catch ( ProjectBuildingException e )
{
Expand Down
Loading

0 comments on commit 4dde10c

Please sign in to comment.