|
50 | 50 | import java.util.List;
|
51 | 51 | import java.util.function.Predicate;
|
52 | 52 | import java.util.regex.Pattern;
|
| 53 | +import java.util.regex.PatternSyntaxException; |
53 | 54 |
|
54 | 55 | import com.oracle.truffle.api.CompilerDirectives;
|
55 | 56 | import com.oracle.truffle.api.InternalResource;
|
@@ -146,21 +147,33 @@ private static class ResourcesFilter implements Predicate<Path> {
|
146 | 147 | private final boolean log;
|
147 | 148 | private final Pattern includePattern;
|
148 | 149 | private final Pattern excludePattern;
|
149 |
| - private final List<String> excluded; |
150 | 150 | private final String exclude;
|
151 | 151 | private final String include;
|
152 |
| - private final ArrayList<String> included; |
| 152 | + private final List<String> excluded; |
| 153 | + private final List<String> included; |
| 154 | + private static final String INCLUDE_PROP = "org.graalvm.python.resources.include"; |
| 155 | + private static final String EXCLUDE_PROP = "org.graalvm.python.resources.exclude"; |
| 156 | + |
| 157 | + private static final String LOG_PROP = "org.graalvm.python.resources.exclude"; |
153 | 158 |
|
154 | 159 | private ResourcesFilter() {
|
155 |
| - include = getProperty("org.graalvm.python.resources.include"); |
156 |
| - exclude = getProperty("org.graalvm.python.resources.exclude"); |
157 |
| - log = Boolean.parseBoolean(getProperty("org.graalvm.python.resources.log")); |
158 |
| - includePattern = include != null ? Pattern.compile(include) : null; |
159 |
| - excludePattern = exclude != null ? Pattern.compile(exclude) : null; |
| 160 | + include = getProperty(INCLUDE_PROP); |
| 161 | + exclude = getProperty(EXCLUDE_PROP); |
| 162 | + log = Boolean.parseBoolean(getProperty(LOG_PROP)); |
| 163 | + includePattern = include != null ? compile(include, INCLUDE_PROP) : null; |
| 164 | + excludePattern = exclude != null ? compile(exclude, EXCLUDE_PROP) : null; |
160 | 165 | included = log ? new ArrayList<>() : null;
|
161 | 166 | excluded = log ? new ArrayList<>() : null;
|
162 | 167 | }
|
163 | 168 |
|
| 169 | + private static Pattern compile(String re, String property) { |
| 170 | + try { |
| 171 | + return Pattern.compile(re); |
| 172 | + } catch (PatternSyntaxException pse) { |
| 173 | + throw new IllegalArgumentException("could not compile regex pattern '" + re + "' provided by system property '" + property + "'", pse); |
| 174 | + } |
| 175 | + } |
| 176 | + |
164 | 177 | @Override
|
165 | 178 | public boolean test(Path path) {
|
166 | 179 | String absolutePath = path.toAbsolutePath().toString();
|
|
0 commit comments