use of com.google.re2j.PatternSyntaxException in project copybara by google.
the class Replace method create.
public static Replace create(Location location, String before, String after, Map<String, String> regexGroups, Glob paths, boolean firstOnly, boolean multiline, boolean repeatedGroups, List<String> patternsToIgnore, WorkflowOptions workflowOptions) throws EvalException {
Map<String, Pattern> parsedGroups = new HashMap<>();
for (Map.Entry<String, String> group : regexGroups.entrySet()) {
try {
parsedGroups.put(group.getKey(), Pattern.compile(group.getValue()));
} catch (PatternSyntaxException e) {
throw new EvalException(location, "'regex_groups' includes invalid regex for key " + group.getKey() + ": " + group.getValue(), e);
}
}
RegexTemplateTokens beforeTokens = new RegexTemplateTokens(location, before, parsedGroups, repeatedGroups);
RegexTemplateTokens afterTokens = new RegexTemplateTokens(location, after, parsedGroups, repeatedGroups);
beforeTokens.validateUnused();
List<Pattern> parsedIgnorePatterns = new ArrayList<>();
for (String toIgnore : patternsToIgnore) {
try {
parsedIgnorePatterns.add(Pattern.compile(toIgnore));
} catch (PatternSyntaxException e) {
throw new EvalException(location, "'patterns_to_ignore' includes invalid regex: " + toIgnore, e);
}
}
return new Replace(beforeTokens, afterTokens, parsedGroups, firstOnly, multiline, repeatedGroups, paths, parsedIgnorePatterns, workflowOptions);
}
use of com.google.re2j.PatternSyntaxException in project hadoop by apache.
the class GlobFilter method init.
void init(String filePattern, PathFilter filter) throws IOException {
try {
userFilter = filter;
pattern = new GlobPattern(filePattern);
} catch (PatternSyntaxException e) {
// Existing code expects IOException startWith("Illegal file pattern")
throw new IOException("Illegal file pattern: " + e.getMessage(), e);
}
}
Aggregations