Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
/**
* 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
*
Expand Down Expand Up @@ -425,6 +424,19 @@ ProducedArtifact createProducedArtifact(
@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(...)}.
*
Expand All @@ -449,6 +461,21 @@ ProducedArtifact createProducedArtifact(
@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(...)}.
*
Expand All @@ -461,6 +488,19 @@ ProducedArtifact createProducedArtifact(
@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(...)}.
*
Expand Down Expand Up @@ -717,6 +757,23 @@ Map<PathType, List<Path>> resolveDependencies(
@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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,6 +46,9 @@ public interface ArtifactResolverRequest {
@Nonnull
Collection<? extends ArtifactCoordinates> getCoordinates();

@Nonnull
List<RemoteRepository> getRepositories();

@Nonnull
static ArtifactResolverRequestBuilder builder() {
return new ArtifactResolverRequestBuilder();
Expand All @@ -57,10 +63,23 @@ static 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
class ArtifactResolverRequestBuilder {
Session session;
Collection<? extends ArtifactCoordinates> coordinates;
List<RemoteRepository> repositories;

ArtifactResolverRequestBuilder() {}

Expand All @@ -76,26 +95,44 @@ public ArtifactResolverRequestBuilder coordinates(Collection<? extends ArtifactC
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
@Override
public Collection<? extends ArtifactCoordinates> getCoordinates() {
return coordinates;
}

@Nullable
@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -94,6 +95,9 @@ enum RequestType {
@Nullable
Predicate<PathType> getPathTypeFilter();

@Nullable
List<RemoteRepository> getRepositories();

@Nonnull
static DependencyResolverRequestBuilder builder() {
return new DependencyResolverRequestBuilder();
Expand Down Expand Up @@ -170,6 +174,7 @@ class DependencyResolverRequestBuilder {
boolean verbose;
PathScope pathScope;
Predicate<PathType> pathTypeFilter;
List<RemoteRepository> repositories;

DependencyResolverRequestBuilder() {}

Expand Down Expand Up @@ -327,6 +332,12 @@ public DependencyResolverRequestBuilder pathTypeFilter(@Nonnull Collection<? ext
return pathTypeFilter(desiredTypes::contains);
}

@Nonnull
public DependencyResolverRequestBuilder repositories(@Nonnull List<RemoteRepository> repositories) {
this.repositories = repositories;
return this;
}

@Nonnull
public DependencyResolverRequest build() {
return new DefaultDependencyResolverRequest(
Expand All @@ -339,7 +350,8 @@ public DependencyResolverRequest build() {
managedDependencies,
verbose,
pathScope,
pathTypeFilter);
pathTypeFilter,
repositories);
}

static class DefaultDependencyResolverRequest extends BaseRequest implements DependencyResolverRequest {
Expand All @@ -352,6 +364,7 @@ static class DefaultDependencyResolverRequest extends BaseRequest implements Dep
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.
Expand All @@ -371,7 +384,8 @@ static class DefaultDependencyResolverRequest extends BaseRequest implements Dep
@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;
Expand All @@ -383,6 +397,7 @@ static class DefaultDependencyResolverRequest extends BaseRequest implements Dep
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");
}
Expand Down Expand Up @@ -439,6 +454,11 @@ public Predicate<PathType> getPathTypeFilter() {
return pathTypeFilter;
}

@Override
public List<RemoteRepository> getRepositories() {
return repositories;
}

@Nonnull
@Override
public String toString() {
Expand Down
Loading