* Shortcut for {@code getService(VersionResolver.class).resolve(...)} * diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Version.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Version.java index ee29cc2b7e68..02f33f44c7ca 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/Version.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Version.java @@ -22,7 +22,9 @@ import org.apache.maven.api.annotations.Nonnull; /** - * A version usually parsed using the {@link org.apache.maven.api.services.VersionParser} service. + * A version or meta-version of an artifact or a dependency. + * A meta-version is a version suffixed with the {@code SNAPSHOT} keyword. + * Version is usually parsed using the {@link org.apache.maven.api.services.VersionParser} service. * * @since 4.0.0 * @see org.apache.maven.api.services.VersionParser#parseVersion(String) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/package-info.java b/api/maven-api-core/src/main/java/org/apache/maven/api/package-info.java new file mode 100644 index 000000000000..e2bbc4984517 --- /dev/null +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/package-info.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Core API for Maven plugins. + * + *
Artifact resolution is the process of {@linkplain org.apache.maven.api.services.VersionResolver + * resolving the version} and then downloading the file.
+ * + *Dependency resolution is the process of collecting dependencies, flattening the graph, + * and then downloading the file. The flattening phase removes branches of the graph so that one artifact + * per ({@code groupId}, {@code artifactId}) pair is present.
+ * + *{@link org.apache.maven.api.ArtifactCoordinate} instances are used to locate artifacts in a repository. + * Each instance is basically a pointer to a file in the Maven repository, except that the version may not be + * defined precisely.
+ * + *{@link org.apache.maven.api.Artifact} instances are the pointed artifacts in the repository. + * They are created when resolving an {@code ArtifactCoordinate}. Resolving is the process + * that selects a particular version and downloads the artifact in the local repository. + * The download may be deferred to the first time that the file is needed.
+ * + *{@link org.apache.maven.api.DependencyCoordinate} instances are used to express a dependency. + * They are an {@code ArtifactCoordinate} completed with information about how the artifact will be used: + * type, scope and obligation (whether the dependency is optional or mandatory). + * The version and the obligation may not be defined precisely.
+ * + *{@link org.apache.maven.api.Dependency} instances are the pointed dependencies in the repository. + * They are created when resolving a {@code DependencyCoordinate}. + * Resolving is the process that clarifies the obligation (optional or mandatory status), + * selects a particular version and downloads the artifact in the local repository.
+ * + *{@link org.apache.maven.api.Node} is the main output of the dependency collection process. + * it's the graph of dependencies. The above-cited {@code Dependency} instances are the outputs of the + * collection process, part of the graph computed from one or more {@code DependencyCoordinate}s.
+ */ +package org.apache.maven.api; diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinateFactoryRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinateFactoryRequest.java index 3b8a6a459df0..c2fd1424cc05 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinateFactoryRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactCoordinateFactoryRequest.java @@ -100,7 +100,7 @@ static ArtifactCoordinateFactoryRequest build(@Nonnull Session session, @Nonnull .groupId(nonNull(coordinate, "coordinate").getGroupId()) .artifactId(coordinate.getArtifactId()) .classifier(coordinate.getClassifier()) - .version(coordinate.getVersion().asString()) + .version(coordinate.getVersionConstraint().asString()) .extension(coordinate.getExtension()) .build(); } diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactoryRequest.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactoryRequest.java index 34483be0de67..5a9249b09f52 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactoryRequest.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinateFactoryRequest.java @@ -74,7 +74,7 @@ static DependencyCoordinateFactoryRequest build(@Nonnull Session session, @Nonnu .session(nonNull(session, "session cannot be null")) .groupId(nonNull(coordinate, "coordinate cannot be null").getGroupId()) .artifactId(coordinate.getArtifactId()) - .version(coordinate.getVersion().asString()) + .version(coordinate.getVersionConstraint().asString()) .classifier(coordinate.getClassifier()) .extension(coordinate.getExtension()) .build(); diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolver.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolver.java index 0a27f97d7c49..a470452f7e78 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolver.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/VersionResolver.java @@ -35,8 +35,8 @@ public interface VersionResolver extends Service { /** - * Resolves an artifact's meta version (if any) to a concrete version. For example, resolves "1.0-SNAPSHOT" - * to "1.0-20090208.132618-23" or "RELEASE"/"LATEST" to "2.0". + * Resolves an artifact's meta version (if any) to a concrete version. + * For example, resolves "1.0-SNAPSHOT" to "1.0-20090208.132618-23". * * @param session The repository session, must not be {@code null}. * @param artifactCoordinate The artifact coordinate for which the version needs to be resolved, must not be {@code null} @@ -50,8 +50,8 @@ default VersionResolverResult resolve(@Nonnull Session session, @Nonnull Artifac } /** - * Resolves an artifact's meta version (if any) to a concrete version. For example, resolves "1.0-SNAPSHOT" - * to "1.0-20090208.132618-23" or "RELEASE"/"LATEST" to "2.0". + * Resolves an artifact's meta version (if any) to a concrete version. + * For example, resolves "1.0-SNAPSHOT" to "1.0-20090208.132618-23". * * @param request The version request, must not be {@code null}. * @return The version result, never {@code null}. diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java index 1d37687b9226..e6e76ae70abe 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java @@ -306,7 +306,7 @@ public org.eclipse.aether.graph.Dependency toDependency(DependencyCoordinate dep dependency.getArtifactId(), dependency.getClassifier(), type.getExtension(), - dependency.getVersion().toString(), + dependency.getVersionConstraint().toString(), Map.of("type", type.id()), (ArtifactType) null), dependency.getScope().id(), @@ -357,7 +357,7 @@ public org.eclipse.aether.artifact.Artifact toArtifact(ArtifactCoordinate coord) coord.getArtifactId(), coord.getClassifier(), coord.getExtension(), - coord.getVersion().toString(), + coord.getVersionConstraint().toString(), null, (File) null); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinate.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinate.java index 04b4c73e286d..98dd3c04ca6f 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinate.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultArtifactCoordinate.java @@ -57,7 +57,7 @@ public String getArtifactId() { @Nonnull @Override - public VersionConstraint getVersion() { + public VersionConstraint getVersionConstraint() { return session.parseVersionConstraint(coordinate.getVersion()); } @@ -83,13 +83,13 @@ public boolean equals(Object o) { DefaultArtifactCoordinate that = (DefaultArtifactCoordinate) o; return Objects.equals(this.getGroupId(), that.getGroupId()) && Objects.equals(this.getArtifactId(), that.getArtifactId()) - && Objects.equals(this.getVersion(), that.getVersion()) + && Objects.equals(this.getVersionConstraint(), that.getVersionConstraint()) && Objects.equals(this.getClassifier(), that.getClassifier()); } @Override public int hashCode() { - return Objects.hash(getGroupId(), getArtifactId(), getVersion(), getClassifier()); + return Objects.hash(getGroupId(), getArtifactId(), getVersionConstraint(), getClassifier()); } @Override diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyCoordinate.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyCoordinate.java index dd88da7a3340..fed15cc41c26 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyCoordinate.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/DefaultDependencyCoordinate.java @@ -33,7 +33,7 @@ public DefaultDependencyCoordinate( } @Override - public VersionConstraint getVersion() { + public VersionConstraint getVersionConstraint() { return session.parseVersionConstraint(dependency.getArtifact().getVersion()); } diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelResolver.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelResolver.java index a3e251294e20..9473c8c36412 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelResolver.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/resolver/DefaultModelResolver.java @@ -50,8 +50,8 @@ public ModelSource resolveModel( throws ModelResolverException { try { ArtifactCoordinate coord = session.createArtifactCoordinate(groupId, artifactId, version, "pom"); - if (coord.getVersion().getVersionRange() != null - && coord.getVersion().getVersionRange().getUpperBoundary() == null) { + if (coord.getVersionConstraint().getVersionRange() != null + && coord.getVersionConstraint().getVersionRange().getUpperBoundary() == null) { // Message below is checked for in the MNG-2199 core IT. throw new ModelResolverException( String.format("The requested version range '%s' does not specify an upper bound", version), diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java index df98a1aa2259..bbbdc14d8278 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java @@ -37,8 +37,10 @@ */ public interface Artifact extends Comparable