Search in sources :

Example 1 with PatternSyntaxException

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);
}
Also used : Pattern(com.google.re2j.Pattern) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EvalException(com.google.devtools.build.lib.syntax.EvalException) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) PatternSyntaxException(com.google.re2j.PatternSyntaxException)

Example 2 with PatternSyntaxException

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);
    }
}
Also used : IOException(java.io.IOException) PatternSyntaxException(com.google.re2j.PatternSyntaxException)

Aggregations

PatternSyntaxException (com.google.re2j.PatternSyntaxException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 EvalException (com.google.devtools.build.lib.syntax.EvalException)1 Pattern (com.google.re2j.Pattern)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1