Skip to content

Commit c0b9106

Browse files
authored
[MNG-8673] SourceRoot includes and excludes should be String (#2232)
1 parent 1da418c commit c0b9106

File tree

3 files changed

+24
-52
lines changed

3 files changed

+24
-52
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.api;
2020

2121
import java.nio.file.Path;
22-
import java.nio.file.PathMatcher;
2322
import java.util.List;
2423
import java.util.Optional;
2524

@@ -47,10 +46,17 @@ default Path directory() {
4746

4847
/**
4948
* {@return the list of pattern matchers for the files to include}.
49+
* The path separator is {@code /} on all platforms, including Windows.
50+
* The patterns are used to match paths relative to the {@code directory}.
51+
* The prefix before the {@code :} character, if present, is the syntax.
52+
* If no syntax is specified, the default is a Maven-specific variation
53+
* of the {@code "glob"} pattern.
54+
*
55+
* <p>
5056
* The default implementation returns an empty list, which means to apply a language-dependent pattern.
5157
* For example, for the Java language, the pattern includes all files with the {@code .java} suffix.
5258
*/
53-
default List<PathMatcher> includes() {
59+
default List<String> includes() {
5460
return List.of();
5561
}
5662

@@ -59,7 +65,7 @@ default List<PathMatcher> includes() {
5965
* The exclusions are applied after the inclusions.
6066
* The default implementation returns an empty list.
6167
*/
62-
default List<PathMatcher> excludes() {
68+
default List<String> excludes() {
6369
return List.of();
6470
}
6571

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,8 @@ public boolean add(Resource resource) {
822822
private static Resource toResource(SourceRoot sourceRoot) {
823823
return new Resource(org.apache.maven.api.model.Resource.newBuilder()
824824
.directory(sourceRoot.directory().toString())
825-
.includes(sourceRoot.includes().stream().map(Object::toString).toList())
826-
.excludes(sourceRoot.excludes().stream().map(Object::toString).toList())
825+
.includes(sourceRoot.includes())
826+
.excludes(sourceRoot.excludes())
827827
.filtering(Boolean.toString(sourceRoot.stringFiltering()))
828828
.build());
829829
}

impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
*/
1919
package org.apache.maven.impl;
2020

21-
import java.nio.file.FileSystem;
2221
import java.nio.file.Path;
23-
import java.nio.file.PathMatcher;
2422
import java.util.List;
2523
import java.util.Objects;
2624
import java.util.Optional;
@@ -39,9 +37,9 @@
3937
public final class DefaultSourceRoot implements SourceRoot {
4038
private final Path directory;
4139

42-
private final List<PathMatcher> includes;
40+
private final List<String> includes;
4341

44-
private final List<PathMatcher> excludes;
42+
private final List<String> excludes;
4543

4644
private final ProjectScope scope;
4745

@@ -65,9 +63,8 @@ public final class DefaultSourceRoot implements SourceRoot {
6563
* @param source a source element from the model
6664
*/
6765
public DefaultSourceRoot(final Session session, final Path baseDir, final Source source) {
68-
FileSystem fs = baseDir.getFileSystem();
69-
includes = matchers(fs, source.getIncludes());
70-
excludes = matchers(fs, source.getExcludes());
66+
includes = source.getIncludes();
67+
excludes = source.getExcludes();
7168
stringFiltering = source.isStringFiltering();
7269
enabled = source.isEnabled();
7370
moduleName = nonBlank(source.getModule());
@@ -106,9 +103,8 @@ public DefaultSourceRoot(final Path baseDir, ProjectScope scope, Resource resour
106103
throw new IllegalArgumentException("Source declaration without directory value.");
107104
}
108105
directory = baseDir.resolve(value).normalize();
109-
FileSystem fs = directory.getFileSystem();
110-
includes = matchers(fs, resource.getIncludes());
111-
excludes = matchers(fs, resource.getExcludes());
106+
includes = resource.getIncludes();
107+
excludes = resource.getExcludes();
112108
stringFiltering = Boolean.parseBoolean(resource.getFiltering());
113109
enabled = true;
114110
moduleName = null;
@@ -144,13 +140,15 @@ public DefaultSourceRoot(final ProjectScope scope, final Language language, fina
144140
* @param scope scope of source code (main or test)
145141
* @param language language of the source code
146142
* @param directory directory of the source code
147-
*/
143+
* @param includes list of patterns for the files to include, or {@code null} if unspecified
144+
* @param excludes list of patterns for the files to exclude, or {@code null} if unspecified
145+
* */
148146
public DefaultSourceRoot(
149147
final ProjectScope scope,
150148
final Language language,
151149
final Path directory,
152-
List<PathMatcher> includes,
153-
List<PathMatcher> excludes) {
150+
List<String> includes,
151+
List<String> excludes) {
154152
this.scope = Objects.requireNonNull(scope);
155153
this.language = language;
156154
this.directory = Objects.requireNonNull(directory);
@@ -176,38 +174,6 @@ private static String nonBlank(String value) {
176174
return value;
177175
}
178176

179-
/**
180-
* Creates a path matcher for each pattern.
181-
* The path separator is {@code /} on all platforms, including Windows.
182-
* The prefix before the {@code :} character is the syntax.
183-
* If no syntax is specified, {@code "glob"} is assumed.
184-
*
185-
* @param fs the file system of the root directory
186-
* @param patterns the patterns for which to create path matcher
187-
* @return a path matcher for each pattern
188-
*/
189-
private static List<PathMatcher> matchers(FileSystem fs, List<String> patterns) {
190-
final var matchers = new PathMatcher[patterns.size()];
191-
for (int i = 0; i < matchers.length; i++) {
192-
String rawPattern = patterns.get(i);
193-
String pattern = rawPattern.contains(":") ? rawPattern : "glob:" + rawPattern;
194-
matchers[i] = new PathMatcher() {
195-
final PathMatcher delegate = fs.getPathMatcher(pattern);
196-
197-
@Override
198-
public boolean matches(Path path) {
199-
return delegate.matches(path);
200-
}
201-
202-
@Override
203-
public String toString() {
204-
return rawPattern;
205-
}
206-
};
207-
}
208-
return List.of(matchers);
209-
}
210-
211177
/**
212178
* {@return the root directory where the sources are stored}.
213179
*/
@@ -221,7 +187,7 @@ public Path directory() {
221187
*/
222188
@Override
223189
@SuppressWarnings("ReturnOfCollectionOrArrayField") // Safe because unmodifiable
224-
public List<PathMatcher> includes() {
190+
public List<String> includes() {
225191
return includes;
226192
}
227193

@@ -230,7 +196,7 @@ public List<PathMatcher> includes() {
230196
*/
231197
@Override
232198
@SuppressWarnings("ReturnOfCollectionOrArrayField") // Safe because unmodifiable
233-
public List<PathMatcher> excludes() {
199+
public List<String> excludes() {
234200
return excludes;
235201
}
236202

0 commit comments

Comments
 (0)