Search in sources :

Example 6 with RegularExpression

use of org.apache.tools.ant.types.RegularExpression in project ant by apache.

the class ContainsRegexpSelector method isSelected.

/**
 * Tests a regular expression against each line of text in a Resource.
 *
 * @param r the Resource to check.
 * @return whether the Resource is selected or not
 */
public boolean isSelected(Resource r) {
    // throw BuildException on error
    validate();
    if (r.isDirectory()) {
        return true;
    }
    if (myRegExp == null) {
        myRegExp = new RegularExpression();
        myRegExp.setPattern(userProvidedExpression);
        myExpression = myRegExp.getRegexp(getProject());
    }
    try (BufferedReader in = new BufferedReader(new InputStreamReader(r.getInputStream()))) {
        try {
            String teststr = in.readLine();
            while (teststr != null) {
                if (myExpression.matches(teststr, RegexpUtil.asOptions(caseSensitive, multiLine, singleLine))) {
                    return true;
                }
                teststr = in.readLine();
            }
            return false;
        } catch (IOException ioe) {
            throw new BuildException("Could not read " + r.toLongString());
        }
    } catch (IOException e) {
        throw new BuildException("Could not get InputStream from " + r.toLongString(), e);
    }
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 7 with RegularExpression

use of org.apache.tools.ant.types.RegularExpression in project ant by apache.

the class Name method matches.

private boolean matches(String name) {
    if (pattern != null) {
        return SelectorUtils.match(modify(pattern), modify(name), cs);
    }
    if (reg == null) {
        reg = new RegularExpression();
        reg.setPattern(regex);
        expression = reg.getRegexp(project);
    }
    return expression.matches(modify(name), RegexpUtil.asOptions(cs));
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression)

Example 8 with RegularExpression

use of org.apache.tools.ant.types.RegularExpression in project ant by apache.

the class AbstractJarSignerTask method createRedirector.

/**
 * Create the redirector to use, if any.
 *
 * @return a configured RedirectorElement.
 */
private RedirectorElement createRedirector() {
    RedirectorElement result = new RedirectorElement();
    if (storepass != null) {
        StringBuilder input = new StringBuilder(storepass).append('\n');
        if (keypass != null) {
            input.append(keypass).append('\n');
        }
        result.setInputString(input.toString());
        result.setLogInputString(false);
        // Try to avoid showing password prompts on log output, as they would be confusing.
        LineContainsRegExp filter = new LineContainsRegExp();
        RegularExpression rx = new RegularExpression();
        // TODO only handles English locale, not ja or zh_CN
        rx.setPattern("^(Enter Passphrase for keystore: |Enter key password for .+: )$");
        filter.addConfiguredRegexp(rx);
        filter.setNegate(true);
        result.createErrorFilterChain().addLineContainsRegExp(filter);
    }
    return result;
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression) RedirectorElement(org.apache.tools.ant.types.RedirectorElement) LineContainsRegExp(org.apache.tools.ant.filters.LineContainsRegExp)

Example 9 with RegularExpression

use of org.apache.tools.ant.types.RegularExpression in project ant by apache.

the class LineContainsRegExp method setRegexp.

/**
 * Set the regular expression as an attribute.
 * @param pattern String
 * @since Ant 1.10.2
 */
public void setRegexp(String pattern) {
    RegularExpression regexp = new RegularExpression();
    regexp.setPattern(pattern);
    regexps.addElement(regexp);
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression)

Example 10 with RegularExpression

use of org.apache.tools.ant.types.RegularExpression in project ant by apache.

the class Matches method setPattern.

/**
 * Set the regular expression to match against
 *
 * @param pattern the regular expression pattern
 */
public void setPattern(String pattern) {
    if (regularExpression != null) {
        throw new BuildException("Only one regular expression is allowed.");
    }
    regularExpression = new RegularExpression();
    regularExpression.setPattern(pattern);
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression) BuildException(org.apache.tools.ant.BuildException)

Aggregations

RegularExpression (org.apache.tools.ant.types.RegularExpression)11 BuildException (org.apache.tools.ant.BuildException)4 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 LineContainsRegExp (org.apache.tools.ant.filters.LineContainsRegExp)2 BufferedWriter (java.io.BufferedWriter)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 TokenFilter (org.apache.tools.ant.filters.TokenFilter)1 FilterChain (org.apache.tools.ant.types.FilterChain)1 RedirectorElement (org.apache.tools.ant.types.RedirectorElement)1 Regexp (org.apache.tools.ant.util.regexp.Regexp)1