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

Replace deprecated ArtifactFactory by RepositorySystem #624

Merged
merged 1 commit into from
Aug 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -231,14 +230,7 @@ protected Artifact toArtifact( Dependency dependency )
Artifact artifact = findArtifact( dependency );
if ( artifact == null )
{
try
{
return getHelper().createDependencyArtifact( dependency );
}
catch ( InvalidVersionSpecificationException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
return getHelper().createDependencyArtifact( dependency );
}
return artifact;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
Expand All @@ -38,6 +37,7 @@
import org.apache.maven.project.path.PathTranslator;
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;
Expand Down Expand Up @@ -82,14 +82,10 @@ public abstract class AbstractVersionsReport
@Parameter( defaultValue = "${project}", required = true, readonly = true )
private MavenProject project;

/**
* @since 1.0-alpha-3
*/
@Component
protected ArtifactFactory artifactFactory;
protected RepositorySystem repositorySystem;

/**
* @component
* @since 1.0-alpha-3
*/
@Component
Expand Down Expand Up @@ -215,7 +211,7 @@ public VersionsHelper getHelper()
{
try
{
helper = new DefaultVersionsHelper( artifactFactory, artifactResolver, artifactMetadataSource,
helper = new DefaultVersionsHelper( repositorySystem, artifactResolver, artifactMetadataSource,
remoteArtifactRepositories, remotePluginRepositories,
localRepository, wagonManager, settings, serverId, rulesUri,
getLog(), session, pathTranslator );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.path.PathTranslator;
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;
Expand Down Expand Up @@ -80,11 +81,8 @@ public abstract class AbstractVersionsUpdaterMojo
@Parameter( defaultValue = "${project}", required = true, readonly = true )
protected MavenProject project;

/**
* @since 1.0-alpha-1
*/
@Component
protected org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;
protected RepositorySystem repositorySystem;

/**
* @since 1.0-alpha-1
Expand Down Expand Up @@ -131,7 +129,6 @@ public abstract class AbstractVersionsUpdaterMojo
protected ArtifactRepository localRepository;

/**
* @component
* @since 1.0-alpha-3
*/
@Component
Expand Down Expand Up @@ -223,7 +220,7 @@ public VersionsHelper getHelper()
{
if ( helper == null )
{
helper = new DefaultVersionsHelper( artifactFactory, artifactResolver, artifactMetadataSource,
helper = new DefaultVersionsHelper( repositorySystem, artifactResolver, artifactMetadataSource,
remoteArtifactRepositories, remotePluginRepositories, localRepository,
wagonManager, settings, serverId, rulesUri, getLog(), session,
pathTranslator );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.TreeSet;

import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -178,7 +177,7 @@ else if ( "xml".equals( format ) )
}
}
}
catch ( InvalidVersionSpecificationException| ArtifactMetadataRetrievalException e )
catch ( ArtifactMetadataRetrievalException e )
{
throw new MavenReportException( e.getMessage(), e );
}
Expand Down Expand Up @@ -231,4 +230,4 @@ public String getOutputName()
return "dependency-updates-report";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
Expand Down Expand Up @@ -153,6 +152,7 @@ public class DisplayDependencyUpdatesMojo
* @deprecated This will be removed with version 3.0.0
* @since 2.5
*/
@Deprecated
@Parameter(property = "allowAnyUpdates", defaultValue = "true")
private boolean allowAnyUpdates;

Expand Down Expand Up @@ -388,7 +388,7 @@ public void execute()
logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" );
}
}
catch ( InvalidVersionSpecificationException | ArtifactMetadataRetrievalException e )
catch ( ArtifactMetadataRetrievalException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -72,9 +73,13 @@ public void execute()
throw new MojoExecutionException( "Invalid version range specification: " + version, e );
}

Artifact artifact = artifactFactory.createDependencyArtifact( getProject().getParent().getGroupId(),
getProject().getParent().getArtifactId(),
versionRange, "pom", null, null );
Dependency dependency = new Dependency();
dependency.setGroupId( getProject().getParent().getGroupId() );
dependency.setArtifactId( getProject().getParent().getArtifactId() );
dependency.setVersion( version );
dependency.setType( "pom" );

Artifact artifact = getHelper().createDependencyArtifact( dependency );

ArtifactVersion artifactVersion;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.RuntimeInformation;
import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
Expand Down Expand Up @@ -148,7 +148,6 @@ public class DisplayPluginUpdatesMojo
/**
* The plugin manager.
*
* @component
* @since 1.0-alpha-1
*/
@Component
Expand Down Expand Up @@ -414,18 +413,8 @@ public void execute()
getLog().debug( "Checking " + coords + " for updates newer than " + version );
String effectiveVersion = version;

Artifact artifactRange;
try
{
boolean unspecified = ( version == null );
VersionRange versionRange = unspecified ? VersionRange.createFromVersionSpec( "[0,)" )
: VersionRange.createFromVersionSpec( version );
artifactRange = artifactFactory.createPluginArtifact( groupId, artifactId, versionRange );
}
catch ( InvalidVersionSpecificationException e )
{
throw new MojoExecutionException( "Invalid version range specification: " + version, e );
}
Artifact artifactRange = getHelper().createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(),
version );

ArtifactVersion artifactVersion = null;
try
Expand All @@ -436,10 +425,15 @@ public void execute()
ArtifactVersion minRequires = null;
for ( int j = newerVersions.length - 1; j >= 0; j-- )
{
Artifact probe =
artifactFactory.createDependencyArtifact( groupId, artifactId,
VersionRange.createFromVersion( newerVersions[j].toString() ),
"pom", null, "runtime" );

Dependency dependency = new Dependency();
dependency.setGroupId( groupId );
dependency.setArtifactId( artifactId );
dependency.setVersion( newerVersions[j].toString() );
dependency.setType( "pom" );
dependency.setScope( "runtime" );

Artifact probe = getHelper().createDependencyArtifact( dependency );
try
{
getHelper().resolveArtifact( probe, true );
Expand Down Expand Up @@ -495,9 +489,14 @@ public void execute()
}
if ( effectiveVersion != null )
{
VersionRange currentVersionRange = VersionRange.createFromVersion( effectiveVersion );
Artifact probe = artifactFactory.createDependencyArtifact( groupId, artifactId, currentVersionRange,
"pom", null, "runtime" );
Dependency dependency = new Dependency();
dependency.setGroupId( groupId );
dependency.setArtifactId( artifactId );
dependency.setVersion( effectiveVersion );
dependency.setType( "pom" );
dependency.setScope( "runtime" );

Artifact probe = getHelper().createDependencyArtifact( dependency );
try
{
getHelper().resolveArtifact( probe, true );
Expand Down Expand Up @@ -769,7 +768,7 @@ private Map<String, String> getParentsPlugins( List<MavenProject> parents )
map.keySet().retainAll( withVersionSpecified );
parentPlugins.putAll( map );
}
catch ( IOException | XMLStreamException e )
catch ( XMLStreamException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
Expand Down Expand Up @@ -851,7 +850,7 @@ private Set<String> findPluginsWithVersionsSpecified( MavenProject project )
* @return a set of Strings which correspond to the plugin coordinates where there is a version specified.
*/
private Set<String> findPluginsWithVersionsSpecified( StringBuilder pomContents, String path )
throws IOException, XMLStreamException
throws XMLStreamException
{
Set<String> result = new HashSet<>();
ModifiedPomXMLEventReader pom = newModifiedPomXER( pomContents, path );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import javax.xml.stream.XMLStreamException;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -193,10 +192,7 @@ private String resolveSnapshotVersion( Dependency dep )

try
{
Artifact depArtifact =
artifactFactory.createDependencyArtifact( dep.getGroupId(), dep.getArtifactId(),
VersionRange.createFromVersionSpec( dep.getVersion() ),
dep.getType(), dep.getClassifier(), dep.getScope() );
Artifact depArtifact = getHelper().createDependencyArtifact( dep );
resolver.resolve( depArtifact, getProject().getRemoteArtifactRepositories(), localRepository );

lockedVersion = depArtifact.getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -136,7 +135,7 @@ else if ( "xml".equals( format ) )
}
}
}
catch ( InvalidVersionSpecificationException | ArtifactMetadataRetrievalException e )
catch ( ArtifactMetadataRetrievalException e )
{
throw new MavenReportException( e.getMessage(), e );
}
Expand Down Expand Up @@ -183,4 +182,4 @@ public String getOutputName()
return "plugin-updates-report";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -106,8 +107,12 @@ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionExcep
throw new MojoExecutionException( "Invalid version range specification: " + version, e );
}

Artifact artifact = artifactFactory.createDependencyArtifact( getProject().getParent().getGroupId(),
getProject().getParent().getArtifactId(), versionRange, "pom", null, null );
Dependency dependency = new Dependency();
dependency.setGroupId( getProject().getParent().getGroupId() );
dependency.setArtifactId( getProject().getParent().getArtifactId() );
dependency.setVersion( version );
dependency.setType( "pom" );
Artifact artifact = getHelper().createDependencyArtifact( dependency );

ArtifactVersion artifactVersion;
try
Expand Down
23 changes: 8 additions & 15 deletions src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -119,20 +117,15 @@ private void useReleases( ModifiedPomXMLEventReader pom, MavenProject project )
{
String releaseVersion = versionMatcher.group( 1 );

VersionRange versionRange;
try
{
versionRange = VersionRange.createFromVersionSpec( releaseVersion );
}
catch ( InvalidVersionSpecificationException e )
{
throw new MojoExecutionException( "Invalid version range specification: " + version, e );
}

final MavenProject parent = getProject().getParent();
Artifact artifact = artifactFactory.createDependencyArtifact( parent.getGroupId(),
parent.getArtifactId(),
versionRange, "pom", null, null );

Dependency dependency = new Dependency();
dependency.setGroupId( parent.getGroupId() );
dependency.setArtifactId( parent.getArtifactId() );
dependency.setVersion( releaseVersion );
dependency.setType( "pom" );

Artifact artifact = getHelper().createDependencyArtifact( dependency );
if ( !isIncluded( artifact ) )
{
return;
Expand Down
Loading