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

#704: Remove remaining ArtifactRepository leftovers + use version range for VersionsHelper where applicable #833

Merged
merged 1 commit into from
Dec 4, 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
14 changes: 10 additions & 4 deletions versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -110,6 +109,13 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<!-- Required by Maven Testing Harness -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
Expand Down Expand Up @@ -175,7 +176,8 @@ public Log getLog()
}

@Override
public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories )
public ArtifactVersions lookupArtifactVersions( Artifact artifact, VersionRange versionRange,
boolean usePluginRepositories )
throws VersionRetrievalException
{
try
Expand All @@ -189,11 +191,14 @@ public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePl
return new ArtifactVersions( artifact,
aetherRepositorySystem.resolveVersionRange( mavenSession.getRepositorySession(),
new VersionRangeRequest(
toArtifact( artifact ).setVersion( "(,)" ),
usePluginRepositories
? mavenSession.getCurrentProject().getRemotePluginRepositories()
: mavenSession.getCurrentProject().getRemoteProjectRepositories(),
"lookupArtifactVersions" ) )
toArtifact( artifact ).setVersion(
versionRange != null
? versionRange.toString()
: "(,)" ),
usePluginRepositories
? mavenSession.getCurrentProject().getRemotePluginRepositories()
: mavenSession.getCurrentProject().getRemoteProjectRepositories(),
"lookupArtifactVersions" ) )
.getVersions()
.parallelStream()
.filter( v -> ignoredVersions.stream()
Expand Down Expand Up @@ -237,6 +242,13 @@ public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePl
}
}

@Override
public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories )
throws VersionRetrievalException
{
return lookupArtifactVersions( artifact, null, usePluginRepositories );
}

/**
* Returns a list of versions which should not be considered when looking for updates.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
Expand All @@ -57,7 +56,6 @@
import org.apache.maven.model.Profile;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.UrlModelSource;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.DefaultProjectBuildingRequest;
Expand Down Expand Up @@ -1523,32 +1521,6 @@ public static MavenProject getLocalRoot( ProjectBuilder projectBuilder,
}
}

/**
* Retrieves the standalone superproject
*
* @param projectBuilder {@link ProjectBuilder} instance
* @param mavenSession {@link MavenSession} instance
* @param logger The logger to log tog
*
* @return superproject retrieved
* @throws ProjectBuildingException if the retrieval fails
*/
public static MavenProject getStandaloneSuperProject( ProjectBuilder projectBuilder,
MavenSession mavenSession,
Log logger ) throws ProjectBuildingException
{
ProjectBuildingResult result = projectBuilder.build( new UrlModelSource(
Objects.requireNonNull( PomHelper.class.getResource( "standalone.xml" ) ) ),
createProjectBuilderRequest( mavenSession, r -> r.setProcessPlugins( false ) ) );
if ( !result.getProblems().isEmpty() )
{
logger.warn( "Problems encountered during building of the superproject." );
result.getProblems().forEach( p ->
logger.warn( "\t" + p.getMessage() ) );
}
return result.getProject();
}

/**
* <p>Convenience method for creating a {@link ProjectBuildingRequest} instance based on maven session.</p>
* <p><u>Note:</u> The method initializes the remote repositories with the remote artifact repositories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -154,6 +155,22 @@ Artifact createDependencyArtifact( String groupId, String artifactId, String ver
ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories )
throws VersionRetrievalException;

/**
* Looks up the versions of the specified artifact that are available in either the local repository, or the
* appropriate remote repositories.
*
* @param artifact The artifact to look for versions of.
* @param versionRange versionRange to restrict the search
* @param usePluginRepositories <code>true</code> will consult the pluginRepositories, while <code>false</code> will
* consult the repositories for normal dependencies.
* @return The details of the available artifact versions.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-alpha-3
*/
ArtifactVersions lookupArtifactVersions( Artifact artifact, VersionRange versionRange,
boolean usePluginRepositories )
throws VersionRetrievalException;

/**
* Looks up the updates for a set of dependencies.
*
Expand Down
7 changes: 0 additions & 7 deletions versions-enforcer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@

import java.util.HashMap;

import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.junit.Test;
Expand Down Expand Up @@ -57,23 +54,17 @@ private static EnforcerRuleHelper mockRuleHelper( MavenProject mavenProject,
when( ruleHelper.evaluate( anyString() ) )
.then( ( a ) -> "${project}".equals( a.getArgument( 0 ) )
? mavenProject
: "${localRepository}".equals( a.getArgument( 0 ) )
? new StubArtifactRepository( "" )
: "${settings}".equals( a.getArgument( 0 ) )
? new Settings()
: "${session}".equals( a.getArgument( 0 ) )
? mockMavenSession()
: "${mojoExecution}".equals( a.getArgument( 0 ) )
? mock( MojoExecution.class )
: null );
: "${session}".equals( a.getArgument( 0 ) )
? mockMavenSession()
: "${mojoExecution}".equals( a.getArgument( 0 ) )
? mock( MojoExecution.class )
: null );
when( ruleHelper.getComponent( ArgumentMatchers.<Class<?>>any() ) )
.then( ( a ) -> a.getArgument( 0 ) == RepositorySystem.class
? mockRepositorySystem()
: a.getArgument( 0 ) == ArtifactResolver.class
? mock( ArtifactResolver.class )
: a.getArgument( 0 ) == org.eclipse.aether.RepositorySystem.class
? aetherRepositorySystem
: null );
: a.getArgument( 0 ) == org.eclipse.aether.RepositorySystem.class
? aetherRepositorySystem
: null );
return ruleHelper;
}

Expand Down
13 changes: 7 additions & 6 deletions versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
Expand Down Expand Up @@ -162,6 +156,13 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<!-- Required by Maven Testing Harness -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
8 changes: 4 additions & 4 deletions versions-maven-plugin/src/it-repo/dummy-maven-plugin-3.1.pom
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
</licenses>

<prerequisites>
<maven>2.0.9</maven>
<maven>3.8.4</maven>
</prerequisites>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>2.0.6</version>
<version>3.8.4</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
Expand All @@ -39,12 +39,12 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0.6</version>
<version>3.8.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.6</version>
<version>3.8.4</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>display-plugin-updates</name>

<prerequisites>
<maven>2.0.6</maven>
<maven>3.2.5</maven>
</prerequisites>
Comment on lines 11 to 13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prerequisites is only used for maven-plugin packaging.


<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def buildLog = new File( basedir, "build.log" ).text

m1 = buildLog =~ /Require Maven 3\.8\.4 to use the following plugin updates:/
m2 = buildLog =~ /localhost:dummy-maven-plugin *\.*\s*\b1\.0 -> 3\.1\b/

assert m1 && m2 && m1.start() < m2.start()
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates -Dversions.outputFile=./dependencyUpdate.txt -Dversions.outputLineWidth=120
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates
invoker.mavenOpts = -Dversions.outputFile=./dependencyUpdate.txt -Dversions.outputLineWidth=60

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert new File( basedir, "dependencyUpdate.txt" ).text =~ /\.{14}/
Loading