[MNG-8235] Move remote repositories into requests (#1712)

This commit is contained in:
Guillaume Nodet 2024-09-12 08:19:14 +02:00 committed by GitHub
parent 85f5dca4a6
commit 2b13a43c09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 457 additions and 92 deletions

View File

@ -38,7 +38,6 @@ import org.apache.maven.api.settings.Settings;
/**
* The session to install / deploy / resolve artifacts and dependencies.
*
* TODO: move the remote repositories in the requests (plugins will need to access this list somehow)
* TODO: add request trace so that requests can be linked together and through the resolver
* TODO: add a Request interface holding session + parent request
*
@ -425,6 +424,19 @@ public interface Session {
@Nonnull
DownloadedArtifact resolveArtifact(@Nonnull ArtifactCoordinates coordinates);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
* @param coordinates coordinates of the artifact to resolve
* @param repositories repositories to use, if {@code null}, the session repositories are used
* @return requested artifact together with the path to its file
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*/
@Nonnull
DownloadedArtifact resolveArtifact(@Nonnull ArtifactCoordinates coordinates, List<RemoteRepository> repositories);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
@ -449,6 +461,21 @@ public interface Session {
@Nonnull
Collection<DownloadedArtifact> resolveArtifacts(@Nonnull Collection<? extends ArtifactCoordinates> coordinates);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
* @param coordinates coordinates of all artifacts to resolve
* @param repositories repositories to use, if {@code null}, the session repositories are used
* @return requested artifacts together with the paths to their files
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*/
@Nonnull
Collection<DownloadedArtifact> resolveArtifacts(
@Nonnull Collection<? extends ArtifactCoordinates> coordinates,
@Nullable List<RemoteRepository> repositories);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
@ -461,6 +488,19 @@ public interface Session {
@Nonnull
DownloadedArtifact resolveArtifact(@Nonnull Artifact artifact);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
* @param artifact the artifact to resolve
* @param repositories repositories to use, if {@code null}, the session repositories are used
* @return requested artifact together with the path to its file
* @throws org.apache.maven.api.services.ArtifactResolverException if the artifact resolution failed
*
* @see org.apache.maven.api.services.ArtifactResolver#resolve(Session, Collection)
*/
@Nonnull
DownloadedArtifact resolveArtifact(@Nonnull Artifact artifact, @Nullable List<RemoteRepository> repositories);
/**
* Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
*
@ -717,6 +757,23 @@ public interface Session {
@Nonnull
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact);
/**
* Expands a version range to a list of matching versions, in ascending order.
* For example, resolves "[3.8,4.0)" to "3.8", "3.8.1", "3.8.2".
* The returned list of versions is only dependent on the configured repositories and their contents.
* The supplied request may also refer to a single concrete version rather than a version range.
* In this case though, the result contains simply the (parsed) input version, regardless of the
* repositories and their contents.
*
* @param artifact the artifact for which to resolve the versions
* @param repositories the repositories to use, or the session repositories if {@code null}
* @return a list of resolved {@code Version}s.
* @throws org.apache.maven.api.services.VersionRangeResolverException if the resolution failed
* @see org.apache.maven.api.services.VersionRangeResolver#resolve(Session, ArtifactCoordinates) (String)
*/
@Nonnull
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact, List<RemoteRepository> repositories);
/**
* Parses the specified version string, for example "1.0".
* <p>

View File

@ -19,8 +19,10 @@
package org.apache.maven.api.services;
import java.util.Collection;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
@ -55,4 +57,22 @@ public interface ArtifactResolver extends Service {
default ArtifactResolverResult resolve(Session session, Collection<? extends ArtifactCoordinates> coordinates) {
return resolve(ArtifactResolverRequest.build(session, coordinates));
}
/**
* Resolves several artifacts from their coordinates.
*
* @param session {@link Session}
* @param repositories the list of remote repositories or {@code null} to use the session repositories
* @param coordinates array of {@link ArtifactCoordinates}
* @return {@link ArtifactResolverResult}
* @throws ArtifactResolverException in case of an error.
* @throws IllegalArgumentException in case of parameter {@code buildingRequest} is {@code null} or
* parameter {@code coordinates} is {@code null} or invalid
*/
default ArtifactResolverResult resolve(
Session session,
Collection<? extends ArtifactCoordinates> coordinates,
List<RemoteRepository> repositories) {
return resolve(ArtifactResolverRequest.build(session, coordinates, repositories));
}
}

View File

@ -19,13 +19,16 @@
package org.apache.maven.api.services;
import java.util.Collection;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import static org.apache.maven.api.services.BaseRequest.nonNull;
@ -43,6 +46,9 @@ public interface ArtifactResolverRequest {
@Nonnull
Collection<? extends ArtifactCoordinates> getCoordinates();
@Nonnull
List<RemoteRepository> getRepositories();
@Nonnull
static ArtifactResolverRequestBuilder builder() {
return new ArtifactResolverRequestBuilder();
@ -57,10 +63,23 @@ public interface ArtifactResolverRequest {
.build();
}
@Nonnull
static ArtifactResolverRequest build(
@Nonnull Session session,
@Nonnull Collection<? extends ArtifactCoordinates> coordinates,
List<RemoteRepository> repositories) {
return builder()
.session(nonNull(session, "session cannot be null"))
.coordinates(nonNull(coordinates, "coordinates cannot be null"))
.repositories(repositories)
.build();
}
@NotThreadSafe
class ArtifactResolverRequestBuilder {
Session session;
Collection<? extends ArtifactCoordinates> coordinates;
List<RemoteRepository> repositories;
ArtifactResolverRequestBuilder() {}
@ -76,19 +95,31 @@ public interface ArtifactResolverRequest {
return this;
}
@Nonnull
public ArtifactResolverRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
@Nonnull
public ArtifactResolverRequest build() {
return new DefaultArtifactResolverRequest(session, coordinates);
return new DefaultArtifactResolverRequest(session, coordinates, repositories);
}
private static class DefaultArtifactResolverRequest extends BaseRequest implements ArtifactResolverRequest {
@Nonnull
private final Collection<? extends ArtifactCoordinates> coordinates;
@Nullable
private final List<RemoteRepository> repositories;
DefaultArtifactResolverRequest(
@Nonnull Session session, @Nonnull Collection<? extends ArtifactCoordinates> coordinates) {
@Nonnull Session session,
@Nonnull Collection<? extends ArtifactCoordinates> coordinates,
@Nonnull List<RemoteRepository> repositories) {
super(session);
this.coordinates = unmodifiable(nonNull(coordinates, "coordinates cannot be null"));
this.repositories = repositories;
}
@Nonnull
@ -96,6 +127,12 @@ public interface ArtifactResolverRequest {
public Collection<? extends ArtifactCoordinates> getCoordinates() {
return coordinates;
}
@Nullable
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}

View File

@ -31,6 +31,7 @@ import org.apache.maven.api.JavaPathType;
import org.apache.maven.api.PathScope;
import org.apache.maven.api.PathType;
import org.apache.maven.api.Project;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
@ -94,6 +95,9 @@ public interface DependencyResolverRequest {
@Nullable
Predicate<PathType> getPathTypeFilter();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull
static DependencyResolverRequestBuilder builder() {
return new DependencyResolverRequestBuilder();
@ -170,6 +174,7 @@ public interface DependencyResolverRequest {
boolean verbose;
PathScope pathScope;
Predicate<PathType> pathTypeFilter;
List<RemoteRepository> repositories;
DependencyResolverRequestBuilder() {}
@ -327,6 +332,12 @@ public interface DependencyResolverRequest {
return pathTypeFilter(desiredTypes::contains);
}
@Nonnull
public DependencyResolverRequestBuilder repositories(@Nonnull List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
@Nonnull
public DependencyResolverRequest build() {
return new DefaultDependencyResolverRequest(
@ -339,7 +350,8 @@ public interface DependencyResolverRequest {
managedDependencies,
verbose,
pathScope,
pathTypeFilter);
pathTypeFilter,
repositories);
}
static class DefaultDependencyResolverRequest extends BaseRequest implements DependencyResolverRequest {
@ -352,6 +364,7 @@ public interface DependencyResolverRequest {
private final boolean verbose;
private final PathScope pathScope;
private final Predicate<PathType> pathTypeFilter;
private final List<RemoteRepository> repositories;
/**
* Creates a request with the specified properties.
@ -371,7 +384,8 @@ public interface DependencyResolverRequest {
@Nonnull Collection<DependencyCoordinates> managedDependencies,
boolean verbose,
@Nullable PathScope pathScope,
@Nullable Predicate<PathType> pathTypeFilter) {
@Nullable Predicate<PathType> pathTypeFilter,
@Nullable List<RemoteRepository> repositories) {
super(session);
this.requestType = nonNull(requestType, "requestType cannot be null");
this.project = project;
@ -383,6 +397,7 @@ public interface DependencyResolverRequest {
this.verbose = verbose;
this.pathScope = pathScope;
this.pathTypeFilter = (pathTypeFilter != null) ? pathTypeFilter : (t) -> true;
this.repositories = repositories;
if (verbose && requestType != RequestType.COLLECT) {
throw new IllegalArgumentException("verbose cannot only be true when collecting dependencies");
}
@ -439,6 +454,11 @@ public interface DependencyResolverRequest {
return pathTypeFilter;
}
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
@Nonnull
@Override
public String toString() {

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
@ -157,6 +158,9 @@ public interface ModelBuilderRequest {
@Nullable
ModelTransformerContextBuilder getTransformerContextBuilder();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull
static ModelBuilderRequest build(@Nonnull ModelBuilderRequest request, @Nonnull ModelSource source) {
return builder(nonNull(request, "request cannot be null"))
@ -210,6 +214,7 @@ public interface ModelBuilderRequest {
Object listener;
ModelBuilderResult interimResult;
ModelTransformerContextBuilder transformerContextBuilder;
List<RemoteRepository> repositories;
ModelBuilderRequestBuilder() {}
@ -232,6 +237,7 @@ public interface ModelBuilderRequest {
this.listener = request.getListener();
this.interimResult = request.getInterimResult();
this.transformerContextBuilder = request.getTransformerContextBuilder();
this.repositories = request.getRepositories();
}
public ModelBuilderRequestBuilder session(Session session) {
@ -325,6 +331,11 @@ public interface ModelBuilderRequest {
return this;
}
public ModelBuilderRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
public ModelBuilderRequest build() {
return new DefaultModelBuilderRequest(
session,
@ -344,7 +355,8 @@ public interface ModelBuilderRequest {
modelCache,
listener,
interimResult,
transformerContextBuilder);
transformerContextBuilder,
repositories);
}
private static class DefaultModelBuilderRequest extends BaseRequest implements ModelBuilderRequest {
@ -365,6 +377,7 @@ public interface ModelBuilderRequest {
private final Object listener;
private final ModelBuilderResult interimResult;
private final ModelTransformerContextBuilder transformerContextBuilder;
private final List<RemoteRepository> repositories;
@SuppressWarnings("checkstyle:ParameterNumber")
DefaultModelBuilderRequest(
@ -385,7 +398,8 @@ public interface ModelBuilderRequest {
ModelCache modelCache,
Object listener,
ModelBuilderResult interimResult,
ModelTransformerContextBuilder transformerContextBuilder) {
ModelTransformerContextBuilder transformerContextBuilder,
List<RemoteRepository> repositories) {
super(session);
this.validationLevel = validationLevel;
this.locationTracking = locationTracking;
@ -405,6 +419,7 @@ public interface ModelBuilderRequest {
this.listener = listener;
this.interimResult = interimResult;
this.transformerContextBuilder = transformerContextBuilder;
this.repositories = repositories != null ? List.copyOf(repositories) : null;
}
@Override
@ -489,6 +504,11 @@ public interface ModelBuilderRequest {
public ModelTransformerContextBuilder getTransformerContextBuilder() {
return transformerContextBuilder;
}
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}

View File

@ -119,7 +119,7 @@ public interface ModelBuilderResult {
List<ModelProblem> getProblems();
/**
* Creates a human readable representation of these errors.
* Creates a human-readable representation of these errors.
*/
String toString();
}

View File

@ -18,12 +18,15 @@
*/
package org.apache.maven.api.services;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.Parent;
@ -36,6 +39,7 @@ public interface ModelResolver extends Service {
* Tries to resolve the POM for the specified parent coordinates possibly updating {@code parent}.
*
* @param session The session to use to resolve the model, must not be {@code null}.
* @param repositories The repositories to use to resolve the model, may be {@code null} in which case the {@code Session} repositories will be used.
* @param parent The parent coordinates to resolve, must not be {@code null}.
* @param modified a holder for the updated parent, must not be {@code null}.
* @return The source of the requested POM, never {@code null}.
@ -43,10 +47,14 @@ public interface ModelResolver extends Service {
*/
@Nonnull
default ModelSource resolveModel(
@Nonnull Session session, @Nonnull Parent parent, @Nonnull AtomicReference<Parent> modified)
@Nonnull Session session,
@Nullable List<RemoteRepository> repositories,
@Nonnull Parent parent,
@Nonnull AtomicReference<Parent> modified)
throws ModelResolverException {
return resolveModel(
session,
repositories,
parent.getGroupId(),
parent.getArtifactId(),
parent.getVersion(),
@ -57,6 +65,7 @@ public interface ModelResolver extends Service {
* Tries to resolve the POM for the specified dependency coordinates possibly updating {@code dependency}.
*
* @param session The session to use to resolve the model, must not be {@code null}.
* @param repositories The repositories to use to resolve the model, may be {@code null} in which case the {@code Session} repositories will be used.
* @param dependency The dependency coordinates to resolve, must not be {@code null}.
* @param modified a holder for the updated dependency, must not be {@code null}.
* @return The source of the requested POM, never {@code null}.
@ -64,10 +73,14 @@ public interface ModelResolver extends Service {
*/
@Nonnull
default ModelSource resolveModel(
@Nonnull Session session, @Nonnull Dependency dependency, @Nonnull AtomicReference<Dependency> modified)
@Nonnull Session session,
@Nullable List<RemoteRepository> repositories,
@Nonnull Dependency dependency,
@Nonnull AtomicReference<Dependency> modified)
throws ModelResolverException {
return resolveModel(
session,
repositories,
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
@ -77,6 +90,7 @@ public interface ModelResolver extends Service {
@Nonnull
ModelSource resolveModel(
@Nonnull Session session,
@Nullable List<RemoteRepository> repositories,
@Nonnull String groupId,
@Nonnull String artifactId,
@Nonnull String version,

View File

@ -19,8 +19,10 @@
package org.apache.maven.api.services;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
@ -57,6 +59,9 @@ public interface ProjectBuilderRequest {
boolean isProcessPlugins();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull
static ProjectBuilderRequest build(@Nonnull Session session, @Nonnull Source source) {
return builder()
@ -86,6 +91,7 @@ public interface ProjectBuilderRequest {
boolean allowStubModel;
boolean recursive;
boolean processPlugins = true;
List<RemoteRepository> repositories;
ProjectBuilderRequestBuilder() {}
@ -109,8 +115,14 @@ public interface ProjectBuilderRequest {
return this;
}
public ProjectBuilderRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
public ProjectBuilderRequest build() {
return new DefaultProjectBuilderRequest(session, path, source, allowStubModel, recursive, processPlugins);
return new DefaultProjectBuilderRequest(
session, path, source, allowStubModel, recursive, processPlugins, repositories);
}
private static class DefaultProjectBuilderRequest extends BaseRequest implements ProjectBuilderRequest {
@ -119,6 +131,7 @@ public interface ProjectBuilderRequest {
private final boolean allowStubModel;
private final boolean recursive;
private final boolean processPlugins;
private final List<RemoteRepository> repositories;
@SuppressWarnings("checkstyle:ParameterNumber")
DefaultProjectBuilderRequest(
@ -127,13 +140,15 @@ public interface ProjectBuilderRequest {
@Nullable Source source,
boolean allowStubModel,
boolean recursive,
boolean processPlugins) {
boolean processPlugins,
@Nullable List<RemoteRepository> repositories) {
super(session);
this.path = path;
this.source = source;
this.allowStubModel = allowStubModel;
this.recursive = recursive;
this.processPlugins = processPlugins;
this.repositories = repositories;
}
@Nonnull
@ -162,6 +177,11 @@ public interface ProjectBuilderRequest {
public boolean isProcessPlugins() {
return processPlugins;
}
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}

View File

@ -18,12 +18,16 @@
*/
package org.apache.maven.api.services;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
/**
* Parses and evaluates version ranges encountered in dependency declarations.
@ -54,6 +58,29 @@ public interface VersionRangeResolver extends Service {
return resolve(VersionRangeResolverRequest.build(session, artifactCoordinates));
}
/**
* Expands a version range to a list of matching versions, in ascending order.
* For example, resolves "[3.8,4.0)" to "3.8", "3.8.1", "3.8.2".
* The returned list of versions is only dependent on the configured repositories and their contents.
* The supplied request may also refer to a single concrete version rather than a version range.
* In this case though, the result contains simply the (parsed) input version, regardless of the
* repositories and their contents.
*
* @param session the session to use
* @param artifactCoordinates t
* @param repositories the repositories to use (if {@code null}, the session repositories are used)
* @return the version range resolution result
* @throws VersionResolverException if an errors occurs
*/
@Nonnull
default VersionRangeResolverResult resolve(
@Nonnull Session session,
@Nonnull ArtifactCoordinates artifactCoordinates,
@Nullable List<RemoteRepository> repositories)
throws VersionResolverException {
return resolve(VersionRangeResolverRequest.build(session, artifactCoordinates, repositories));
}
@Nonnull
VersionRangeResolverResult resolve(@Nonnull VersionRangeResolverRequest request)
throws VersionRangeResolverException;

View File

@ -18,11 +18,15 @@
*/
package org.apache.maven.api.services;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import static org.apache.maven.api.services.BaseRequest.nonNull;
@ -39,12 +43,24 @@ public interface VersionRangeResolverRequest {
@Nonnull
ArtifactCoordinates getArtifactCoordinates();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull
static VersionRangeResolverRequest build(
@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
return build(session, artifactCoordinates, null);
}
@Nonnull
static VersionRangeResolverRequest build(
@Nonnull Session session,
@Nonnull ArtifactCoordinates artifactCoordinates,
@Nullable List<RemoteRepository> repositories) {
return builder()
.session(nonNull(session, "session cannot be null"))
.artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null"))
.repositories(repositories)
.build();
}
@ -57,6 +73,7 @@ public interface VersionRangeResolverRequest {
class VersionResolverRequestBuilder {
Session session;
ArtifactCoordinates artifactCoordinates;
List<RemoteRepository> repositories;
public VersionResolverRequestBuilder session(Session session) {
this.session = session;
@ -68,17 +85,27 @@ public interface VersionRangeResolverRequest {
return this;
}
public VersionResolverRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
public VersionRangeResolverRequest build() {
return new DefaultVersionResolverRequest(session, artifactCoordinates);
return new DefaultVersionResolverRequest(session, artifactCoordinates, repositories);
}
private static class DefaultVersionResolverRequest extends BaseRequest implements VersionRangeResolverRequest {
private final ArtifactCoordinates artifactCoordinates;
private final List<RemoteRepository> repositories;
@SuppressWarnings("checkstyle:ParameterNumber")
DefaultVersionResolverRequest(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
DefaultVersionResolverRequest(
@Nonnull Session session,
@Nonnull ArtifactCoordinates artifactCoordinates,
@Nullable List<RemoteRepository> repositories) {
super(session);
this.artifactCoordinates = artifactCoordinates;
this.repositories = repositories;
}
@Nonnull
@ -86,6 +113,12 @@ public interface VersionRangeResolverRequest {
public ArtifactCoordinates getArtifactCoordinates() {
return artifactCoordinates;
}
@Nullable
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}

View File

@ -18,11 +18,15 @@
*/
package org.apache.maven.api.services;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import static org.apache.maven.api.services.BaseRequest.nonNull;
@ -39,6 +43,9 @@ public interface VersionResolverRequest {
@Nonnull
ArtifactCoordinates getArtifactCoordinates();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull
static VersionResolverRequest build(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
return builder()
@ -47,6 +54,18 @@ public interface VersionResolverRequest {
.build();
}
@Nonnull
static VersionResolverRequest build(
@Nonnull Session session,
@Nonnull ArtifactCoordinates artifactCoordinates,
@Nullable List<RemoteRepository> repositories) {
return builder()
.session(nonNull(session, "session cannot be null"))
.artifactCoordinates(nonNull(artifactCoordinates, "artifactCoordinates cannot be null"))
.repositories(repositories)
.build();
}
@Nonnull
static VersionResolverRequestBuilder builder() {
return new VersionResolverRequestBuilder();
@ -56,6 +75,7 @@ public interface VersionResolverRequest {
class VersionResolverRequestBuilder {
Session session;
ArtifactCoordinates artifactCoordinates;
List<RemoteRepository> repositories;
public VersionResolverRequestBuilder session(Session session) {
this.session = session;
@ -67,17 +87,27 @@ public interface VersionResolverRequest {
return this;
}
public VersionResolverRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
public VersionResolverRequest build() {
return new DefaultVersionResolverRequest(session, artifactCoordinates);
return new DefaultVersionResolverRequest(session, artifactCoordinates, repositories);
}
private static class DefaultVersionResolverRequest extends BaseRequest implements VersionResolverRequest {
private final ArtifactCoordinates artifactCoordinates;
private final List<RemoteRepository> repositories;
@SuppressWarnings("checkstyle:ParameterNumber")
DefaultVersionResolverRequest(@Nonnull Session session, @Nonnull ArtifactCoordinates artifactCoordinates) {
DefaultVersionResolverRequest(
@Nonnull Session session,
@Nonnull ArtifactCoordinates artifactCoordinates,
@Nullable List<RemoteRepository> repositories) {
super(session);
this.artifactCoordinates = artifactCoordinates;
this.repositories = repositories;
}
@Nonnull
@ -85,6 +115,12 @@ public interface VersionResolverRequest {
public ArtifactCoordinates getArtifactCoordinates() {
return artifactCoordinates;
}
@Nullable
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}

View File

@ -547,6 +547,21 @@ public abstract class AbstractSession implements InternalSession {
.next();
}
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
*
* @throws ArtifactResolverException if the artifact resolution failed
* @see ArtifactResolver#resolve(Session, Collection)
*/
@Override
public DownloadedArtifact resolveArtifact(ArtifactCoordinates coordinates, List<RemoteRepository> repositories) {
return getService(ArtifactResolver.class)
.resolve(this, Collections.singletonList(coordinates), repositories)
.getArtifacts()
.iterator()
.next();
}
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
*
@ -569,6 +584,20 @@ public abstract class AbstractSession implements InternalSession {
return getService(ArtifactResolver.class).resolve(this, coordinates).getArtifacts();
}
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
*
* @throws ArtifactResolverException if the artifact resolution failed
* @see ArtifactResolver#resolve(Session, Collection)
*/
@Override
public Collection<DownloadedArtifact> resolveArtifacts(
Collection<? extends ArtifactCoordinates> coordinates, List<RemoteRepository> repositories) {
return getService(ArtifactResolver.class)
.resolve(this, coordinates, repositories)
.getArtifacts();
}
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
*
@ -582,6 +611,19 @@ public abstract class AbstractSession implements InternalSession {
return resolveArtifact(coordinates);
}
/**
* Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
*
* @throws ArtifactResolverException if the artifact resolution failed
* @see ArtifactResolver#resolve(Session, Collection)
*/
@Override
public DownloadedArtifact resolveArtifact(Artifact artifact, List<RemoteRepository> repositories) {
ArtifactCoordinates coordinates =
getService(ArtifactCoordinatesFactory.class).create(this, artifact);
return resolveArtifact(coordinates, repositories);
}
@Override
public Collection<DownloadedArtifact> resolveArtifacts(Artifact... artifacts) {
ArtifactCoordinatesFactory acf = getService(ArtifactCoordinatesFactory.class);
@ -803,6 +845,13 @@ public abstract class AbstractSession implements InternalSession {
return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions();
}
@Override
public List<Version> resolveVersionRange(ArtifactCoordinates artifact, List<RemoteRepository> repositories) {
return getService(VersionRangeResolver.class)
.resolve(this, artifact, repositories)
.getVersions();
}
@Override
public Type requireType(String id) {
return getService(TypeRegistry.class).require(id);

View File

@ -54,7 +54,8 @@ public class DefaultArtifactResolver implements ArtifactResolver {
try {
Map<DownloadedArtifact, Path> paths = new HashMap<>();
ArtifactManager artifactManager = session.getService(ArtifactManager.class);
List<RemoteRepository> repositories = session.toRepositories(session.getRemoteRepositories());
List<RemoteRepository> repositories = session.toRepositories(
request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories());
List<ArtifactRequest> requests = new ArrayList<>();
for (ArtifactCoordinates coords : request.getCoordinates()) {
org.eclipse.aether.artifact.Artifact aetherArtifact = session.toArtifact(coords);

View File

@ -85,13 +85,16 @@ public class DefaultDependencyResolver implements DependencyResolver {
root = null;
dependencies = project.getDependencies();
managedDependencies = project.getManagedDependencies();
remoteRepositories = session.getService(ProjectManager.class).getRemoteProjectRepositories(project);
remoteRepositories = request.getRepositories() != null
? request.getRepositories()
: session.getService(ProjectManager.class).getRemoteProjectRepositories(project);
} else {
rootArtifact = request.getRootArtifact().orElse(null);
root = request.getRoot().orElse(null);
dependencies = request.getDependencies();
managedDependencies = request.getManagedDependencies();
remoteRepositories = session.getRemoteRepositories();
remoteRepositories =
request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories();
}
CollectRequest collectRequest = new CollectRequest()
.setRootArtifact(rootArtifact != null ? session.toArtifact(rootArtifact) : null)
@ -149,6 +152,8 @@ public class DefaultDependencyResolver implements DependencyResolver {
InternalSession.from(nonNull(request, "request").getSession());
DependencyResolverResult result;
DependencyResolverResult collectorResult = collect(request);
List<RemoteRepository> repositories =
request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories();
if (request.getRequestType() == DependencyResolverRequest.RequestType.COLLECT) {
result = collectorResult;
} else {
@ -171,7 +176,7 @@ public class DefaultDependencyResolver implements DependencyResolver {
DefaultDependencyResolverResult resolverResult = new DefaultDependencyResolverResult(
cache, collectorResult.getExceptions(), collectorResult.getRoot(), nodes.size());
ArtifactResolverResult artifactResolverResult =
session.getService(ArtifactResolver.class).resolve(session, coordinates);
session.getService(ArtifactResolver.class).resolve(session, coordinates, repositories);
for (Node node : nodes) {
Dependency d = node.getDependency();
Path path = (d != null) ? artifactResolverResult.getPath(d) : null;

View File

@ -63,7 +63,10 @@ public class DefaultVersionRangeResolver implements VersionRangeResolver {
session.getSession(),
new VersionRangeRequest(
session.toArtifact(request.getArtifactCoordinates()),
session.toRepositories(session.getRemoteRepositories()),
session.toRepositories(
request.getRepositories() != null
? request.getRepositories()
: session.getRemoteRepositories()),
null));
Map<String, ArtifactRepository> repos = res.getVersions().stream()

View File

@ -58,7 +58,10 @@ public class DefaultVersionResolver implements VersionResolver {
session.getSession(),
new VersionRequest(
session.toArtifact(request.getArtifactCoordinates()),
session.toRepositories(session.getRemoteRepositories()),
session.toRepositories(
request.getRepositories() != null
? request.getRepositories()
: session.getRemoteRepositories()),
null));
return new VersionResolverResult() {

View File

@ -42,7 +42,6 @@ import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.Session;
import org.apache.maven.api.Type;
import org.apache.maven.api.VersionRange;
import org.apache.maven.api.annotations.Nullable;
@ -1180,9 +1179,8 @@ public class DefaultModelBuilder implements ModelBuilder {
ModelSource modelSource;
try {
AtomicReference<Parent> modified = new AtomicReference<>();
Session session = request.getSession()
.withRemoteRepositories(request.getModelRepositoryHolder().getRepositories());
modelSource = modelResolver.resolveModel(session, parent, modified);
modelSource = modelResolver.resolveModel(
request.getSession(), request.getModelRepositoryHolder().getRepositories(), parent, modified);
if (modified.get() != null) {
parent = modified.get();
}
@ -1422,10 +1420,11 @@ public class DefaultModelBuilder implements ModelBuilder {
if (importModel == null) {
final ModelSource importSource;
try {
Session session = request.getSession()
.withRemoteRepositories(
request.getModelRepositoryHolder().getRepositories());
importSource = modelResolver.resolveModel(session, dependency, new AtomicReference<>());
importSource = modelResolver.resolveModel(
request.getSession(),
request.getModelRepositoryHolder().getRepositories(),
dependency,
new AtomicReference<>());
} catch (ModelBuilderException e) {
StringBuilder buffer = new StringBuilder(256);
buffer.append("Non-resolvable import POM");
@ -1459,9 +1458,8 @@ public class DefaultModelBuilder implements ModelBuilder {
final ModelBuilderResult importResult;
try {
ModelBuilderRequest importRequest = ModelBuilderRequest.builder()
.session(request.getSession()
.withRemoteRepositories(
request.getModelRepositoryHolder().getRepositories()))
.session(request.getSession())
.repositories(request.getModelRepositoryHolder().getRepositories())
.validationLevel(ModelBuilderRequest.VALIDATION_LEVEL_MINIMAL)
.systemProperties(request.getSystemProperties())
.userProperties(request.getUserProperties())

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.maven.api.Session;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.di.Inject;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
@ -40,7 +40,6 @@ import org.apache.maven.api.services.ModelResolverException;
import org.apache.maven.api.services.ModelSource;
import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.internal.impl.model.ModelProblemUtils;
import org.codehaus.plexus.interpolation.util.StringUtils;
import org.eclipse.aether.RepositoryEvent;
import org.eclipse.aether.RepositoryEvent.EventType;
import org.eclipse.aether.RepositoryException;
@ -199,18 +198,16 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
try {
InternalSession iSession = InternalSession.from(session);
Session iSessionWithRepos = iSession.withRemoteRepositories(request.getRepositories().stream()
List<RemoteRepository> repositories = request.getRepositories().stream()
.map(iSession::getRemoteRepository)
.toList());
.toList();
String gav =
pomArtifact.getGroupId() + ":" + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion();
ModelResolver modelResolver = new DefaultModelResolver();
ModelRepositoryHolder modelRepositoryHolder = new DefaultModelRepositoryHolder(
iSessionWithRepos,
DefaultModelRepositoryHolder.RepositoryMerging.REQUEST_DOMINANT,
iSessionWithRepos.getRemoteRepositories());
iSession, DefaultModelRepositoryHolder.RepositoryMerging.REQUEST_DOMINANT, repositories);
ModelBuilderRequest modelRequest = ModelBuilderRequest.builder()
.session(iSessionWithRepos)
.session(iSession)
.projectBuild(false)
.processPlugins(false)
.twoPhaseBuilding(false)
@ -222,6 +219,7 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
.modelResolver(modelResolver)
.modelRepositoryHolder(modelRepositoryHolder)
.modelCache(DefaultModelCache.newInstance(session, false))
.repositories(repositories)
.build();
ModelBuilderResult modelResult = modelBuilder.build(modelRequest);
@ -230,21 +228,23 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
if (!modelResult.getProblems().isEmpty()) {
List<ModelProblem> problems = modelResult.getProblems();
if (logger.isDebugEnabled()) {
String problem = (problems.size() == 1) ? "problem" : "problems";
String problemPredicate = problem + ((problems.size() == 1) ? " was" : " were");
String message = String.format(
"%s %s encountered while building the effective model for %s during %s\n",
problems.size(),
problemPredicate,
request.getArtifact(),
RequestTraceHelper.interpretTrace(true, request.getTrace()));
message += StringUtils.capitalizeFirstLetter(problem);
StringBuilder sb = new StringBuilder();
sb.append(problems.size())
.append(" ")
.append((problems.size() == 1) ? "problem was" : "problems were")
.append(" encountered while building the effective model for ")
.append(request.getArtifact())
.append(" during ")
.append(RequestTraceHelper.interpretTrace(true, request.getTrace()))
.append("\n")
.append((problems.size() == 1) ? "Problem" : "Problems");
for (ModelProblem modelProblem : problems) {
message += String.format(
"\n* %s @ %s",
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null));
sb.append("\n* ")
.append(modelProblem.getMessage())
.append(" @ ")
.append(ModelProblemUtils.formatLocation(modelProblem, null));
}
logger.warn(message);
logger.warn(sb.toString());
} else {
logger.warn(
"{} {} encountered while building the effective model for {} during {} (use -X to see details)",

View File

@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.DownloadedArtifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.Version;
import org.apache.maven.api.di.Named;
@ -50,7 +51,12 @@ public class DefaultModelResolver implements ModelResolver {
@Override
public ModelSource resolveModel(
Session session, String groupId, String artifactId, String version, Consumer<String> resolvedVersion)
Session session,
List<RemoteRepository> repositories,
String groupId,
String artifactId,
String version,
Consumer<String> resolvedVersion)
throws ModelResolverException {
try {
ArtifactCoordinates coords = session.createArtifactCoordinates(groupId, artifactId, version, "pom");
@ -63,7 +69,7 @@ public class DefaultModelResolver implements ModelResolver {
artifactId,
version);
}
List<Version> versions = session.resolveVersionRange(coords);
List<Version> versions = session.resolveVersionRange(coords, repositories);
if (versions.isEmpty()) {
throw new ModelResolverException(
String.format("No versions matched the requested version range '%s'", version),
@ -76,8 +82,8 @@ public class DefaultModelResolver implements ModelResolver {
resolvedVersion.accept(newVersion);
}
DownloadedArtifact resolved =
session.resolveArtifact(session.createArtifactCoordinates(groupId, artifactId, newVersion, "pom"));
DownloadedArtifact resolved = session.resolveArtifact(
session.createArtifactCoordinates(groupId, artifactId, newVersion, "pom"), repositories);
Path path = resolved.getPath();
String location = groupId + ":" + artifactId + ":" + newVersion;
return new ModelSource() {
@ -109,9 +115,8 @@ public class DefaultModelResolver implements ModelResolver {
} catch (VersionRangeResolverException | ArtifactResolverException e) {
throw new ModelResolverException(
e.getMessage() + " (remote repositories: "
+ session.getRemoteRepositories().stream()
.map(Object::toString)
.collect(Collectors.joining(", "))
+ (repositories != null ? repositories : session.getRemoteRepositories())
.stream().map(Object::toString).collect(Collectors.joining(", "))
+ ")",
groupId,
artifactId,

View File

@ -69,7 +69,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, parent, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertNotNull(e.getMessage());
assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central"));
@ -85,7 +85,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, parent, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertEquals("No versions matched the requested version range '[2.0,2.1)'", e.getMessage());
}
@ -100,7 +100,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, parent, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertEquals("The requested version range '[1,)' does not specify an upper bound", e.getMessage());
}
@ -113,7 +113,7 @@ class DefaultModelResolverTest {
.version("1")
.build();
assertNotNull(this.newModelResolver().resolveModel(session, parent, new AtomicReference<>()));
assertNotNull(this.newModelResolver().resolveModel(session, null, parent, new AtomicReference<>()));
assertEquals("1", parent.getVersion());
}
@ -126,7 +126,7 @@ class DefaultModelResolverTest {
.build();
AtomicReference<org.apache.maven.api.model.Parent> modified = new AtomicReference<>();
assertNotNull(this.newModelResolver().resolveModel(session, parent, modified));
assertNotNull(this.newModelResolver().resolveModel(session, null, parent, modified));
assertEquals("1", modified.get().getVersion());
}
@ -140,7 +140,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, dependency, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertNotNull(e.getMessage());
assertThat(e.getMessage(), containsString("Could not find artifact org.apache:apache:pom:0 in central"));
@ -156,7 +156,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, dependency, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertEquals("No versions matched the requested version range '[2.0,2.1)'", e.getMessage());
}
@ -171,7 +171,7 @@ class DefaultModelResolverTest {
ModelResolverException e = assertThrows(
ModelResolverException.class,
() -> newModelResolver().resolveModel(session, dependency, new AtomicReference<>()),
() -> newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()),
"Expected 'ModelResolverException' not thrown.");
assertEquals("The requested version range '[1,)' does not specify an upper bound", e.getMessage());
}
@ -184,7 +184,7 @@ class DefaultModelResolverTest {
.version("1")
.build();
assertNotNull(this.newModelResolver().resolveModel(session, dependency, new AtomicReference<>()));
assertNotNull(this.newModelResolver().resolveModel(session, null, dependency, new AtomicReference<>()));
assertEquals("1", dependency.getVersion());
}
@ -197,7 +197,7 @@ class DefaultModelResolverTest {
.build();
AtomicReference<org.apache.maven.api.model.Dependency> modified = new AtomicReference<>();
assertNotNull(this.newModelResolver().resolveModel(session, dependency, modified));
assertNotNull(this.newModelResolver().resolveModel(session, null, dependency, modified));
assertEquals("1", modified.get().getVersion());
}

View File

@ -66,7 +66,8 @@ public class DefaultProjectBuilder implements ProjectBuilder {
throws ProjectBuilderException, IllegalArgumentException {
InternalMavenSession session = InternalMavenSession.from(request.getSession());
try {
List<ArtifactRepository> repositories = session.toArtifactRepositories(session.getRemoteRepositories());
List<ArtifactRepository> repositories = session.toArtifactRepositories(
request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories());
ProjectBuildingRequest req = new DefaultProjectBuildingRequest()
.setRepositorySession(session.getSession())
.setRemoteRepositories(repositories)
@ -134,14 +135,14 @@ public class DefaultProjectBuilder implements ProjectBuilder {
}
if (getLineNumber() > 0) {
if (buffer.length() > 0) {
if (!buffer.isEmpty()) {
buffer.append(", ");
}
buffer.append("line ").append(getLineNumber());
}
if (getColumnNumber() > 0) {
if (buffer.length() > 0) {
if (!buffer.isEmpty()) {
buffer.append(", ");
}
buffer.append("column ").append(getColumnNumber());

View File

@ -54,7 +54,6 @@ import org.apache.maven.api.plugin.descriptor.Resolution;
import org.apache.maven.api.services.DependencyResolver;
import org.apache.maven.api.services.DependencyResolverResult;
import org.apache.maven.api.services.PathScopeRegistry;
import org.apache.maven.api.services.ProjectManager;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.classrealm.ClassRealmManager;
@ -549,10 +548,6 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
InternalMavenSession sessionV4 = InternalMavenSession.from(session.getSession());
Project project = sessionV4.getProject(session.getCurrentProject());
List<org.apache.maven.api.RemoteRepository> repos =
sessionV4.getService(ProjectManager.class).getRemoteProjectRepositories(project);
sessionV4 = InternalMavenSession.from(sessionV4.withRemoteRepositories(repos));
org.apache.maven.api.MojoExecution execution = new DefaultMojoExecution(sessionV4, mojoExecution);
org.apache.maven.api.plugin.Log log = new DefaultLog(
LoggerFactory.getLogger(mojoExecution.getMojoDescriptor().getFullGoalName()));

View File

@ -1108,9 +1108,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
ModelBuilderRequest.ModelBuilderRequestBuilder modelBuildingRequest = ModelBuilderRequest.builder();
InternalSession internalSession = InternalSession.from(session);
modelBuildingRequest.session(internalSession.withRemoteRepositories(request.getRemoteRepositories().stream()
.map(r -> internalSession.getRemoteRepository(RepositoryUtils.toRepo(r)))
.toList()));
modelBuildingRequest.session(internalSession);
modelBuildingRequest.validationLevel(request.getValidationLevel());
modelBuildingRequest.processPlugins(request.isProcessPlugins());
modelBuildingRequest.profiles(
@ -1135,6 +1133,9 @@ public class DefaultProjectBuilder implements ProjectBuilder {
modelBuildingRequest.modelRepositoryHolder(holder);
modelBuildingRequest.modelCache(modelCache);
modelBuildingRequest.transformerContextBuilder(transformerContextBuilder);
modelBuildingRequest.repositories(request.getRemoteRepositories().stream()
.map(r -> internalSession.getRemoteRepository(RepositoryUtils.toRepo(r)))
.toList());
/* TODO: bv4
InternalMavenSession session =
(InternalMavenSession) this.session.getData().get(InternalMavenSession.class);
@ -1300,12 +1301,17 @@ public class DefaultProjectBuilder implements ProjectBuilder {
@Override
public ModelSource resolveModel(
Session session, String groupId, String artifactId, String version, Consumer<String> resolved)
Session session,
List<org.apache.maven.api.RemoteRepository> repositories,
String groupId,
String artifactId,
String version,
Consumer<String> resolved)
throws ModelResolverException {
try {
InternalSession internalSession = InternalSession.from(session);
org.apache.maven.model.resolution.ModelResolver resolver =
getResolver(internalSession.toRepositories(internalSession.getRemoteRepositories()));
org.apache.maven.model.resolution.ModelResolver resolver = getResolver(internalSession.toRepositories(
repositories != null ? repositories : internalSession.getRemoteRepositories()));
org.apache.maven.model.Parent p = new org.apache.maven.model.Parent(Parent.newBuilder()
.groupId(groupId)
.artifactId(artifactId)
@ -1322,13 +1328,17 @@ public class DefaultProjectBuilder implements ProjectBuilder {
}
@Override
public ModelSource resolveModel(Session session, Parent parent, AtomicReference<Parent> modified)
public ModelSource resolveModel(
Session session,
List<org.apache.maven.api.RemoteRepository> repositories,
Parent parent,
AtomicReference<Parent> modified)
throws ModelResolverException {
try {
org.apache.maven.model.Parent p = new org.apache.maven.model.Parent(parent);
InternalSession internalSession = InternalSession.from(session);
org.apache.maven.model.resolution.ModelResolver resolver =
getResolver(internalSession.toRepositories(internalSession.getRemoteRepositories()));
org.apache.maven.model.resolution.ModelResolver resolver = getResolver(internalSession.toRepositories(
repositories != null ? repositories : internalSession.getRemoteRepositories()));
ModelSource source = toSource(resolver.resolveModel(p));
if (p.getDelegate() != parent) {
modified.set(p.getDelegate());
@ -1340,13 +1350,17 @@ public class DefaultProjectBuilder implements ProjectBuilder {
}
@Override
public ModelSource resolveModel(Session session, Dependency dependency, AtomicReference<Dependency> modified)
public ModelSource resolveModel(
Session session,
List<org.apache.maven.api.RemoteRepository> repositories,
Dependency dependency,
AtomicReference<Dependency> modified)
throws ModelResolverException {
try {
org.apache.maven.model.Dependency d = new org.apache.maven.model.Dependency(dependency);
InternalSession internalSession = InternalSession.from(session);
org.apache.maven.model.resolution.ModelResolver resolver =
getResolver(internalSession.toRepositories(internalSession.getRemoteRepositories()));
org.apache.maven.model.resolution.ModelResolver resolver = getResolver(internalSession.toRepositories(
repositories != null ? repositories : internalSession.getRemoteRepositories()));
ModelSource source = toSource(resolver.resolveModel(d));
if (d.getDelegate() != dependency) {
modified.set(d.getDelegate());

View File

@ -27,8 +27,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.services.ModelResolver;
@ -101,7 +103,12 @@ public class ConsumerPomBuilderTest extends AbstractRepositoryTestCase {
public static class MyModelResolver implements ModelResolver {
@Override
public ModelSource resolveModel(
Session session, String groupId, String artifactId, String version, Consumer<String> resolvedVersion)
Session session,
List<RemoteRepository> repositories,
String groupId,
String artifactId,
String version,
Consumer<String> resolvedVersion)
throws ModelResolverException {
String id = groupId + ":" + artifactId + ":" + version;
if (id.startsWith("org.sonatype.mavenbook.multi:parent:")) {