Skip to content

Commit c9b724c

Browse files
authored
Maven 4.x w/ Resolver 2.0.14-SNAPSHOT (#11473)
Changes: * update to Resolver 2.0.14 * use per-request metadata nature in version range requests * apply required code changes * use new TrackingFileManager in maven-compat upgrade check manager
1 parent a5faf4e commit c9b724c

File tree

18 files changed

+404
-149
lines changed

18 files changed

+404
-149
lines changed

.mvn/maven.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
-DsessionRootDirectory=${session.rootDirectory}
1+
-DsessionRootDirectory=${session.rootDirectory}
2+

api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,10 @@ public final class Constants {
545545
* <li>"release" - query only release repositories to discover versions</li>
546546
* <li>"snapshot" - query only snapshot repositories to discover versions</li>
547547
* </ul>
548-
* Default (when unset) is existing Maven behaviour: "release_or_snapshots".
548+
* Default (when unset) is using request carried nature. Hence, this configuration really makes sense with value
549+
* {@code "auto"}, while ideally callers needs update and use newly added method on version range request to
550+
* express preference.
551+
*
549552
* @since 4.0.0
550553
*/
551554
@Config(defaultValue = "release_or_snapshot")

api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionRangeResolverRequest.java

Lines changed: 142 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,83 +32,210 @@
3232
import static java.util.Objects.requireNonNull;
3333

3434
/**
35+
* A request to resolve a version range to a list of matching versions.
36+
* This request is used by {@link VersionRangeResolver} to expand version ranges
37+
* (e.g., "[3.8,4.0)") into concrete versions available in the configured repositories.
3538
*
3639
* @since 4.0.0
3740
*/
3841
@Experimental
3942
public interface VersionRangeResolverRequest extends RepositoryAwareRequest {
4043

44+
/**
45+
* Specifies which type of repositories to query when resolving version ranges.
46+
* This controls whether to search in release repositories, snapshot repositories, or both.
47+
*
48+
* @since 4.0.0
49+
*/
50+
enum Nature {
51+
/**
52+
* Query only release repositories to discover versions.
53+
*/
54+
RELEASE,
55+
/**
56+
* Query only snapshot repositories to discover versions.
57+
*/
58+
SNAPSHOT,
59+
/**
60+
* Query both release and snapshot repositories to discover versions.
61+
* This is the default behavior.
62+
*/
63+
RELEASE_OR_SNAPSHOT
64+
}
65+
66+
/**
67+
* Gets the artifact coordinates whose version range should be resolved.
68+
* The coordinates may contain a version range (e.g., "[1.0,2.0)") or a single version.
69+
*
70+
* @return the artifact coordinates, never {@code null}
71+
*/
4172
@Nonnull
4273
ArtifactCoordinates getArtifactCoordinates();
4374

75+
/**
76+
* Gets the nature of repositories to query when resolving the version range.
77+
* This determines whether to search in release repositories, snapshot repositories, or both.
78+
*
79+
* @return the repository nature, never {@code null}
80+
*/
81+
@Nonnull
82+
Nature getNature();
83+
84+
/**
85+
* Creates a version range resolver request using the session's repositories.
86+
*
87+
* @param session the session to use, must not be {@code null}
88+
* @param artifactCoordinates the artifact coordinates whose version range should be resolved, must not be {@code null}
89+
* @return the version range resolver request, never {@code null}
90+
*/
4491
@Nonnull
4592
static VersionRangeResolverRequest build(
4693
@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
47-
return build(session, artifactCoordinates, null);
94+
return build(session, artifactCoordinates, null, null);
4895
}
4996

97+
/**
98+
* Creates a version range resolver request.
99+
*
100+
* @param session the session to use, must not be {@code null}
101+
* @param artifactCoordinates the artifact coordinates whose version range should be resolved, must not be {@code null}
102+
* @param repositories the repositories to use, or {@code null} to use the session's repositories
103+
* @return the version range resolver request, never {@code null}
104+
*/
50105
@Nonnull
51106
static VersionRangeResolverRequest build(
52107
@Nonnull Session session,
53108
@Nonnull ArtifactCoordinates artifactCoordinates,
54109
@Nullable List<RemoteRepository> repositories) {
110+
return build(session, artifactCoordinates, repositories, null);
111+
}
112+
113+
/**
114+
* Creates a version range resolver request.
115+
*
116+
* @param session the session to use, must not be {@code null}
117+
* @param artifactCoordinates the artifact coordinates whose version range should be resolved, must not be {@code null}
118+
* @param repositories the repositories to use, or {@code null} to use the session's repositories
119+
* @param nature the nature of repositories to query when resolving the version range, or {@code null} to use the default
120+
* @return the version range resolver request, never {@code null}
121+
*/
122+
@Nonnull
123+
static VersionRangeResolverRequest build(
124+
@Nonnull Session session,
125+
@Nonnull ArtifactCoordinates artifactCoordinates,
126+
@Nullable List<RemoteRepository> repositories,
127+
@Nullable Nature nature) {
55128
return builder()
56129
.session(requireNonNull(session, "session cannot be null"))
57130
.artifactCoordinates(requireNonNull(artifactCoordinates, "artifactCoordinates cannot be null"))
58131
.repositories(repositories)
132+
.nature(nature)
59133
.build();
60134
}
61135

136+
/**
137+
* Creates a new builder for version range resolver requests.
138+
*
139+
* @return a new builder, never {@code null}
140+
*/
62141
@Nonnull
63142
static VersionResolverRequestBuilder builder() {
64143
return new VersionResolverRequestBuilder();
65144
}
66145

146+
/**
147+
* Builder for {@link VersionRangeResolverRequest}.
148+
*/
67149
@NotThreadSafe
68150
class VersionResolverRequestBuilder {
69151
Session session;
70152
RequestTrace trace;
71153
ArtifactCoordinates artifactCoordinates;
72154
List<RemoteRepository> repositories;
155+
Nature nature = Nature.RELEASE_OR_SNAPSHOT;
73156

157+
/**
158+
* Sets the session to use for the request.
159+
*
160+
* @param session the session, must not be {@code null}
161+
* @return this builder, never {@code null}
162+
*/
74163
public VersionResolverRequestBuilder session(Session session) {
75164
this.session = session;
76165
return this;
77166
}
78167

168+
/**
169+
* Sets the request trace for debugging and diagnostics.
170+
*
171+
* @param trace the request trace, may be {@code null}
172+
* @return this builder, never {@code null}
173+
*/
79174
public VersionResolverRequestBuilder trace(RequestTrace trace) {
80175
this.trace = trace;
81176
return this;
82177
}
83178

179+
/**
180+
* Sets the artifact coordinates whose version range should be resolved.
181+
*
182+
* @param artifactCoordinates the artifact coordinates, must not be {@code null}
183+
* @return this builder, never {@code null}
184+
*/
84185
public VersionResolverRequestBuilder artifactCoordinates(ArtifactCoordinates artifactCoordinates) {
85186
this.artifactCoordinates = artifactCoordinates;
86187
return this;
87188
}
88189

190+
/**
191+
* Sets the nature of repositories to query when resolving the version range.
192+
* If {@code null} is provided, defaults to {@link Nature#RELEASE_OR_SNAPSHOT}.
193+
*
194+
* @param nature the repository nature, or {@code null} to use the default
195+
* @return this builder, never {@code null}
196+
*/
197+
public VersionResolverRequestBuilder nature(Nature nature) {
198+
this.nature = Objects.requireNonNullElse(nature, Nature.RELEASE_OR_SNAPSHOT);
199+
return this;
200+
}
201+
202+
/**
203+
* Sets the repositories to use for resolving the version range.
204+
*
205+
* @param repositories the repositories, or {@code null} to use the session's repositories
206+
* @return this builder, never {@code null}
207+
*/
89208
public VersionResolverRequestBuilder repositories(List<RemoteRepository> repositories) {
90209
this.repositories = repositories;
91210
return this;
92211
}
93212

213+
/**
214+
* Builds the version range resolver request.
215+
*
216+
* @return the version range resolver request, never {@code null}
217+
*/
94218
public VersionRangeResolverRequest build() {
95-
return new DefaultVersionResolverRequest(session, trace, artifactCoordinates, repositories);
219+
return new DefaultVersionResolverRequest(session, trace, artifactCoordinates, repositories, nature);
96220
}
97221

98222
private static class DefaultVersionResolverRequest extends BaseRequest<Session>
99223
implements VersionRangeResolverRequest {
100224
private final ArtifactCoordinates artifactCoordinates;
101225
private final List<RemoteRepository> repositories;
226+
private final Nature nature;
102227

103228
@SuppressWarnings("checkstyle:ParameterNumber")
104229
DefaultVersionResolverRequest(
105230
@Nonnull Session session,
106231
@Nullable RequestTrace trace,
107232
@Nonnull ArtifactCoordinates artifactCoordinates,
108-
@Nullable List<RemoteRepository> repositories) {
233+
@Nullable List<RemoteRepository> repositories,
234+
@Nonnull Nature nature) {
109235
super(session, trace);
110-
this.artifactCoordinates = artifactCoordinates;
236+
this.artifactCoordinates = requireNonNull(artifactCoordinates);
111237
this.repositories = validate(repositories);
238+
this.nature = requireNonNull(nature);
112239
}
113240

114241
@Nonnull
@@ -123,23 +250,31 @@ public List<RemoteRepository> getRepositories() {
123250
return repositories;
124251
}
125252

253+
@Nonnull
254+
@Override
255+
public Nature getNature() {
256+
return nature;
257+
}
258+
126259
@Override
127260
public boolean equals(Object o) {
128261
return o instanceof DefaultVersionResolverRequest that
129262
&& Objects.equals(artifactCoordinates, that.artifactCoordinates)
130-
&& Objects.equals(repositories, that.repositories);
263+
&& Objects.equals(repositories, that.repositories)
264+
&& nature == that.nature;
131265
}
132266

133267
@Override
134268
public int hashCode() {
135-
return Objects.hash(artifactCoordinates, repositories);
269+
return Objects.hash(artifactCoordinates, repositories, nature);
136270
}
137271

138272
@Override
139273
public String toString() {
140274
return "VersionResolverRequest[" + "artifactCoordinates="
141275
+ artifactCoordinates + ", repositories="
142-
+ repositories + ']';
276+
+ repositories + ", nature="
277+
+ nature + ']';
143278
}
144279
}
145280
}

compat/maven-compat/pom.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ under the License.
115115
<groupId>org.apache.maven.resolver</groupId>
116116
<artifactId>maven-resolver-util</artifactId>
117117
</dependency>
118+
<dependency>
119+
<groupId>org.apache.maven.resolver</groupId>
120+
<artifactId>maven-resolver-impl</artifactId>
121+
</dependency>
118122

119123
<dependency>
120124
<groupId>org.codehaus.plexus</groupId>
@@ -212,11 +216,6 @@ under the License.
212216
<artifactId>maven-resolver-spi</artifactId>
213217
<scope>test</scope>
214218
</dependency>
215-
<dependency>
216-
<groupId>org.apache.maven.resolver</groupId>
217-
<artifactId>maven-resolver-impl</artifactId>
218-
<scope>test</scope>
219-
</dependency>
220219
<dependency>
221220
<groupId>org.apache.maven.resolver</groupId>
222221
<artifactId>maven-resolver-connector-basic</artifactId>

0 commit comments

Comments
 (0)