Skip to content

Commit ea672ac

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

File tree

4 files changed

+49
-46
lines changed

4 files changed

+49
-46
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: 34 additions & 0 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;
@@ -123,6 +124,37 @@ default void attachArtifact(
123124
*/
124125
void attachArtifact(@Nonnull Project project, @Nonnull ProducedArtifact artifact, @Nonnull Path path);
125126

127+
/**
128+
* {@return all source root directories}, including the disabled ones, for all languages and scopes.
129+
* For listing only the {@linkplain SourceRoot#enabled() enabled} source roots,
130+
* the following code can be used:
131+
*
132+
* <pre>{@literal
133+
* List<SourceRoot> enabledRoots = project.getSourceRoots()
134+
* .stream().filter(SourceRoot::enabled).toList();
135+
* }</pre>
136+
*
137+
* The iteration order is the order in which the sources are declared in the POM file.
138+
*
139+
* @param project the project for which to get the source roots
140+
*/
141+
@Nonnull
142+
Collection<SourceRoot> getSourceRoots(@Nonnull Project project);
143+
144+
/**
145+
* {@return all enabled sources that provide files in the given language for the given scope}.
146+
* If the given scope is {@code null}, then this method returns the enabled sources for all scopes.
147+
* If the given language is {@code null}, then this method returns the enabled sources for all languages.
148+
* An arbitrary number of source roots may exist for the same scope and language.
149+
* It may be, for example, the case of a multi-versions project.
150+
* The iteration order is the order in which the sources are declared in the POM file.
151+
*
152+
* @param project the project for which to get the enabled source roots
153+
* @param scope the scope of the sources to return, or {@code null} for all scopes
154+
* @param language the language of the sources to return, or {@code null} for all languages
155+
*/
156+
Stream<SourceRoot> getEnabledSourceRoots(@Nonnull Project project, ProjectScope scope, Language language);
157+
126158
/**
127159
* Adds the given source to the given project.
128160
* If a source already exists for the given scope, language and directory,
@@ -174,6 +206,8 @@ void addSourceRoot(
174206
/**
175207
* {@return an immutable map of the project properties}.
176208
*
209+
* @param project the project for which to get the properties
210+
*
177211
* @see #setProperty(Project, String, String)
178212
*/
179213
@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)