Skip to content

Commit c0f25d3

Browse files
committed
Switch core API value types to noun-style accessors
Add noun-style accessors (record-accessor pattern) to core API interfaces for immutable value types, consistent with modern JDK conventions and existing Maven 4 API types (XmlNode, PathType, Lifecycle.Phase, etc.). For each method, the noun-style accessor is now the primary abstract method. The existing getX() method is kept as a default delegating to it, annotated @deprecated(since = "4.1.0", forRemoval = true). Interfaces migrated: Artifact, ArtifactCoordinates, Dependency, DependencyCoordinates, DownloadedArtifact, Exclusion, Project, VersionConstraint, VersionRange. Fixes #13035
1 parent 37dead1 commit c0f25d3

27 files changed

Lines changed: 833 additions & 224 deletions

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

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
* <p>Each {@code Artifact} instance is basically an exact pointer to a file in a Maven repository.
3131
* {@code Artifact} instances are created when <dfn>resolving</dfn> {@link ArtifactCoordinates} instances.
32-
* Resolving is the process that selects a {@linkplain #getVersion() particular version}
32+
* Resolving is the process that selects a {@linkplain #version() particular version}
3333
* and downloads the artifact in the local repository. This operation returns a {@link DownloadedArtifact}.
3434
* </p>
3535
*
@@ -46,32 +46,61 @@ public interface Artifact {
4646
*/
4747
@Nonnull
4848
default String key() {
49-
String c = getClassifier();
50-
return getGroupId()
51-
+ ':'
52-
+ getArtifactId()
53-
+ ':'
54-
+ getExtension()
55-
+ (c.isEmpty() ? "" : ":" + c)
56-
+ ':'
57-
+ getVersion();
49+
String c = classifier();
50+
return groupId() + ':' + artifactId() + ':' + extension() + (c.isEmpty() ? "" : ":" + c) + ':' + version();
5851
}
5952

53+
/**
54+
* {@return the group identifier of the artifact}.
55+
*
56+
* @see ArtifactCoordinates#groupId()
57+
*/
58+
@Nonnull
59+
String groupId();
60+
6061
/**
6162
* {@return the group identifier of the artifact}.
6263
*
6364
* @see ArtifactCoordinates#getGroupId()
65+
* @deprecated Use {@link #groupId()} instead.
66+
*/
67+
@Deprecated(since = "4.1.0", forRemoval = true)
68+
@Nonnull
69+
default String getGroupId() {
70+
return groupId();
71+
}
72+
73+
/**
74+
* {@return the identifier of the artifact}.
75+
*
76+
* @see ArtifactCoordinates#artifactId()
6477
*/
6578
@Nonnull
66-
String getGroupId();
79+
String artifactId();
6780

6881
/**
6982
* {@return the identifier of the artifact}.
7083
*
7184
* @see ArtifactCoordinates#getArtifactId()
85+
* @deprecated Use {@link #artifactId()} instead.
7286
*/
87+
@Deprecated(since = "4.1.0", forRemoval = true)
7388
@Nonnull
74-
String getArtifactId();
89+
default String getArtifactId() {
90+
return artifactId();
91+
}
92+
93+
/**
94+
* {@return the version of the artifact}.
95+
* Contrarily to {@link ArtifactCoordinates},
96+
* each {@code Artifact} is associated to a specific version instead of a range of versions.
97+
* If the {@linkplain #baseVersion() base version} contains a meta-version such as {@code SNAPSHOT},
98+
* those keywords are replaced by, for example, the actual timestamp.
99+
*
100+
* @see ArtifactCoordinates#versionConstraint()
101+
*/
102+
@Nonnull
103+
Version version();
75104

76105
/**
77106
* {@return the version of the artifact}.
@@ -81,37 +110,82 @@ default String key() {
81110
* those keywords are replaced by, for example, the actual timestamp.
82111
*
83112
* @see ArtifactCoordinates#getVersionConstraint()
113+
* @deprecated Use {@link #version()} instead.
114+
*/
115+
@Deprecated(since = "4.1.0", forRemoval = true)
116+
@Nonnull
117+
default Version getVersion() {
118+
return version();
119+
}
120+
121+
/**
122+
* {@return the version or meta-version of the artifact}.
123+
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
124+
* Meta-versions are represented in a base version by their symbols (e.g., {@code SNAPSHOT}),
125+
* while they are replaced by, for example, the actual timestamp in the {@linkplain #version() version}.
84126
*/
85127
@Nonnull
86-
Version getVersion();
128+
Version baseVersion();
87129

88130
/**
89131
* {@return the version or meta-version of the artifact}.
90132
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
91133
* Meta-versions are represented in a base version by their symbols (e.g., {@code SNAPSHOT}),
92134
* while they are replaced by, for example, the actual timestamp in the {@linkplain #getVersion() version}.
135+
*
136+
* @deprecated Use {@link #baseVersion()} instead.
93137
*/
138+
@Deprecated(since = "4.1.0", forRemoval = true)
94139
@Nonnull
95-
Version getBaseVersion();
140+
default Version getBaseVersion() {
141+
return baseVersion();
142+
}
143+
144+
/**
145+
* Returns the classifier of the artifact.
146+
*
147+
* @return the classifier or an empty string if none, never {@code null}
148+
* @see ArtifactCoordinates#classifier()
149+
*/
150+
@Nonnull
151+
String classifier();
96152

97153
/**
98154
* Returns the classifier of the artifact.
99155
*
100156
* @return the classifier or an empty string if none, never {@code null}
101157
* @see ArtifactCoordinates#getClassifier()
158+
* @deprecated Use {@link #classifier()} instead.
159+
*/
160+
@Deprecated(since = "4.1.0", forRemoval = true)
161+
@Nonnull
162+
default String getClassifier() {
163+
return classifier();
164+
}
165+
166+
/**
167+
* Returns the file extension of the artifact.
168+
* The dot separator is <em>not</em> included in the returned string.
169+
*
170+
* @return the file extension or an empty string if none, never {@code null}
171+
* @see ArtifactCoordinates#extension()
102172
*/
103173
@Nonnull
104-
String getClassifier();
174+
String extension();
105175

106176
/**
107177
* Returns the file extension of the artifact.
108178
* The dot separator is <em>not</em> included in the returned string.
109179
*
110180
* @return the file extension or an empty string if none, never {@code null}
111181
* @see ArtifactCoordinates#getExtension()
182+
* @deprecated Use {@link #extension()} instead.
112183
*/
184+
@Deprecated(since = "4.1.0", forRemoval = true)
113185
@Nonnull
114-
String getExtension();
186+
default String getExtension() {
187+
return extension();
188+
}
115189

116190
/**
117191
* Determines whether this artifact uses a snapshot version.

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

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,74 @@ public interface ArtifactCoordinates {
3636
* {@return the group identifier of the artifact}.
3737
*/
3838
@Nonnull
39-
String getGroupId();
39+
String groupId();
40+
41+
/**
42+
* {@return the group identifier of the artifact}.
43+
*
44+
* @deprecated Use {@link #groupId()} instead.
45+
*/
46+
@Deprecated(since = "4.1.0", forRemoval = true)
47+
@Nonnull
48+
default String getGroupId() {
49+
return groupId();
50+
}
51+
52+
/**
53+
* {@return the identifier of the artifact}.
54+
*/
55+
@Nonnull
56+
String artifactId();
4057

4158
/**
4259
* {@return the identifier of the artifact}.
60+
*
61+
* @deprecated Use {@link #artifactId()} instead.
4362
*/
63+
@Deprecated(since = "4.1.0", forRemoval = true)
4464
@Nonnull
45-
String getArtifactId();
65+
default String getArtifactId() {
66+
return artifactId();
67+
}
4668

4769
/**
4870
* Returns the classifier of the artifact.
4971
*
5072
* @return the classifier or an empty string if none, never {@code null}
5173
*/
5274
@Nonnull
53-
String getClassifier();
75+
String classifier();
76+
77+
/**
78+
* Returns the classifier of the artifact.
79+
*
80+
* @return the classifier or an empty string if none, never {@code null}
81+
* @deprecated Use {@link #classifier()} instead.
82+
*/
83+
@Deprecated(since = "4.1.0", forRemoval = true)
84+
@Nonnull
85+
default String getClassifier() {
86+
return classifier();
87+
}
88+
89+
/**
90+
* {@return the specific version, range of versions, or meta-version of the artifact}.
91+
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
92+
*/
93+
@Nonnull
94+
VersionConstraint versionConstraint();
5495

5596
/**
5697
* {@return the specific version, range of versions, or meta-version of the artifact}.
5798
* A meta-version is a version suffixed with the {@code SNAPSHOT} keyword.
99+
*
100+
* @deprecated Use {@link #versionConstraint()} instead.
58101
*/
102+
@Deprecated(since = "4.1.0", forRemoval = true)
59103
@Nonnull
60-
VersionConstraint getVersionConstraint();
104+
default VersionConstraint getVersionConstraint() {
105+
return versionConstraint();
106+
}
61107

62108
/**
63109
* Returns the file extension of the artifact.
@@ -66,7 +112,20 @@ public interface ArtifactCoordinates {
66112
* @return the file extension or an empty string if none, never {@code null}
67113
*/
68114
@Nonnull
69-
String getExtension();
115+
String extension();
116+
117+
/**
118+
* Returns the file extension of the artifact.
119+
* The dot separator is <em>not</em> included in the returned string.
120+
*
121+
* @return the file extension or an empty string if none, never {@code null}
122+
* @deprecated Use {@link #extension()} instead.
123+
*/
124+
@Deprecated(since = "4.1.0", forRemoval = true)
125+
@Nonnull
126+
default String getExtension() {
127+
return extension();
128+
}
70129

71130
/**
72131
* {@return a unique string identifying this artifact}.
@@ -78,14 +137,14 @@ public interface ArtifactCoordinates {
78137
*/
79138
@Nonnull
80139
default String getId() {
81-
String c = getClassifier();
82-
return getGroupId()
140+
String c = classifier();
141+
return groupId()
83142
+ ':'
84-
+ getArtifactId()
143+
+ artifactId()
85144
+ ':'
86-
+ getExtension()
145+
+ extension()
87146
+ (c.isEmpty() ? "" : ":" + c)
88147
+ ':'
89-
+ getVersionConstraint();
148+
+ versionConstraint();
90149
}
91150
}

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,61 @@
3535
@Experimental
3636
@Immutable
3737
public interface Dependency extends Artifact {
38+
/**
39+
* {@return the type of the dependency}.
40+
* A dependency can be a <abbr>JAR</abbr> file,
41+
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module path,
42+
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
43+
*
44+
* @see DependencyCoordinates#type()
45+
*/
46+
@Nonnull
47+
Type type();
48+
3849
/**
3950
* {@return the type of the dependency}.
4051
* A dependency can be a <abbr>JAR</abbr> file,
4152
* a modular-<abbr>JAR</abbr> if it is intended to be placed on the module path,
4253
* a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
4354
*
4455
* @see DependencyCoordinates#getType()
56+
* @deprecated Use {@link #type()} instead.
57+
*/
58+
@Deprecated(since = "4.1.0", forRemoval = true)
59+
@Nonnull
60+
default Type getType() {
61+
return type();
62+
}
63+
64+
/**
65+
* {@return the time at which the dependency will be used}.
66+
* It may be, for example, at compile time only, at run time or at test time.
67+
*
68+
* @see DependencyCoordinates#scope()
4569
*/
4670
@Nonnull
47-
Type getType();
71+
DependencyScope scope();
4872

4973
/**
5074
* {@return the time at which the dependency will be used}.
5175
* It may be, for example, at compile time only, at run time or at test time.
5276
*
5377
* @see DependencyCoordinates#getScope()
78+
* @deprecated Use {@link #scope()} instead.
5479
*/
80+
@Deprecated(since = "4.1.0", forRemoval = true)
5581
@Nonnull
56-
DependencyScope getScope();
82+
default DependencyScope getScope() {
83+
return scope();
84+
}
5785

5886
/**
5987
* Returns whether the dependency is optional or mandatory.
6088
* Unlike {@link DependencyCoordinates}, the obligation of a {@code Dependency} is always present.
6189
* The value is computed during the dependencies collection phase.
6290
*
6391
* @return {@code true} if the dependency is optional, or {@code false} if mandatory
64-
* @see DependencyCoordinates#getOptional()
92+
* @see DependencyCoordinates#optional()
6593
*/
6694
boolean isOptional();
6795

0 commit comments

Comments
 (0)