diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java b/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
index 0b77dbcec513..8db3be1c2863 100644
--- a/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
+++ b/api/maven-api-core/src/main/java/org/apache/maven/api/SourceRoot.java
@@ -19,7 +19,6 @@
package org.apache.maven.api;
import java.nio.file.Path;
-import java.nio.file.PathMatcher;
import java.util.List;
import java.util.Optional;
@@ -47,10 +46,17 @@ default Path directory() {
/**
* {@return the list of pattern matchers for the files to include}.
+ * The path separator is {@code /} on all platforms, including Windows.
+ * The patterns are used to match paths relative to the {@code directory}.
+ * The prefix before the {@code :} character, if present, is the syntax.
+ * If no syntax is specified, the default is a Maven-specific variation
+ * of the {@code "glob"} pattern.
+ *
+ *
* The default implementation returns an empty list, which means to apply a language-dependent pattern.
* For example, for the Java language, the pattern includes all files with the {@code .java} suffix.
*/
- default List includes() {
+ default List includes() {
return List.of();
}
@@ -59,7 +65,7 @@ default List includes() {
* The exclusions are applied after the inclusions.
* The default implementation returns an empty list.
*/
- default List excludes() {
+ default List excludes() {
return List.of();
}
diff --git a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
index 5e7e48059fc3..758b9936e8c0 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
@@ -822,8 +822,8 @@ public boolean add(Resource resource) {
private static Resource toResource(SourceRoot sourceRoot) {
return new Resource(org.apache.maven.api.model.Resource.newBuilder()
.directory(sourceRoot.directory().toString())
- .includes(sourceRoot.includes().stream().map(Object::toString).toList())
- .excludes(sourceRoot.excludes().stream().map(Object::toString).toList())
+ .includes(sourceRoot.includes())
+ .excludes(sourceRoot.excludes())
.filtering(Boolean.toString(sourceRoot.stringFiltering()))
.build());
}
diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
index cc24ee6089d6..0c5f9e54e3ce 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java
@@ -18,9 +18,7 @@
*/
package org.apache.maven.impl;
-import java.nio.file.FileSystem;
import java.nio.file.Path;
-import java.nio.file.PathMatcher;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -39,9 +37,9 @@
public final class DefaultSourceRoot implements SourceRoot {
private final Path directory;
- private final List includes;
+ private final List includes;
- private final List excludes;
+ private final List excludes;
private final ProjectScope scope;
@@ -65,9 +63,8 @@ public final class DefaultSourceRoot implements SourceRoot {
* @param source a source element from the model
*/
public DefaultSourceRoot(final Session session, final Path baseDir, final Source source) {
- FileSystem fs = baseDir.getFileSystem();
- includes = matchers(fs, source.getIncludes());
- excludes = matchers(fs, source.getExcludes());
+ includes = source.getIncludes();
+ excludes = source.getExcludes();
stringFiltering = source.isStringFiltering();
enabled = source.isEnabled();
moduleName = nonBlank(source.getModule());
@@ -106,9 +103,8 @@ public DefaultSourceRoot(final Path baseDir, ProjectScope scope, Resource resour
throw new IllegalArgumentException("Source declaration without directory value.");
}
directory = baseDir.resolve(value).normalize();
- FileSystem fs = directory.getFileSystem();
- includes = matchers(fs, resource.getIncludes());
- excludes = matchers(fs, resource.getExcludes());
+ includes = resource.getIncludes();
+ excludes = resource.getExcludes();
stringFiltering = Boolean.parseBoolean(resource.getFiltering());
enabled = true;
moduleName = null;
@@ -144,13 +140,15 @@ public DefaultSourceRoot(final ProjectScope scope, final Language language, fina
* @param scope scope of source code (main or test)
* @param language language of the source code
* @param directory directory of the source code
- */
+ * @param includes list of patterns for the files to include, or {@code null} if unspecified
+ * @param excludes list of patterns for the files to exclude, or {@code null} if unspecified
+ * */
public DefaultSourceRoot(
final ProjectScope scope,
final Language language,
final Path directory,
- List includes,
- List excludes) {
+ List includes,
+ List excludes) {
this.scope = Objects.requireNonNull(scope);
this.language = language;
this.directory = Objects.requireNonNull(directory);
@@ -176,38 +174,6 @@ private static String nonBlank(String value) {
return value;
}
- /**
- * Creates a path matcher for each pattern.
- * The path separator is {@code /} on all platforms, including Windows.
- * The prefix before the {@code :} character is the syntax.
- * If no syntax is specified, {@code "glob"} is assumed.
- *
- * @param fs the file system of the root directory
- * @param patterns the patterns for which to create path matcher
- * @return a path matcher for each pattern
- */
- private static List matchers(FileSystem fs, List patterns) {
- final var matchers = new PathMatcher[patterns.size()];
- for (int i = 0; i < matchers.length; i++) {
- String rawPattern = patterns.get(i);
- String pattern = rawPattern.contains(":") ? rawPattern : "glob:" + rawPattern;
- matchers[i] = new PathMatcher() {
- final PathMatcher delegate = fs.getPathMatcher(pattern);
-
- @Override
- public boolean matches(Path path) {
- return delegate.matches(path);
- }
-
- @Override
- public String toString() {
- return rawPattern;
- }
- };
- }
- return List.of(matchers);
- }
-
/**
* {@return the root directory where the sources are stored}.
*/
@@ -221,7 +187,7 @@ public Path directory() {
*/
@Override
@SuppressWarnings("ReturnOfCollectionOrArrayField") // Safe because unmodifiable
- public List includes() {
+ public List includes() {
return includes;
}
@@ -230,7 +196,7 @@ public List includes() {
*/
@Override
@SuppressWarnings("ReturnOfCollectionOrArrayField") // Safe because unmodifiable
- public List excludes() {
+ public List excludes() {
return excludes;
}