Skip to content

Commit 7b4a4bf

Browse files
desruisseauxgnodet
andauthored
[MNG-8395] Redirect the <sourceDirectory> element to <Source> (#2061)
* Include the list of <Source> elements in the path translation. * Add a `SourceRoot` interface for the properties declared in the POM's `<Source>` element. The API use method names without `get` prefix in anticipation for possible use of records in the future. In the `MavenProject` class, the `compileSourceRoots`, `testCompileSourceRoots` and `scriptSourceRoots` fields are replaced by redirections to the new `sources` field with paths wrapped in `SourceRoot` objects. The getters and setters methods for the previous fields are deprecated. This commit contains other opportunistic deprecations on methods working with deprecated interfaces. In the POM file, the above-cited properties are ignored if a corresponding `<Source>` element exists. This rule exits because Maven sets default values to those fields, which can interfer with user's setting. * Deprecate POM elements that are replaced by <Source> elements. * Add @deprecated annotation on model elements flagged as @deprecated in the documentation. * Update `ProjectManager` API using `SourceRoot`: - Add `addSourceRoot(Project, …)` methods. - Add `getSourceRoots()` and `getEnabledSourceRoots(ProjectScope, Language)`. - Remove `get/addResource(Project, …)` methods. - Remove `get/addCompileSourceRoots(Project, …)` methods. --------- Co-authored-by: Guillaume Nodet <[email protected]>
1 parent 3347e91 commit 7b4a4bf

File tree

12 files changed

+885
-152
lines changed

12 files changed

+885
-152
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ public interface Language extends ExtensibleEnum {
4545
*/
4646
Language NONE = language("none");
4747

48+
/**
49+
* The "resources" language. This is used for files such as images to provide in the output.
50+
*/
51+
Language RESOURCES = language("resources");
52+
53+
/**
54+
* The "script" language. Provided for compatibility with Maven 3.
55+
*
56+
* @deprecated Use {@link #RESOURCES} instead.
57+
*/
58+
@Deprecated
59+
Language SCRIPT = language("script");
60+
4861
// TODO: this should be moved out from here to Java Support (builtin into core)
4962
Language JAVA_FAMILY = language("java");
5063
}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@
4949
public interface Project {
5050

5151
/**
52-
* Returns the project groupId.
52+
* {@return the project groupId}.
5353
*/
5454
@Nonnull
5555
String getGroupId();
5656

5757
/**
58-
* Returns the project artifactId.
58+
* {@return the project artifactId}.
5959
*/
6060
@Nonnull
6161
String getArtifactId();
6262

6363
/**
64-
* Returns the project version.
64+
* {@return the project version}.
6565
*/
6666
@Nonnull
6767
String getVersion();
6868

6969
/**
70-
* Returns the project packaging.
70+
* {@return the project packaging}.
7171
* <p>
7272
* Note: unlike in legacy code, logical checks against string representing packaging (returned by this method)
7373
* are NOT recommended (code like {@code "pom".equals(project.getPackaging)} must be avoided). Use method
@@ -79,7 +79,7 @@ public interface Project {
7979
Packaging getPackaging();
8080

8181
/**
82-
* Returns the project language. It is by default determined by {@link #getPackaging()}.
82+
* {@return the project language}. It is by default determined by {@link #getPackaging()}.
8383
*
8484
* @see #getPackaging()
8585
*/
@@ -89,7 +89,7 @@ default Language getLanguage() {
8989
}
9090

9191
/**
92-
* Returns the project POM artifact, which is the artifact of the POM of this project. Every project have a POM
92+
* {@return the project POM artifact}, which is the artifact of the POM of this project. Every project have a POM
9393
* artifact, even if the existence of backing POM file is NOT a requirement (i.e. for some transient projects).
9494
*
9595
* @see org.apache.maven.api.services.ArtifactManager#getPath(Artifact)
@@ -100,7 +100,7 @@ default ProducedArtifact getPomArtifact() {
100100
}
101101

102102
/**
103-
* Returns the project main artifact, which is the artifact produced by this project build, if applicable.
103+
* {@return the project main artifact}, which is the artifact produced by this project build, if applicable.
104104
* This artifact MAY be absent if the project is actually not producing any main artifact (i.e. "pom" packaging).
105105
*
106106
* @see #getPackaging()
@@ -113,7 +113,7 @@ default Optional<ProducedArtifact> getMainArtifact() {
113113
}
114114

115115
/**
116-
* Returns the project artifacts as immutable list. Elements are the project POM artifact and the artifact
116+
* {@return the project artifacts as immutable list}. Elements are the project POM artifact and the artifact
117117
* produced by this project build, if applicable. Hence, the returned list may have one or two elements
118118
* (never less than 1, never more than 2), depending on project packaging.
119119
* <p>
@@ -129,13 +129,15 @@ default Optional<ProducedArtifact> getMainArtifact() {
129129
List<ProducedArtifact> getArtifacts();
130130

131131
/**
132-
* Returns the project model.
132+
* {@return the project model}.
133133
*/
134134
@Nonnull
135135
Model getModel();
136136

137137
/**
138138
* Shorthand method.
139+
*
140+
* @return the build element of the project model
139141
*/
140142
@Nonnull
141143
default Build getBuild() {
@@ -170,19 +172,19 @@ default Build getBuild() {
170172
Path getBasedir();
171173

172174
/**
173-
* Returns the project direct dependencies (directly specified or inherited).
175+
* {@return the project direct dependencies (directly specified or inherited)}.
174176
*/
175177
@Nonnull
176178
List<DependencyCoordinates> getDependencies();
177179

178180
/**
179-
* Returns the project managed dependencies (directly specified or inherited).
181+
* {@return the project managed dependencies (directly specified or inherited)}.
180182
*/
181183
@Nonnull
182184
List<DependencyCoordinates> getManagedDependencies();
183185

184186
/**
185-
* Returns the project ID, usable as key.
187+
* {@return the project ID, usable as key}.
186188
*/
187189
@Nonnull
188190
default String getId() {
@@ -216,6 +218,7 @@ default String getId() {
216218
* Gets the root directory of the project, which is the parent directory
217219
* containing the {@code .mvn} directory or flagged with {@code root="true"}.
218220
*
221+
* @return the root directory of the project
219222
* @throws IllegalStateException if the root directory could not be found
220223
* @see Session#getRootDirectory()
221224
*/
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.nio.file.Path;
22+
import java.nio.file.PathMatcher;
23+
import java.util.List;
24+
import java.util.Optional;
25+
26+
/**
27+
* A root directory of source files.
28+
* The sources may be Java main classes, test classes, resources or anything else identified by the scope.
29+
*/
30+
public interface SourceRoot {
31+
/**
32+
* {@return the root directory where the sources are stored}.
33+
* The path is relative to the <abbr>POM</abbr> file.
34+
*/
35+
Path directory();
36+
37+
/**
38+
* {@return the list of pattern matchers for the files to include}.
39+
* The default implementation returns an empty list, which means to apply a language-dependent pattern.
40+
* For example, for the Java language, the pattern includes all files with the {@code .java} suffix.
41+
*/
42+
default List<PathMatcher> includes() {
43+
return List.of();
44+
}
45+
46+
/**
47+
* {@return the list of pattern matchers for the files to exclude}.
48+
* The exclusions are applied after the inclusions.
49+
* The default implementation returns an empty list.
50+
*/
51+
default List<PathMatcher> excludes() {
52+
return List.of();
53+
}
54+
55+
/**
56+
* {@return in which context the source files will be used}.
57+
* The default value is {@link ProjectScope#MAIN}.
58+
*/
59+
default ProjectScope scope() {
60+
return ProjectScope.MAIN;
61+
}
62+
63+
/**
64+
* {@return the language of the source files}.
65+
*/
66+
Language language();
67+
68+
/**
69+
* {@return the name of the Java module (or other language-specific module) which is built by the sources}.
70+
* The default value is empty.
71+
*/
72+
default Optional<String> module() {
73+
return Optional.empty();
74+
}
75+
76+
/**
77+
* {@return the version of the platform where the code will be executed}.
78+
* In a Java environment, this is the value of the {@code --release} compiler option.
79+
* The default value is empty.
80+
*/
81+
default Optional<Version> targetVersion() {
82+
return Optional.empty();
83+
}
84+
85+
/**
86+
* {@return an explicit target path, overriding the default value}.
87+
* When a target path is explicitly specified, the values of the {@link #module()} and {@link #targetVersion()}
88+
* elements are not used for inferring the path (they are still used as compiler options however).
89+
* It means that for scripts and resources, the files below the path specified by {@link #directory()}
90+
* are copied to the path specified by {@code targetPath()} with the exact same directory structure.
91+
*/
92+
default Optional<Path> targetPath() {
93+
return Optional.empty();
94+
}
95+
96+
/**
97+
* {@return whether resources are filtered to replace tokens with parameterized values}.
98+
* The default value is {@code false}.
99+
*/
100+
default boolean stringFiltering() {
101+
return false;
102+
}
103+
104+
/**
105+
* {@return whether the directory described by this source element should be included in the build}.
106+
* The default value is {@code true}.
107+
*/
108+
default boolean enabled() {
109+
return true;
110+
}
111+
}

0 commit comments

Comments
 (0)