Skip to content
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 @@ -523,6 +523,22 @@ public final class Constants {
@Config(type = "java.lang.Integer", defaultValue = "100")
public static final String MAVEN_BUILDER_MAX_PROBLEMS = "maven.builder.maxProblems";

/**
* Configuration property for version range resolution used metadata "nature".
* It may contain following string values:
* <ul>
* <li>"auto" - decision done based on range being resolver: if any boundary is snapshot, use "release_or_snapshot", otherwise "release"</li>
* <li>"release_or_snapshot" - the default</li>
* <li>"release" - query only release repositories to discover versions</li>
* <li>"snapshot" - query only snapshot repositories to discover versions</li>
* </ul>
* Default (when unset) is existing Maven behaviour: "release_or_snapshots".
* @since 4.0.0
Copy link
Member

Choose a reason for hiding this comment

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

4.1.0 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@gnodet this needs backport to 4.0.0, but do I need to backport it manually or we have some automation?

Copy link
Member Author

Choose a reason for hiding this comment

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

and is 4.0.0 as if you check #2574 the property is different: 3.x uses 3.x "way of naming", and 4.x already had maven.versionResolver... so this introduced maven.versionRangeResolver... prop

Copy link
Contributor

Choose a reason for hiding this comment

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

@gnodet this needs backport to 4.0.0, but do I need to backport it manually or we have some automation?

We don't. I haven't been able to setup something that would work without a global GH access token as a secret. I may have missed something though.
Anyway, I've been using backport so far.

*/
@Config(defaultValue = "release_or_snapshot")
public static final String MAVEN_VERSION_RANGE_RESOLVER_NATURE_OVERRIDE =
"maven.versionRangeResolver.natureOverride";

/**
* All system properties used by Maven Logger start with this prefix.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.api.Constants;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.repository.metadata.Versioning;
import org.apache.maven.metadata.v4.MetadataStaxReader;
Expand All @@ -53,6 +55,7 @@
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.eclipse.aether.spi.synccontext.SyncContextFactory;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionConstraint;
Expand Down Expand Up @@ -107,11 +110,37 @@ public VersionRangeResult resolveVersionRange(RepositorySystemSession session, V
result.addVersion(versionConstraint.getVersion());
} else {
VersionRange.Bound lowerBound = versionConstraint.getRange().getLowerBound();
VersionRange.Bound upperBound = versionConstraint.getRange().getUpperBound();
if (lowerBound != null
&& lowerBound.equals(versionConstraint.getRange().getUpperBound())) {
result.addVersion(lowerBound.getVersion());
} else {
Map<String, ArtifactRepository> versionIndex = getVersions(session, result, request);
Metadata.Nature wantedNature;
String natureString = ConfigUtils.getString(
session,
Metadata.Nature.RELEASE_OR_SNAPSHOT.name(),
Constants.MAVEN_VERSION_RANGE_RESOLVER_NATURE_OVERRIDE);
if ("auto".equals(natureString)) {
org.eclipse.aether.artifact.Artifact lowerArtifact = lowerBound != null
? request.getArtifact()
.setVersion(lowerBound.getVersion().toString())
: null;
org.eclipse.aether.artifact.Artifact upperArtifact = upperBound != null
? request.getArtifact()
.setVersion(upperBound.getVersion().toString())
: null;

if (lowerArtifact != null && lowerArtifact.isSnapshot()
|| upperArtifact != null && upperArtifact.isSnapshot()) {
wantedNature = Metadata.Nature.RELEASE_OR_SNAPSHOT;
} else {
wantedNature = Metadata.Nature.RELEASE;
}
} else {
wantedNature = Metadata.Nature.valueOf(natureString.toUpperCase(Locale.ROOT));
}

Map<String, ArtifactRepository> versionIndex = getVersions(session, result, request, wantedNature);

List<Version> versions = new ArrayList<>();
for (Map.Entry<String, ArtifactRepository> v : versionIndex.entrySet()) {
Expand All @@ -135,7 +164,10 @@ public VersionRangeResult resolveVersionRange(RepositorySystemSession session, V
}

private Map<String, ArtifactRepository> getVersions(
RepositorySystemSession session, VersionRangeResult result, VersionRangeRequest request) {
RepositorySystemSession session,
VersionRangeResult result,
VersionRangeRequest request,
Metadata.Nature wantedNature) {
RequestTrace trace = RequestTrace.newChild(request.getTrace(), request);

Map<String, ArtifactRepository> versionIndex = new HashMap<>();
Expand All @@ -144,7 +176,7 @@ private Map<String, ArtifactRepository> getVersions(
request.getArtifact().getGroupId(),
request.getArtifact().getArtifactId(),
MAVEN_METADATA_XML,
Metadata.Nature.RELEASE_OR_SNAPSHOT);
wantedNature);

List<MetadataRequest> metadataRequests =
new ArrayList<>(request.getRepositories().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.api.Constants;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
Expand All @@ -52,6 +54,7 @@
import org.eclipse.aether.resolution.VersionRangeResolutionException;
import org.eclipse.aether.resolution.VersionRangeResult;
import org.eclipse.aether.spi.synccontext.SyncContextFactory;
import org.eclipse.aether.util.ConfigUtils;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import org.eclipse.aether.version.VersionConstraint;
Expand Down Expand Up @@ -104,11 +107,36 @@ public VersionRangeResult resolveVersionRange(RepositorySystemSession session, V
result.addVersion(versionConstraint.getVersion());
} else {
VersionRange.Bound lowerBound = versionConstraint.getRange().getLowerBound();
if (lowerBound != null
&& lowerBound.equals(versionConstraint.getRange().getUpperBound())) {
VersionRange.Bound upperBound = versionConstraint.getRange().getUpperBound();
if (lowerBound != null && lowerBound.equals(upperBound)) {
result.addVersion(lowerBound.getVersion());
} else {
Map<String, ArtifactRepository> versionIndex = getVersions(session, result, request);
Metadata.Nature wantedNature;
String natureString = ConfigUtils.getString(
session,
Metadata.Nature.RELEASE_OR_SNAPSHOT.name(),
Constants.MAVEN_VERSION_RANGE_RESOLVER_NATURE_OVERRIDE);
if ("auto".equals(natureString)) {
org.eclipse.aether.artifact.Artifact lowerArtifact = lowerBound != null
? request.getArtifact()
.setVersion(lowerBound.getVersion().toString())
: null;
org.eclipse.aether.artifact.Artifact upperArtifact = upperBound != null
? request.getArtifact()
.setVersion(upperBound.getVersion().toString())
: null;

if (lowerArtifact != null && lowerArtifact.isSnapshot()
|| upperArtifact != null && upperArtifact.isSnapshot()) {
wantedNature = Metadata.Nature.RELEASE_OR_SNAPSHOT;
} else {
wantedNature = Metadata.Nature.RELEASE;
}
} else {
wantedNature = Metadata.Nature.valueOf(natureString.toUpperCase(Locale.ROOT));
}

Map<String, ArtifactRepository> versionIndex = getVersions(session, result, request, wantedNature);

List<Version> versions = new ArrayList<>();
for (Map.Entry<String, ArtifactRepository> v : versionIndex.entrySet()) {
Expand All @@ -132,7 +160,10 @@ public VersionRangeResult resolveVersionRange(RepositorySystemSession session, V
}

private Map<String, ArtifactRepository> getVersions(
RepositorySystemSession session, VersionRangeResult result, VersionRangeRequest request) {
RepositorySystemSession session,
VersionRangeResult result,
VersionRangeRequest request,
Metadata.Nature wantedNature) {
RequestTrace trace = RequestTrace.newChild(request.getTrace(), request);

Map<String, ArtifactRepository> versionIndex = new HashMap<>();
Expand All @@ -141,7 +172,7 @@ private Map<String, ArtifactRepository> getVersions(
request.getArtifact().getGroupId(),
request.getArtifact().getArtifactId(),
MAVEN_METADATA_XML,
Metadata.Nature.RELEASE_OR_SNAPSHOT);
wantedNature);

List<MetadataRequest> metadataRequests =
new ArrayList<>(request.getRepositories().size());
Expand Down
18 changes: 12 additions & 6 deletions src/site/markdown/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Generated from: maven-resolver-tools/src/main/resources/configuration.properties.vm
# To modify this file, edit the template and regenerate.
#
props.count = 64
props.count = 65
props.1.key = maven.build.timestamp.format
props.1.configurationType = String
props.1.description = Build timestamp format.
Expand Down Expand Up @@ -397,9 +397,15 @@ props.63.description = Maven snapshot: contains "true" if this Maven is a snapsh
props.63.defaultValue =
props.63.since = 4.0.0
props.63.configurationSource = system_properties
props.64.key = maven.versionResolver.noCache
props.64.configurationType = Boolean
props.64.description = User property for disabling version resolver cache.
props.64.defaultValue = false
props.64.since = 3.0.0
props.64.key = maven.versionRangeResolver.natureOverride
props.64.configurationType = String
props.64.description = Configuration property for version range resolution used metadata "nature". It may contain following string values: <ul> <li>"auto" - decision done based on range being resolver: if any boundary is snapshot, use "release_or_snapshot", otherwise "release"</li> <li>"release_or_snapshot" - the default</li> <li>"release" - query only release repositories to discover versions</li> <li>"snapshot" - query only snapshot repositories to discover versions</li> </ul> Default (when unset) is existing Maven behaviour: "release_or_snapshots".
props.64.defaultValue = release_or_snapshot
props.64.since = 4.0.0
props.64.configurationSource = User properties
props.65.key = maven.versionResolver.noCache
props.65.configurationType = Boolean
props.65.description = User property for disabling version resolver cache.
props.65.defaultValue = false
props.65.since = 3.0.0
props.65.configurationSource = User properties
6 changes: 6 additions & 0 deletions src/site/markdown/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ props:
defaultValue:
since: 4.0.0
configurationSource: system_properties
- key: maven.versionRangeResolver.natureOverride
configurationType: String
description: "Configuration property for version range resolution used metadata \"nature\". It may contain following string values: <ul> <li>\"auto\" - decision done based on range being resolver: if any boundary is snapshot, use \"release_or_snapshot\", otherwise \"release\"</li> <li>\"release_or_snapshot\" - the default</li> <li>\"release\" - query only release repositories to discover versions</li> <li>\"snapshot\" - query only snapshot repositories to discover versions</li> </ul> Default (when unset) is existing Maven behaviour: \"release_or_snapshots\"."
defaultValue: release_or_snapshot
since: 4.0.0
configurationSource: User properties
- key: maven.versionResolver.noCache
configurationType: Boolean
description: "User property for disabling version resolver cache."
Expand Down
1 change: 1 addition & 0 deletions src/site/markdown/maven-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ To modify this file, edit the template and regenerate.
| `maven.version.minor` | `String` | Maven minor version: contains the minor segment of this Maven version. | - | 4.0.0 | system_properties |
| `maven.version.patch` | `String` | Maven patch version: contains the patch segment of this Maven version. | - | 4.0.0 | system_properties |
| `maven.version.snapshot` | `String` | Maven snapshot: contains "true" if this Maven is a snapshot version. | - | 4.0.0 | system_properties |
| `maven.versionRangeResolver.natureOverride` | `String` | Configuration property for version range resolution used metadata "nature". It may contain following string values: <ul> <li>"auto" - decision done based on range being resolver: if any boundary is snapshot, use "release_or_snapshot", otherwise "release"</li> <li>"release_or_snapshot" - the default</li> <li>"release" - query only release repositories to discover versions</li> <li>"snapshot" - query only snapshot repositories to discover versions</li> </ul> Default (when unset) is existing Maven behaviour: "release_or_snapshots". | `release_or_snapshot` | 4.0.0 | User properties |
| `maven.versionResolver.noCache` | `Boolean` | User property for disabling version resolver cache. | `false` | 3.0.0 | User properties |