Skip to content

Commit 9af4ac9

Browse files
committed
Move the recently added Project methods into ProjectManager.
1 parent 4552207 commit 9af4ac9

File tree

4 files changed

+52
-48
lines changed

4 files changed

+52
-48
lines changed

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
package org.apache.maven.api;
2020

2121
import java.nio.file.Path;
22-
import java.util.Collection;
2322
import java.util.List;
2423
import java.util.Optional;
25-
import java.util.stream.Stream;
2624

2725
import org.apache.maven.api.annotations.Experimental;
2826
import org.apache.maven.api.annotations.Nonnull;
@@ -239,32 +237,4 @@ default String getId() {
239237
*/
240238
@Nonnull
241239
Optional<Project> getParent();
242-
243-
/**
244-
* {@return all source root directories}, including the disabled ones, for all languages and scopes.
245-
* For listing only the {@linkplain SourceRoot#enabled() enabled} source roots,
246-
* the following code can be used:
247-
*
248-
* <pre>{@literal
249-
* List<SourceRoot> enabledRoots = project.getSourceRoots()
250-
* .stream().filter(SourceRoot::enabled).toList();
251-
* }</pre>
252-
*
253-
* The iteration order is the order in which the sources are declared in the POM file.
254-
*/
255-
@Nonnull
256-
Collection<SourceRoot> getSourceRoots();
257-
258-
/**
259-
* {@return all enabled sources that provide files in the given language for the given scope}.
260-
* If the given scope is {@code null}, then this method returns the enabled sources for all scopes.
261-
* If the given language is {@code null}, then this method returns the enabled sources for all languages.
262-
* An arbitrary number of source roots may exist for the same scope and language.
263-
* It may be, for example, the case of a multi-versions project.
264-
* The iteration order is the order in which the sources are declared in the POM file.
265-
*
266-
* @param scope the scope of the sources to return, or {@code null} for all scopes
267-
* @param language the language of the sources to return, or {@code null} for all languages
268-
*/
269-
Stream<SourceRoot> getEnabledSourceRoots(ProjectScope scope, Language language);
270240
}

api/maven-api-core/src/main/java/org/apache/maven/api/services/ProjectManager.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Optional;
26+
import java.util.stream.Stream;
2627

2728
import org.apache.maven.api.Artifact;
2829
import org.apache.maven.api.Language;
@@ -103,6 +104,7 @@ default void attachArtifact(@Nonnull Session session, @Nonnull Project project,
103104
* @param type the type of the artifact (e.g., "jar", "war", "sources")
104105
* @param path the path to the artifact file
105106
* @throws IllegalArgumentException if the session, project, type or path is null
107+
*
106108
* @see org.apache.maven.api.Type
107109
*/
108110
default void attachArtifact(
@@ -123,6 +125,37 @@ default void attachArtifact(
123125
*/
124126
void attachArtifact(@Nonnull Project project, @Nonnull ProducedArtifact artifact, @Nonnull Path path);
125127

128+
/**
129+
* {@return all source root directories}, including the disabled ones, for all languages and scopes.
130+
* For listing only the {@linkplain SourceRoot#enabled() enabled} source roots,
131+
* the following code can be used:
132+
*
133+
* <pre>{@literal
134+
* List<SourceRoot> enabledRoots = project.getSourceRoots()
135+
* .stream().filter(SourceRoot::enabled).toList();
136+
* }</pre>
137+
*
138+
* The iteration order is the order in which the sources are declared in the POM file.
139+
*
140+
* @param project the project for which to get the source roots
141+
*/
142+
@Nonnull
143+
Collection<SourceRoot> getSourceRoots(@Nonnull Project project);
144+
145+
/**
146+
* {@return all enabled sources that provide files in the given language for the given scope}.
147+
* If the given scope is {@code null}, then this method returns the enabled sources for all scopes.
148+
* If the given language is {@code null}, then this method returns the enabled sources for all languages.
149+
* An arbitrary number of source roots may exist for the same scope and language.
150+
* It may be, for example, the case of a multi-versions project.
151+
* The iteration order is the order in which the sources are declared in the POM file.
152+
*
153+
* @param project the project for which to get the enabled source roots
154+
* @param scope the scope of the sources to return, or {@code null} for all scopes
155+
* @param language the language of the sources to return, or {@code null} for all languages
156+
*/
157+
Stream<SourceRoot> getEnabledSourceRoots(@Nonnull Project project, ProjectScope scope, Language language);
158+
126159
/**
127160
* Adds the given source to the given project.
128161
* If a source already exists for the given scope, language and directory,
@@ -133,7 +166,7 @@ default void attachArtifact(
133166
* @param source the source to add
134167
* @throws IllegalArgumentException if this project manager rejects the given source because of conflict
135168
*
136-
* @see Project#getSourceRoots()
169+
* @see #getSourceRoots(Project)
137170
*/
138171
void addSourceRoot(@Nonnull Project project, @Nonnull SourceRoot source);
139172

@@ -150,7 +183,7 @@ default void attachArtifact(
150183
* @param language language of the files contained in the directory to add
151184
* @param directory the directory to add if not already present in the source
152185
*
153-
* @see Project#getEnabledSourceRoots(ProjectScope, Language)
186+
* @see #getEnabledSourceRoots(Project, ProjectScope, Language)
154187
*/
155188
void addSourceRoot(
156189
@Nonnull Project project, @Nonnull ProjectScope scope, @Nonnull Language language, @Nonnull Path directory);
@@ -174,6 +207,8 @@ void addSourceRoot(
174207
/**
175208
* {@return an immutable map of the project properties}.
176209
*
210+
* @param project the project for which to get the properties
211+
*
177212
* @see #setProperty(Project, String, String)
178213
*/
179214
@Nonnull

impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@
2424
import java.util.Collections;
2525
import java.util.List;
2626
import java.util.Optional;
27-
import java.util.stream.Stream;
2827

2928
import org.apache.maven.RepositoryUtils;
3029
import org.apache.maven.api.DependencyCoordinates;
3130
import org.apache.maven.api.DependencyScope;
3231
import org.apache.maven.api.Exclusion;
33-
import org.apache.maven.api.Language;
3432
import org.apache.maven.api.Packaging;
3533
import org.apache.maven.api.ProducedArtifact;
3634
import org.apache.maven.api.Project;
37-
import org.apache.maven.api.ProjectScope;
38-
import org.apache.maven.api.SourceRoot;
3935
import org.apache.maven.api.Type;
4036
import org.apache.maven.api.VersionConstraint;
4137
import org.apache.maven.api.annotations.Nonnull;
@@ -169,18 +165,6 @@ public Optional<Project> getParent() {
169165
return Optional.ofNullable(session.getProject(parent));
170166
}
171167

172-
@Nonnull
173-
@Override
174-
public Collection<SourceRoot> getSourceRoots() {
175-
return project.getSourceRoots();
176-
}
177-
178-
@Nonnull
179-
@Override
180-
public Stream<SourceRoot> getEnabledSourceRoots(ProjectScope scope, Language language) {
181-
return project.getEnabledSourceRoots(scope, language);
182-
}
183-
184168
@Nonnull
185169
private DependencyCoordinates toDependency(org.apache.maven.api.model.Dependency dependency) {
186170
return new DependencyCoordinates() {

impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Objects;
3131
import java.util.Optional;
3232
import java.util.Properties;
33+
import java.util.stream.Stream;
3334

3435
import org.apache.maven.RepositoryUtils;
3536
import org.apache.maven.api.Language;
@@ -126,6 +127,20 @@ public void attachArtifact(Project project, ProducedArtifact artifact, Path path
126127
artifactManager.setPath(artifact, path);
127128
}
128129

130+
@Nonnull
131+
@Override
132+
public Collection<SourceRoot> getSourceRoots(Project project) {
133+
MavenProject prj = getMavenProject(nonNull(project, "project"));
134+
return prj.getSourceRoots();
135+
}
136+
137+
@Nonnull
138+
@Override
139+
public Stream<SourceRoot> getEnabledSourceRoots(Project project, ProjectScope scope, Language language) {
140+
MavenProject prj = getMavenProject(nonNull(project, "project"));
141+
return prj.getEnabledSourceRoots(scope, language);
142+
}
143+
129144
@Override
130145
public void addSourceRoot(Project project, SourceRoot source) {
131146
MavenProject prj = getMavenProject(nonNull(project, "project"));

0 commit comments

Comments
 (0)