This is an automated email from the ASF dual-hosted git repository. henning pushed a commit to branch maven-3.8.x in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.8.x by this push: new dc745c43a [MNG-7529] Maven resolver makes bad repository choices (#797) dc745c43a is described below commit dc745c43a5ac37f46b9ba283b9d3e557e2b226df Author: Henning Schmiedehausen <henn...@schmiedehausen.org> AuthorDate: Fri Sep 2 20:24:51 2022 -0700 [MNG-7529] Maven resolver makes bad repository choices (#797) Structure the version checks slightly different to make the separation between repository versions and the version range resolution clearer. Backport from master branch --- .../internal/DefaultVersionRangeResolver.java | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java index a97323629..b4abce4f4 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java @@ -19,6 +19,7 @@ package org.apache.maven.repository.internal; * under the License. */ +import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.eclipse.aether.RepositoryEvent; @@ -72,8 +73,6 @@ public class DefaultVersionRangeResolver private static final String MAVEN_METADATA_XML = "maven-metadata.xml"; - private static final String SNAPSHOT = "SNAPSHOT"; - private MetadataResolver metadataResolver; private SyncContextFactory syncContextFactory; @@ -220,11 +219,12 @@ public class DefaultVersionRangeResolver } Versioning versioning = readVersions( session, trace, metadataResult.getMetadata(), repository, result ); - RemoteRepository remoteRepository = metadataResult.getRequest().getRepository(); + + versioning = filterVersionsByRepositoryType( versioning, metadataResult.getRequest().getRepository() ); for ( String version : versioning.getVersions() ) { - if ( isEnabled( remoteRepository, version ) && !versionIndex.containsKey( version ) ) + if ( !versionIndex.containsKey( version ) ) { versionIndex.put( version, repository ); } @@ -234,19 +234,6 @@ public class DefaultVersionRangeResolver return versionIndex; } - private boolean isEnabled( RemoteRepository remoteRepository, String version ) - { - if ( remoteRepository == null ) - { - return true; - } - - boolean snapshot = version != null && version.endsWith( SNAPSHOT ); - - return remoteRepository.getPolicy( snapshot ).isEnabled(); - } - - private Versioning readVersions( RepositorySystemSession session, RequestTrace trace, Metadata metadata, ArtifactRepository repository, VersionRangeResult result ) { @@ -278,6 +265,26 @@ public class DefaultVersionRangeResolver return ( versioning != null ) ? versioning : new Versioning(); } + private Versioning filterVersionsByRepositoryType( Versioning versioning, RemoteRepository remoteRepository ) + { + if ( remoteRepository == null ) + { + return versioning; + } + + Versioning filteredVersions = versioning.clone(); + + for ( String version : versioning.getVersions() ) + { + if ( !remoteRepository.getPolicy( ArtifactUtils.isSnapshot( version ) ).isEnabled() ) + { + filteredVersions.removeVersion( version ); + } + } + + return filteredVersions; + } + private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata metadata, ArtifactRepository repository, Exception exception ) {