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);
}
}
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));
}
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;
}
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);
}
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);
}
Aggregations