Skip to content

Commit 30dc812

Browse files
gnodetdesruisseaux
andauthored
Renaming of ArtifactCoordinate.getVersion() + documentation (#1662)
* Rename ArtifactCoordinate.getVersion() as getVersionConstraint(). * Introduce DownloadedArtifact, DownloadedDependency and ProducedArtifact. * Rename coordinate -> coordinates. * Add documentation on Artifact, ArtifactCoordinates, Dependency and DependencyCoordinates and other classes. * Remove `LATEST` and `SNAPSHOT` from documentation since they are deprecated. * Opportunistic addition of some missing `@Override` annotations. --------- Co-authored-by: Martin Desruisseaux <[email protected]>
1 parent 6a5580f commit 30dc812

File tree

74 files changed

+1331
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1331
-563
lines changed

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

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,91 @@
2323
import org.apache.maven.api.annotations.Nonnull;
2424

2525
/**
26-
* An artifact points to a resource such as a jar file or war application.
26+
* A Maven artifact is a file, typically a JAR, that is produced and used by Maven projects.
27+
* It is identified by a unique combination of a group ID, artifact ID, version, classifier,
28+
* and extension, and it is stored in a repository for dependency management and build purposes.
29+
*
30+
* <p>Each {@code Artifact} instance is basically an exact pointer to a file in a Maven repository.
31+
* {@code Artifact} instances are created when <dfn>resolving</dfn> {@link ArtifactCoordinates} instances.
32+
* Resolving is the process that selects a {@linkplain #getVersion() particular version}
33+
* and downloads the artifact in the local repository. This operation returns a {@link DownloadedArtifact}.
34+
* </p>
2735
*
2836
* @since 4.0.0
2937
*/
3038
@Experimental
3139
@Immutable
3240
public interface Artifact {
33-
3441
/**
35-
* Returns a unique identifier for this artifact.
42+
* {@return a unique identifier for this artifact}.
3643
* The identifier is composed of groupId, artifactId, extension, classifier, and version.
3744
*
38-
* @return the unique identifier
45+
* @see ArtifactCoordinates#getId()
3946
*/
4047
@Nonnull
4148
default String key() {
49+
String c = getClassifier();
4250
return getGroupId()
4351
+ ':'
4452
+ getArtifactId()
4553
+ ':'
4654
+ getExtension()
47-
+ (getClassifier().isEmpty() ? "" : ":" + getClassifier())
55+
+ (c.isEmpty() ? "" : ":" + c)
4856
+ ':'
4957
+ getVersion();
5058
}
5159

5260
/**
53-
* The groupId of the artifact.
61+
* {@return the group identifier of the artifact}.
5462
*
55-
* @return the groupId
63+
* @see ArtifactCoordinates#getGroupId()
5664
*/
5765
@Nonnull
5866
String getGroupId();
5967

6068
/**
61-
* The artifactId of the artifact.
69+
* {@return the identifier of the artifact}.
6270
*
63-
* @return the artifactId
71+
* @see ArtifactCoordinates#getArtifactId()
6472
*/
6573
@Nonnull
6674
String getArtifactId();
6775

6876
/**
69-
* The version of the artifact.
77+
* {@return the version of the artifact}. Contrarily to {@link ArtifactCoordinates},
78+
* each {@code Artifact} is associated to a specific version instead of a range of versions.
79+
* If the {@linkplain #getBaseVersion() base version} contains a meta-version such as {@code SNAPSHOT},
80+
* those keywords are replaced by, for example, the actual timestamp.
7081
*
71-
* @return the version
82+
* @see ArtifactCoordinates#getVersionConstraint()
7283
*/
7384
@Nonnull
7485
Version getVersion();
7586

7687
/**
77-
* The base version of the artifact.
78-
*
79-
* @return the version
88+
* {@return the version or meta-version of the artifact}.
89+
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
90+
* Meta-versions are represented in a base version by their symbols (e.g., {@code SNAPSHOT}),
91+
* while they are replaced by, for example, the actual timestamp in the {@linkplain #getVersion() version}.
8092
*/
8193
@Nonnull
8294
Version getBaseVersion();
8395

8496
/**
85-
* The classifier of the artifact.
97+
* Returns the classifier of the artifact.
8698
*
8799
* @return the classifier or an empty string if none, never {@code null}
100+
* @see ArtifactCoordinates#getClassifier()
88101
*/
89102
@Nonnull
90103
String getClassifier();
91104

92105
/**
93-
* The file extension of the artifact.
106+
* Returns the file extension of the artifact.
107+
* The dot separator is <em>not</em> included in the returned string.
94108
*
95-
* @return the extension
109+
* @return the file extension or an empty string if none, never {@code null}
110+
* @see ArtifactCoordinates#getExtension()
96111
*/
97112
@Nonnull
98113
String getExtension();
@@ -106,11 +121,11 @@ default String key() {
106121
boolean isSnapshot();
107122

108123
/**
109-
* Shortcut for {@code session.createArtifactCoordinate(artifact)}
124+
* {@return coordinates with the same identifiers as this artifact}.
125+
* This is a shortcut for {@code session.createArtifactCoordinates(artifact)}.
110126
*
111-
* @return an {@link ArtifactCoordinate}
112-
* @see org.apache.maven.api.Session#createArtifactCoordinate(Artifact)
127+
* @see org.apache.maven.api.Session#createArtifactCoordinates(Artifact)
113128
*/
114129
@Nonnull
115-
ArtifactCoordinate toCoordinate();
130+
ArtifactCoordinates toCoordinates();
116131
}

api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinate.java renamed to api/maven-api-core/src/main/java/org/apache/maven/api/ArtifactCoordinates.java

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,64 +23,70 @@
2323
import org.apache.maven.api.annotations.Nonnull;
2424

2525
/**
26-
* The {@code Coordinate} object is used to point to an {@link Artifact}
27-
* but the version may be specified as a range instead of an exact version.
26+
* Partial identification of an {@link Artifact} in a Maven repository.
27+
* Each {@code ArtifactCoordinates} instance is basically a pointer to a file in the Maven repository,
28+
* except that the exact version may not be known yet.
2829
*
2930
* @since 4.0.0
3031
*/
3132
@Experimental
3233
@Immutable
33-
public interface ArtifactCoordinate {
34-
34+
public interface ArtifactCoordinates {
3535
/**
36-
* The groupId of the artifact.
37-
*
38-
* @return the groupId
36+
* {@return the group identifier of the artifact}.
3937
*/
4038
@Nonnull
4139
String getGroupId();
4240

4341
/**
44-
* The artifactId of the artifact.
45-
*
46-
* @return the artifactId
42+
* {@return the identifier of the artifact}.
4743
*/
4844
@Nonnull
4945
String getArtifactId();
5046

5147
/**
52-
* The classifier of the artifact.
48+
* Returns the classifier of the artifact.
5349
*
5450
* @return the classifier or an empty string if none, never {@code null}
5551
*/
5652
@Nonnull
5753
String getClassifier();
5854

5955
/**
60-
* The version of the artifact.
61-
*
62-
* @return the version
56+
* {@return the specific version, range of versions or meta-version of the artifact}.
57+
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
6358
*/
6459
@Nonnull
65-
VersionConstraint getVersion();
60+
VersionConstraint getVersionConstraint();
6661

6762
/**
68-
* The extension of the artifact.
63+
* Returns the file extension of the artifact.
64+
* The dot separator is <em>not</em> included in the returned string.
6965
*
70-
* @return the extension or an empty string if none, never {@code null}
66+
* @return the file extension or an empty string if none, never {@code null}
7167
*/
7268
@Nonnull
7369
String getExtension();
7470

7571
/**
76-
* Unique id identifying this artifact
72+
* {@return a unique string representation identifying this artifact}
73+
*
74+
* The default implementation returns a colon-separated list of group
75+
* identifier, artifact identifier, extension, classifier and version.
76+
*
77+
* @see Artifact#key()
7778
*/
7879
@Nonnull
7980
default String getId() {
81+
String c = getClassifier();
8082
return getGroupId()
81-
+ ":" + getArtifactId()
82-
+ ":" + getExtension()
83-
+ (getClassifier().isEmpty() ? "" : ":" + getClassifier())
84-
+ ":" + getVersion();
83+
+ ':'
84+
+ getArtifactId()
85+
+ ':'
86+
+ getExtension()
87+
+ ':'
88+
+ c
89+
+ (c.isEmpty() ? "" : ":")
90+
+ getVersionConstraint();
8591
}
8692
}

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,51 @@
2323
import org.apache.maven.api.annotations.Nonnull;
2424

2525
/**
26+
* A result of collecting, flattening and resolving {@link DependencyCoordinates}s.
27+
* Dependency is the output of the <dfn>collection</dfn> process, which builds the graph of dependencies,
28+
* followed by <dfn>flattening</dfn> and <dfn>resolution</dfn>.
29+
* The version selection is done for each dependency during the collection phase.
30+
* The flatten phase will keep only a single version per ({@code groupId}, {@code artifactId}) pair.
31+
* The resolution will actually download the dependencies (or artifacts) that have been computed.
2632
*
2733
* @since 4.0.0
2834
*/
2935
@Experimental
3036
@Immutable
3137
public interface Dependency extends Artifact {
32-
3338
/**
34-
* The dependency type.
39+
* {@return the type of the dependency}. A dependency can be a <abbr>JAR</abbr> file,
40+
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module-path,
41+
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
3542
*
36-
* @return the dependency type, never {@code null}
43+
* @see DependencyCoordinates#getType()
3744
*/
3845
@Nonnull
3946
Type getType();
4047

48+
/**
49+
* {@return the time at which the dependency will be used}.
50+
* If may be, for example, at compile time only, at run time or at test time.
51+
*
52+
* @see DependencyCoordinates#getScope()
53+
*/
4154
@Nonnull
4255
DependencyScope getScope();
4356

57+
/**
58+
* Returns whether the dependency is optional or mandatory.
59+
* Contrarily to {@link DependencyCoordinates}, the obligation of a {@code Dependency} is always present.
60+
* The value is computed during the dependencies collection phase.
61+
*
62+
* @return {@code true} if the dependency is optional, or {@code false} if mandatory
63+
* @see DependencyCoordinates#getOptional()
64+
*/
4465
boolean isOptional();
4566

4667
/**
47-
* Creates a {@code DependencyCoordinate} based on this {@code Dependency}.
48-
*
49-
* @return a {@link DependencyCoordinate}
68+
* {@return coordinates with the same identifiers as this dependency}
5069
*/
5170
@Nonnull
5271
@Override
53-
DependencyCoordinate toCoordinate();
72+
DependencyCoordinates toCoordinates();
5473
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api;
20+
21+
import java.util.Collection;
22+
23+
import org.apache.maven.api.annotations.Experimental;
24+
import org.apache.maven.api.annotations.Immutable;
25+
import org.apache.maven.api.annotations.Nonnull;
26+
import org.apache.maven.api.annotations.Nullable;
27+
28+
/**
29+
* {@code ArtifactCoordinates} completed with information about how the artifact will be used.
30+
* This information include the dependency type (main classes, test classes, <i>etc.</i>),
31+
* a scope (compile-time, run-time <i>etc.</i>), an obligation (whether the dependency
32+
* is optional or mandatory), and possible exclusions for transitive dependencies.
33+
* The {@linkplain #getVersionConstraint() version} and the {@linkplain #getOptional() obligation}
34+
* may not be defined precisely.
35+
*
36+
* @since 4.0.0
37+
*/
38+
@Experimental
39+
@Immutable
40+
public interface DependencyCoordinates extends ArtifactCoordinates {
41+
/**
42+
* {@return the type of the dependency}. A dependency can be a <abbr>JAR</abbr> file,
43+
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module-path,
44+
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
45+
*/
46+
@Nonnull
47+
Type getType();
48+
49+
/**
50+
* {@return the time at which the dependency will be used}.
51+
* If may be, for example, at compile time only, at run time or at test time.
52+
*/
53+
@Nonnull
54+
DependencyScope getScope();
55+
56+
/**
57+
* Returns whether the dependency is optional, mandatory or of unspecified obligation.
58+
*
59+
* @return the obligation, or {@code null} if unspecified
60+
*/
61+
@Nullable
62+
Boolean getOptional();
63+
64+
/**
65+
* {@return transitive dependencies to exclude}.
66+
*/
67+
@Nonnull
68+
Collection<Exclusion> getExclusions();
69+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.apache.maven.api.annotations.Nonnull;
2929

3030
/**
31-
* Dependency scope.
32-
* This represents at which time the dependency will be used, for example, at compile time only,
33-
* at run time or at test time. For a given dependency, the scope is directly derived from the
31+
* Indicates when the dependency will be used.
32+
* For example, it may be at compile time only, at runtime, or at test time.
33+
* For a given dependency, the scope is directly derived from the
3434
* {@link org.apache.maven.api.model.Dependency#getScope()} and will be used when using {@link PathScope}
3535
* and the {@link org.apache.maven.api.services.DependencyResolver}.
3636
*
@@ -50,7 +50,7 @@ public enum DependencyScope {
5050

5151
/**
5252
* Undefined. When no scope is explicitly given, UNDEFINED will be used, but its meaning will depend on
53-
* whether the DependencyCoordinate is used in dependency management, in which case it means the scope is not
53+
* whether the DependencyCoordinates is used in dependency management, in which case it means the scope is not
5454
* explicitly managed by this managed dependency, or as a real dependency, in which case, the scope
5555
* will default to {@link #COMPILE}.
5656
*/

0 commit comments

Comments
 (0)