Skip to content

Commit 7000a3c

Browse files
committed
Rename getSourceRoots(scope, language) as getEnabledSourceRoot and returns only enabled sources.
1 parent 36bd9d6 commit 7000a3c

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void attachArtifact(Project project, ProducedArtifact artifact, Path path
130130
@Override
131131
public List<Path> getCompileSourceRoots(Project project, ProjectScope scope) {
132132
MavenProject prj = getMavenProject(nonNull(project, "project"));
133-
return prj.getSourceRoots(scope, Language.JAVA_FAMILY)
133+
return prj.getEnabledSourceRoots(scope, Language.JAVA_FAMILY)
134134
.map(SourceRoot::directory)
135135
.toList();
136136
}

impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.Writer;
2424
import java.nio.file.Path;
2525
import java.util.ArrayList;
26+
import java.util.Collection;
2627
import java.util.Collections;
2728
import java.util.HashMap;
2829
import java.util.LinkedHashMap;
@@ -352,6 +353,8 @@ public DependencyManagement getDependencyManagement() {
352353
* @throws IllegalArgumentException if a source exists for the given language, scope and directory
353354
* but with different values for the other properties.
354355
*
356+
* @see #getSourceRoots()
357+
*
355358
* @since 4.0.0
356359
*/
357360
public void addSourceRoot(SourceRoot source) {
@@ -372,6 +375,8 @@ public void addSourceRoot(SourceRoot source) {
372375
* @param language language of the files contained in the directory to add
373376
* @param directory the directory to add if not already present in the source
374377
*
378+
* @see #getEnabledSourceRoots(ProjectScope, Language)
379+
*
375380
* @since 4.0.0
376381
*/
377382
public void addSourceRoot(ProjectScope scope, Language language, Path directory) {
@@ -420,17 +425,29 @@ public void addTestCompileSourceRoot(String path) {
420425
}
421426

422427
/**
423-
* {@return all sources that provide files in the given language for the given scope}.
424-
* If the given scope is {@code null}, then this method returns the sources for all scopes.
425-
* If the given language is {@code null}, then this method returns the sources for all languages.
428+
* {@return all source root directories, including the disabled ones, for all languages and scopes}.
429+
* The returned collection is unmodifiable.
430+
*
431+
* @see #addSourceRoot(SourceRoot)
432+
*/
433+
public Collection<SourceRoot> getSourceRoots() {
434+
return Collections.unmodifiableCollection(sources.values());
435+
}
436+
437+
/**
438+
* {@return all enabled sources that provide files in the given language for the given scope}.
439+
* If the given scope is {@code null}, then this method returns the enabled sources for all scopes.
440+
* If the given language is {@code null}, then this method returns the enabled sources for all languages.
426441
*
427442
* @param scope the scope of the sources to return, or {@code null} for all scopes
428443
* @param language the language of the sources to return, or {@code null} for all languages
429444
*
445+
* @see #addSourceRoot(ProjectScope, Language, Path)
446+
*
430447
* @since 4.0.0
431448
*/
432-
public Stream<SourceRoot> getSourceRoots(ProjectScope scope, Language language) {
433-
Stream<SourceRoot> s = sources.values().stream();
449+
public Stream<SourceRoot> getEnabledSourceRoots(ProjectScope scope, Language language) {
450+
Stream<SourceRoot> s = sources.values().stream().filter(SourceRoot::enabled);
434451
if (scope != null) {
435452
s = s.filter((source) -> scope.equals(source.scope()));
436453
}
@@ -447,21 +464,21 @@ public Stream<SourceRoot> getSourceRoots(ProjectScope scope, Language language)
447464
*/
448465
@Deprecated
449466
private List<String> getSourceRootDirs(ProjectScope scope, Language language) {
450-
return getSourceRoots(scope, language)
467+
return getEnabledSourceRoots(scope, language)
451468
.map((source) -> source.directory().toString())
452469
.toList();
453470
}
454471

455472
/**
456-
* @deprecated Replaced by {@code getSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY)}.
473+
* @deprecated Replaced by {@code getEnabledSourceRoots(ProjectScope.MAIN, Language.JAVA_FAMILY)}.
457474
*/
458475
@Deprecated(since = "4.0.0")
459476
public List<String> getCompileSourceRoots() {
460477
return getSourceRootDirs(ProjectScope.MAIN, Language.JAVA_FAMILY);
461478
}
462479

463480
/**
464-
* @deprecated Replaced by {@code getSourceRoots(ProjectScope.TEST, Language.JAVA_FAMILY)}.
481+
* @deprecated Replaced by {@code getEnabledSourceRoots(ProjectScope.TEST, Language.JAVA_FAMILY)}.
465482
*/
466483
@Deprecated(since = "4.0.0")
467484
public List<String> getTestCompileSourceRoots() {
@@ -747,15 +764,15 @@ public Build getBuild() {
747764
}
748765

749766
/**
750-
* @deprecated Replaced by {@code getSourceRoots(ProjectScope.MAIN, Language.RESOURCES)}.
767+
* @deprecated Replaced by {@code getEnabledSourceRoots(ProjectScope.MAIN, Language.RESOURCES)}.
751768
*/
752769
@Deprecated(since = "4.0.0")
753770
public List<Resource> getResources() {
754771
return getBuild().getResources();
755772
}
756773

757774
/**
758-
* @deprecated Replaced by {@code getSourceRoots(ProjectScope.TEST, Language.RESOURCES)}.
775+
* @deprecated Replaced by {@code getEnabledSourceRoots(ProjectScope.TEST, Language.RESOURCES)}.
759776
*/
760777
@Deprecated(since = "4.0.0")
761778
public List<Resource> getTestResources() {

0 commit comments

Comments
 (0)