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 27, 2022
1 parent badd0c4 commit 4abe0bb
Show file tree
Hide file tree
Showing 51 changed files with 129 additions and 307 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,13 @@
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.ArtifactResult;
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 +116,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 +134,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 +369,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 +465,24 @@ 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
{
ArtifactResult artifactResult = aetherRepositorySystem.resolveArtifact( mavenSession.getRepositorySession(),
new ArtifactRequest( toArtifact( artifact ),
usePluginRepositories
? mavenSession.getCurrentProject().getRemotePluginRepositories()
: mavenSession.getCurrentProject().getRemoteProjectRepositories(),
getClass().getName() ) );
artifact.setFile( artifactResult.getArtifact().getFile() );
artifact.setVersion( artifactResult.getArtifact().getVersion() );
artifact.setResolved( artifactResult.isResolved() );
}
catch ( org.eclipse.aether.resolution.ArtifactResolutionException e )
{
throw new ArtifactResolutionException( e.getMessage(), artifact );
}
}

@Override
Expand Down Expand Up @@ -864,12 +861,9 @@ else if ( !excludePropertiesList.isEmpty() && excludePropertiesList.contains( pr
public static class Builder
{
private RepositorySystem repositorySystem;
private ArtifactResolver artifactResolver;
private ArtifactRepository localRepository;
private Collection<String> ignoredVersions;
private RuleSet ruleSet;
private WagonManager wagonManager;
private Settings settings;
private String serverId;
private String rulesUri;
private Log log;
Expand All @@ -887,18 +881,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 All @@ -917,12 +899,6 @@ public Builder withWagonManager( WagonManager wagonManager )
return this;
}

public Builder withSettings( Settings settings )
{
this.settings = settings;
return this;
}

public Builder withServerId( String serverId )
{
this.serverId = serverId;
Expand Down Expand Up @@ -968,7 +944,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 @@ -984,16 +959,15 @@ public DefaultVersionsHelper build() throws MojoExecutionException
instance.ruleSet = isBlank( rulesUri )
? new RuleSet()
: isClasspathUri( rulesUri )
? getRulesFromClasspath( rulesUri, log )
: getRulesViaWagon( rulesUri, log, serverId, serverId, wagonManager,
settings );
? getRulesFromClasspath( rulesUri, log )
: getRulesViaWagon( rulesUri, log, serverId, serverId, wagonManager,
mavenSession.getSettings() );
}
if ( ignoredVersions != null && !ignoredVersions.isEmpty() )
{
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,10 +407,9 @@ 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;
}
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 All @@ -41,7 +38,6 @@
import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.versions.model.IgnoreVersion;
import org.codehaus.mojo.versions.model.Rule;
import org.codehaus.mojo.versions.model.RuleSet;
Expand Down Expand Up @@ -234,12 +230,8 @@ 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( "" )
.withRulesUri( rulesUri )
.withLog( mock( Log.class ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.util.stream.Collectors;

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.enforcer.rule.api.EnforcerLevel;
import org.apache.maven.enforcer.rule.api.EnforcerRule;
Expand All @@ -40,7 +38,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.DefaultVersionsHelper;
import org.codehaus.mojo.versions.api.Segment;
Expand Down Expand Up @@ -278,11 +275,8 @@ private static VersionsHelper createVersionsHelper( EnforcerRuleHelper ruleHelpe
{
return new DefaultVersionsHelper.Builder()
.withRepositorySystem( ruleHelper.getComponent( RepositorySystem.class ) )
.withArtifactResolver( ruleHelper.getComponent( ArtifactResolver.class ) )
.withAetherRepositorySystem( ruleHelper.getComponent( org.eclipse.aether.RepositorySystem.class ) )
.withLocalRepository( (ArtifactRepository) ruleHelper.evaluate( "${localRepository}" ) )
.withWagonManager( ruleHelper.getComponent( WagonManager.class ) )
.withSettings( (Settings) ruleHelper.evaluate( "${settings}" ) )
.withServerId( serverId )
.withRulesUri( rulesUri )
.withRuleSet( ruleSet )
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 All @@ -40,7 +39,6 @@
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.api.DefaultVersionsHelper;
import org.codehaus.mojo.versions.api.VersionRetrievalException;
Expand Down Expand Up @@ -98,12 +96,6 @@ public abstract class AbstractVersionsReport<T>
*/
private final WagonManager wagonManager;

/**
* @since 1.0-alpha-3
*/
@Parameter( defaultValue = "${settings}", readonly = true )
private Settings settings;

/**
* settings.xml's server id for the URL. This is used when wagon needs extra authentication information.
*
Expand Down Expand Up @@ -156,8 +148,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 +186,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,11 +205,8 @@ public VersionsHelper getHelper()
{
helper = new DefaultVersionsHelper.Builder()
.withRepositorySystem( repositorySystem )
.withArtifactResolver( artifactResolver )
.withAetherRepositorySystem( aetherRepositorySystem )
.withLocalRepository( localRepository )
.withWagonManager( wagonManager )
.withSettings( settings )
.withServerId( serverId )
.withRulesUri( rulesUri )
.withRuleSet( ruleSet )
Expand Down
Loading

0 comments on commit 4abe0bb

Please sign in to comment.