[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. * 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 request trace so that requests can be linked together and through the resolver
* TODO: add a Request interface holding session + parent request * TODO: add a Request interface holding session + parent request
* *
@ -425,6 +424,19 @@ public interface Session {
@Nonnull @Nonnull
DownloadedArtifact resolveArtifact(@Nonnull ArtifactCoordinates coordinates); 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(...)}. * Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
* *
@ -449,6 +461,21 @@ public interface Session {
@Nonnull @Nonnull
Collection<DownloadedArtifact> resolveArtifacts(@Nonnull Collection<? extends ArtifactCoordinates> coordinates); 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(...)}. * Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
* *
@ -461,6 +488,19 @@ public interface Session {
@Nonnull @Nonnull
DownloadedArtifact resolveArtifact(@Nonnull Artifact artifact); 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(...)}. * Shortcut for {@code getService(ArtifactResolver.class).resolve(...)}.
* *
@ -717,6 +757,23 @@ public interface Session {
@Nonnull @Nonnull
List<Version> resolveVersionRange(@Nonnull ArtifactCoordinates artifact); 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". * Parses the specified version string, for example "1.0".
* <p> * <p>

View File

@ -19,8 +19,10 @@
package org.apache.maven.api.services; package org.apache.maven.api.services;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates; import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; 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) { default ArtifactResolverResult resolve(Session session, Collection<? extends ArtifactCoordinates> coordinates) {
return resolve(ArtifactResolverRequest.build(session, 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; package org.apache.maven.api.services;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates; import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.NotThreadSafe; import org.apache.maven.api.annotations.NotThreadSafe;
import org.apache.maven.api.annotations.Nullable;
import static org.apache.maven.api.services.BaseRequest.nonNull; import static org.apache.maven.api.services.BaseRequest.nonNull;
@ -43,6 +46,9 @@ public interface ArtifactResolverRequest {
@Nonnull @Nonnull
Collection<? extends ArtifactCoordinates> getCoordinates(); Collection<? extends ArtifactCoordinates> getCoordinates();
@Nonnull
List<RemoteRepository> getRepositories();
@Nonnull @Nonnull
static ArtifactResolverRequestBuilder builder() { static ArtifactResolverRequestBuilder builder() {
return new ArtifactResolverRequestBuilder(); return new ArtifactResolverRequestBuilder();
@ -57,10 +63,23 @@ public interface ArtifactResolverRequest {
.build(); .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 @NotThreadSafe
class ArtifactResolverRequestBuilder { class ArtifactResolverRequestBuilder {
Session session; Session session;
Collection<? extends ArtifactCoordinates> coordinates; Collection<? extends ArtifactCoordinates> coordinates;
List<RemoteRepository> repositories;
ArtifactResolverRequestBuilder() {} ArtifactResolverRequestBuilder() {}
@ -76,19 +95,31 @@ public interface ArtifactResolverRequest {
return this; return this;
} }
@Nonnull
public ArtifactResolverRequestBuilder repositories(List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
@Nonnull @Nonnull
public ArtifactResolverRequest build() { public ArtifactResolverRequest build() {
return new DefaultArtifactResolverRequest(session, coordinates); return new DefaultArtifactResolverRequest(session, coordinates, repositories);
} }
private static class DefaultArtifactResolverRequest extends BaseRequest implements ArtifactResolverRequest { private static class DefaultArtifactResolverRequest extends BaseRequest implements ArtifactResolverRequest {
@Nonnull @Nonnull
private final Collection<? extends ArtifactCoordinates> coordinates; private final Collection<? extends ArtifactCoordinates> coordinates;
@Nullable
private final List<RemoteRepository> repositories;
DefaultArtifactResolverRequest( DefaultArtifactResolverRequest(
@Nonnull Session session, @Nonnull Collection<? extends ArtifactCoordinates> coordinates) { @Nonnull Session session,
@Nonnull Collection<? extends ArtifactCoordinates> coordinates,
@Nonnull List<RemoteRepository> repositories) {
super(session); super(session);
this.coordinates = unmodifiable(nonNull(coordinates, "coordinates cannot be null")); this.coordinates = unmodifiable(nonNull(coordinates, "coordinates cannot be null"));
this.repositories = repositories;
} }
@Nonnull @Nonnull
@ -96,6 +127,12 @@ public interface ArtifactResolverRequest {
public Collection<? extends ArtifactCoordinates> getCoordinates() { public Collection<? extends ArtifactCoordinates> getCoordinates() {
return coordinates; 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.PathScope;
import org.apache.maven.api.PathType; import org.apache.maven.api.PathType;
import org.apache.maven.api.Project; import org.apache.maven.api.Project;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable; import org.apache.maven.api.annotations.Immutable;
@ -94,6 +95,9 @@ public interface DependencyResolverRequest {
@Nullable @Nullable
Predicate<PathType> getPathTypeFilter(); Predicate<PathType> getPathTypeFilter();
@Nullable
List<RemoteRepository> getRepositories();
@Nonnull @Nonnull
static DependencyResolverRequestBuilder builder() { static DependencyResolverRequestBuilder builder() {
return new DependencyResolverRequestBuilder(); return new DependencyResolverRequestBuilder();
@ -170,6 +174,7 @@ public interface DependencyResolverRequest {
boolean verbose; boolean verbose;
PathScope pathScope; PathScope pathScope;
Predicate<PathType> pathTypeFilter; Predicate<PathType> pathTypeFilter;
List<RemoteRepository> repositories;
DependencyResolverRequestBuilder() {} DependencyResolverRequestBuilder() {}
@ -327,6 +332,12 @@ public interface DependencyResolverRequest {
return pathTypeFilter(desiredTypes::contains); return pathTypeFilter(desiredTypes::contains);
} }
@Nonnull
public DependencyResolverRequestBuilder repositories(@Nonnull List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}
@Nonnull @Nonnull
public DependencyResolverRequest build() { public DependencyResolverRequest build() {
return new DefaultDependencyResolverRequest( return new DefaultDependencyResolverRequest(
@ -339,7 +350,8 @@ public interface DependencyResolverRequest {
managedDependencies, managedDependencies,
verbose, verbose,
pathScope, pathScope,
pathTypeFilter); pathTypeFilter,
repositories);
} }
static class DefaultDependencyResolverRequest extends BaseRequest implements DependencyResolverRequest { static class DefaultDependencyResolverRequest extends BaseRequest implements DependencyResolverRequest {
@ -352,6 +364,7 @@ public interface DependencyResolverRequest {
private final boolean verbose; private final boolean verbose;
private final PathScope pathScope; private final PathScope pathScope;
private final Predicate<PathType> pathTypeFilter; private final Predicate<PathType> pathTypeFilter;
private final List<RemoteRepository> repositories;
/** /**
* Creates a request with the specified properties. * Creates a request with the specified properties.
@ -371,7 +384,8 @@ public interface DependencyResolverRequest {
@Nonnull Collection<DependencyCoordinates> managedDependencies, @Nonnull Collection<DependencyCoordinates> managedDependencies,
boolean verbose, boolean verbose,
@Nullable PathScope pathScope, @Nullable PathScope pathScope,
@Nullable Predicate<PathType> pathTypeFilter) { @Nullable Predicate<PathType> pathTypeFilter,
@Nullable List<RemoteRepository> repositories) {
super(session); super(session);
this.requestType = nonNull(requestType, "requestType cannot be null"); this.requestType = nonNull(requestType, "requestType cannot be null");
this.project = project; this.project = project;
@ -383,6 +397,7 @@ public interface DependencyResolverRequest {
this.verbose = verbose; this.verbose = verbose;
this.pathScope = pathScope; this.pathScope = pathScope;
this.pathTypeFilter = (pathTypeFilter != null) ? pathTypeFilter : (t) -> true; this.pathTypeFilter = (pathTypeFilter != null) ? pathTypeFilter : (t) -> true;
this.repositories = repositories;
if (verbose && requestType != RequestType.COLLECT) { if (verbose && requestType != RequestType.COLLECT) {
throw new IllegalArgumentException("verbose cannot only be true when collecting dependencies"); throw new IllegalArgumentException("verbose cannot only be true when collecting dependencies");
} }
@ -439,6 +454,11 @@ public interface DependencyResolverRequest {
return pathTypeFilter; return pathTypeFilter;
} }
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
@Nonnull @Nonnull
@Override @Override
public String toString() { public String toString() {

View File

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

View File

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

View File

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

View File

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

View File

@ -18,12 +18,16 @@
*/ */
package org.apache.maven.api.services; package org.apache.maven.api.services;
import java.util.List;
import org.apache.maven.api.ArtifactCoordinates; import org.apache.maven.api.ArtifactCoordinates;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Service; import org.apache.maven.api.Service;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.annotations.Consumer; import org.apache.maven.api.annotations.Consumer;
import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull; import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
/** /**
* Parses and evaluates version ranges encountered in dependency declarations. * Parses and evaluates version ranges encountered in dependency declarations.
@ -54,6 +58,29 @@ public interface VersionRangeResolver extends Service {
return resolve(VersionRangeResolverRequest.build(session, artifactCoordinates)); 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 @Nonnull
VersionRangeResolverResult resolve(@Nonnull VersionRangeResolverRequest request) VersionRangeResolverResult resolve(@Nonnull VersionRangeResolverRequest request)
throws VersionRangeResolverException; throws VersionRangeResolverException;

View File

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

View File

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

View File

@ -547,6 +547,21 @@ public abstract class AbstractSession implements InternalSession {
.next(); .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> * 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(); 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> * Shortcut for <code>getService(ArtifactResolver.class).resolve(...)</code>
* *
@ -582,6 +611,19 @@ public abstract class AbstractSession implements InternalSession {
return resolveArtifact(coordinates); 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 @Override
public Collection<DownloadedArtifact> resolveArtifacts(Artifact... artifacts) { public Collection<DownloadedArtifact> resolveArtifacts(Artifact... artifacts) {
ArtifactCoordinatesFactory acf = getService(ArtifactCoordinatesFactory.class); ArtifactCoordinatesFactory acf = getService(ArtifactCoordinatesFactory.class);
@ -803,6 +845,13 @@ public abstract class AbstractSession implements InternalSession {
return getService(VersionRangeResolver.class).resolve(this, artifact).getVersions(); 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 @Override
public Type requireType(String id) { public Type requireType(String id) {
return getService(TypeRegistry.class).require(id); return getService(TypeRegistry.class).require(id);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; 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.Inject;
import org.apache.maven.api.di.Named; import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton; 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.api.services.ModelSource;
import org.apache.maven.internal.impl.InternalSession; import org.apache.maven.internal.impl.InternalSession;
import org.apache.maven.internal.impl.model.ModelProblemUtils; 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;
import org.eclipse.aether.RepositoryEvent.EventType; import org.eclipse.aether.RepositoryEvent.EventType;
import org.eclipse.aether.RepositoryException; import org.eclipse.aether.RepositoryException;
@ -199,18 +198,16 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
try { try {
InternalSession iSession = InternalSession.from(session); InternalSession iSession = InternalSession.from(session);
Session iSessionWithRepos = iSession.withRemoteRepositories(request.getRepositories().stream() List<RemoteRepository> repositories = request.getRepositories().stream()
.map(iSession::getRemoteRepository) .map(iSession::getRemoteRepository)
.toList()); .toList();
String gav = String gav =
pomArtifact.getGroupId() + ":" + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion(); pomArtifact.getGroupId() + ":" + pomArtifact.getArtifactId() + ":" + pomArtifact.getVersion();
ModelResolver modelResolver = new DefaultModelResolver(); ModelResolver modelResolver = new DefaultModelResolver();
ModelRepositoryHolder modelRepositoryHolder = new DefaultModelRepositoryHolder( ModelRepositoryHolder modelRepositoryHolder = new DefaultModelRepositoryHolder(
iSessionWithRepos, iSession, DefaultModelRepositoryHolder.RepositoryMerging.REQUEST_DOMINANT, repositories);
DefaultModelRepositoryHolder.RepositoryMerging.REQUEST_DOMINANT,
iSessionWithRepos.getRemoteRepositories());
ModelBuilderRequest modelRequest = ModelBuilderRequest.builder() ModelBuilderRequest modelRequest = ModelBuilderRequest.builder()
.session(iSessionWithRepos) .session(iSession)
.projectBuild(false) .projectBuild(false)
.processPlugins(false) .processPlugins(false)
.twoPhaseBuilding(false) .twoPhaseBuilding(false)
@ -222,6 +219,7 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
.modelResolver(modelResolver) .modelResolver(modelResolver)
.modelRepositoryHolder(modelRepositoryHolder) .modelRepositoryHolder(modelRepositoryHolder)
.modelCache(DefaultModelCache.newInstance(session, false)) .modelCache(DefaultModelCache.newInstance(session, false))
.repositories(repositories)
.build(); .build();
ModelBuilderResult modelResult = modelBuilder.build(modelRequest); ModelBuilderResult modelResult = modelBuilder.build(modelRequest);
@ -230,21 +228,23 @@ public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader
if (!modelResult.getProblems().isEmpty()) { if (!modelResult.getProblems().isEmpty()) {
List<ModelProblem> problems = modelResult.getProblems(); List<ModelProblem> problems = modelResult.getProblems();
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
String problem = (problems.size() == 1) ? "problem" : "problems"; StringBuilder sb = new StringBuilder();
String problemPredicate = problem + ((problems.size() == 1) ? " was" : " were"); sb.append(problems.size())
String message = String.format( .append(" ")
"%s %s encountered while building the effective model for %s during %s\n", .append((problems.size() == 1) ? "problem was" : "problems were")
problems.size(), .append(" encountered while building the effective model for ")
problemPredicate, .append(request.getArtifact())
request.getArtifact(), .append(" during ")
RequestTraceHelper.interpretTrace(true, request.getTrace())); .append(RequestTraceHelper.interpretTrace(true, request.getTrace()))
message += StringUtils.capitalizeFirstLetter(problem); .append("\n")
.append((problems.size() == 1) ? "Problem" : "Problems");
for (ModelProblem modelProblem : problems) { for (ModelProblem modelProblem : problems) {
message += String.format( sb.append("\n* ")
"\n* %s @ %s", .append(modelProblem.getMessage())
modelProblem.getMessage(), ModelProblemUtils.formatLocation(modelProblem, null)); .append(" @ ")
.append(ModelProblemUtils.formatLocation(modelProblem, null));
} }
logger.warn(message); logger.warn(sb.toString());
} else { } else {
logger.warn( logger.warn(
"{} {} encountered while building the effective model for {} during {} (use -X to see details)", "{} {} 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.ArtifactCoordinates;
import org.apache.maven.api.DownloadedArtifact; import org.apache.maven.api.DownloadedArtifact;
import org.apache.maven.api.RemoteRepository;
import org.apache.maven.api.Session; import org.apache.maven.api.Session;
import org.apache.maven.api.Version; import org.apache.maven.api.Version;
import org.apache.maven.api.di.Named; import org.apache.maven.api.di.Named;
@ -50,7 +51,12 @@ public class DefaultModelResolver implements ModelResolver {
@Override @Override
public ModelSource resolveModel( 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 { throws ModelResolverException {
try { try {
ArtifactCoordinates coords = session.createArtifactCoordinates(groupId, artifactId, version, "pom"); ArtifactCoordinates coords = session.createArtifactCoordinates(groupId, artifactId, version, "pom");
@ -63,7 +69,7 @@ public class DefaultModelResolver implements ModelResolver {
artifactId, artifactId,
version); version);
} }
List<Version> versions = session.resolveVersionRange(coords); List<Version> versions = session.resolveVersionRange(coords, repositories);
if (versions.isEmpty()) { if (versions.isEmpty()) {
throw new ModelResolverException( throw new ModelResolverException(
String.format("No versions matched the requested version range '%s'", version), String.format("No versions matched the requested version range '%s'", version),
@ -76,8 +82,8 @@ public class DefaultModelResolver implements ModelResolver {
resolvedVersion.accept(newVersion); resolvedVersion.accept(newVersion);
} }
DownloadedArtifact resolved = DownloadedArtifact resolved = session.resolveArtifact(
session.resolveArtifact(session.createArtifactCoordinates(groupId, artifactId, newVersion, "pom")); session.createArtifactCoordinates(groupId, artifactId, newVersion, "pom"), repositories);
Path path = resolved.getPath(); Path path = resolved.getPath();
String location = groupId + ":" + artifactId + ":" + newVersion; String location = groupId + ":" + artifactId + ":" + newVersion;
return new ModelSource() { return new ModelSource() {
@ -109,9 +115,8 @@ public class DefaultModelResolver implements ModelResolver {
} catch (VersionRangeResolverException | ArtifactResolverException e) { } catch (VersionRangeResolverException | ArtifactResolverException e) {
throw new ModelResolverException( throw new ModelResolverException(
e.getMessage() + " (remote repositories: " e.getMessage() + " (remote repositories: "
+ session.getRemoteRepositories().stream() + (repositories != null ? repositories : session.getRemoteRepositories())
.map(Object::toString) .stream().map(Object::toString).collect(Collectors.joining(", "))
.collect(Collectors.joining(", "))
+ ")", + ")",
groupId, groupId,
artifactId, artifactId,

View File

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

View File

@ -66,7 +66,8 @@ public class DefaultProjectBuilder implements ProjectBuilder {
throws ProjectBuilderException, IllegalArgumentException { throws ProjectBuilderException, IllegalArgumentException {
InternalMavenSession session = InternalMavenSession.from(request.getSession()); InternalMavenSession session = InternalMavenSession.from(request.getSession());
try { try {
List<ArtifactRepository> repositories = session.toArtifactRepositories(session.getRemoteRepositories()); List<ArtifactRepository> repositories = session.toArtifactRepositories(
request.getRepositories() != null ? request.getRepositories() : session.getRemoteRepositories());
ProjectBuildingRequest req = new DefaultProjectBuildingRequest() ProjectBuildingRequest req = new DefaultProjectBuildingRequest()
.setRepositorySession(session.getSession()) .setRepositorySession(session.getSession())
.setRemoteRepositories(repositories) .setRemoteRepositories(repositories)
@ -134,14 +135,14 @@ public class DefaultProjectBuilder implements ProjectBuilder {
} }
if (getLineNumber() > 0) { if (getLineNumber() > 0) {
if (buffer.length() > 0) { if (!buffer.isEmpty()) {
buffer.append(", "); buffer.append(", ");
} }
buffer.append("line ").append(getLineNumber()); buffer.append("line ").append(getLineNumber());
} }
if (getColumnNumber() > 0) { if (getColumnNumber() > 0) {
if (buffer.length() > 0) { if (!buffer.isEmpty()) {
buffer.append(", "); buffer.append(", ");
} }
buffer.append("column ").append(getColumnNumber()); 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.DependencyResolver;
import org.apache.maven.api.services.DependencyResolverResult; import org.apache.maven.api.services.DependencyResolverResult;
import org.apache.maven.api.services.PathScopeRegistry; 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.api.xml.XmlNode;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.classrealm.ClassRealmManager; import org.apache.maven.classrealm.ClassRealmManager;
@ -549,10 +548,6 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
InternalMavenSession sessionV4 = InternalMavenSession.from(session.getSession()); InternalMavenSession sessionV4 = InternalMavenSession.from(session.getSession());
Project project = sessionV4.getProject(session.getCurrentProject()); 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.MojoExecution execution = new DefaultMojoExecution(sessionV4, mojoExecution);
org.apache.maven.api.plugin.Log log = new DefaultLog( org.apache.maven.api.plugin.Log log = new DefaultLog(
LoggerFactory.getLogger(mojoExecution.getMojoDescriptor().getFullGoalName())); LoggerFactory.getLogger(mojoExecution.getMojoDescriptor().getFullGoalName()));

View File

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

View File

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