This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new c0b9106121 [MNG-8673] SourceRoot includes and excludes should be String (#2232) c0b9106121 is described below commit c0b9106121a58f7c84e04e53d8e9c6044ef9fbb0 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Sun Apr 13 21:00:20 2025 +0100 [MNG-8673] SourceRoot includes and excludes should be String (#2232) --- .../main/java/org/apache/maven/api/SourceRoot.java | 12 +++-- .../org/apache/maven/project/MavenProject.java | 4 +- .../org/apache/maven/impl/DefaultSourceRoot.java | 60 +++++----------------- 3 files changed, 24 insertions(+), 52 deletions(-) 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 0b77dbcec5..8db3be1c28 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. + * + * <p> * 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<PathMatcher> includes() { + default List<String> includes() { return List.of(); } @@ -59,7 +65,7 @@ default List<PathMatcher> includes() { * The exclusions are applied after the inclusions. * The default implementation returns an empty list. */ - default List<PathMatcher> excludes() { + default List<String> 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 5e7e48059f..758b9936e8 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 cc24ee6089..0c5f9e54e3 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<PathMatcher> includes; + private final List<String> includes; - private final List<PathMatcher> excludes; + private final List<String> 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<PathMatcher> includes, - List<PathMatcher> excludes) { + List<String> includes, + List<String> 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<PathMatcher> matchers(FileSystem fs, List<String> 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<PathMatcher> includes() { + public List<String> includes() { return includes; } @@ -230,7 +196,7 @@ public List<PathMatcher> includes() { */ @Override @SuppressWarnings("ReturnOfCollectionOrArrayField") // Safe because unmodifiable - public List<PathMatcher> excludes() { + public List<String> excludes() { return excludes; }