1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.impl;
20
21 import java.nio.file.Path;
22 import java.nio.file.PathMatcher;
23 import java.util.Collection;
24 import java.util.Objects;
25
26 import org.apache.maven.api.annotations.Nonnull;
27 import org.apache.maven.api.di.Named;
28 import org.apache.maven.api.di.Singleton;
29 import org.apache.maven.api.services.PathMatcherFactory;
30
31 import static java.util.Objects.requireNonNull;
32
33
34
35
36
37
38
39
40
41
42 @Named
43 @Singleton
44 public class DefaultPathMatcherFactory implements PathMatcherFactory {
45
46 @Nonnull
47 @Override
48 public PathMatcher createPathMatcher(
49 @Nonnull Path baseDirectory,
50 Collection<String> includes,
51 Collection<String> excludes,
52 boolean useDefaultExcludes) {
53 requireNonNull(baseDirectory, "baseDirectory cannot be null");
54
55 return PathSelector.of(baseDirectory, includes, excludes, useDefaultExcludes);
56 }
57
58 @Nonnull
59 @Override
60 public PathMatcher createExcludeOnlyMatcher(
61 @Nonnull Path baseDirectory, Collection<String> excludes, boolean useDefaultExcludes) {
62 return createPathMatcher(baseDirectory, null, excludes, useDefaultExcludes);
63 }
64
65 @Nonnull
66 @Override
67 public PathMatcher deriveDirectoryMatcher(@Nonnull PathMatcher fileMatcher) {
68 if (Objects.requireNonNull(fileMatcher) instanceof PathSelector selector) {
69 if (selector.canFilterDirectories()) {
70 return selector::couldHoldSelected;
71 }
72 }
73 return PathSelector.INCLUDES_ALL;
74 }
75
76 @Nonnull
77 @Override
78 public PathMatcher includesAll() {
79 return PathSelector.INCLUDES_ALL;
80 }
81 }