use of org.apache.tools.ant.types.RegularExpression in project JikesRVM by JikesRVM.
the class SelectRegexTask method setPattern.
public void setPattern(final String pattern) {
this.pattern = new RegularExpression();
this.pattern.setPattern(pattern);
this.patternLines = pattern.split(System.getProperty("line.separator")).length;
}
use of org.apache.tools.ant.types.RegularExpression in project ant by apache.
the class LineContainsRegExp method read.
/**
* Returns the next character in the filtered stream, only including
* lines from the original stream which match all of the specified
* regular expressions.
*
* @return the next character in the resulting stream, or -1
* if the end of the resulting stream has been reached
*
* @exception IOException if the underlying stream throws an IOException
* during reading
*/
public int read() throws IOException {
if (!getInitialized()) {
initialize();
setInitialized(true);
}
int ch = -1;
if (line != null) {
ch = line.charAt(0);
if (line.length() == 1) {
line = null;
} else {
line = line.substring(1);
}
} else {
for (line = readLine(); line != null; line = readLine()) {
boolean matches = true;
for (RegularExpression regexp : regexps) {
if (!regexp.getRegexp(getProject()).matches(line, regexpOptions)) {
matches = false;
break;
}
}
if (matches ^ isNegated()) {
break;
}
}
if (line != null) {
return read();
}
}
return ch;
}
use of org.apache.tools.ant.types.RegularExpression in project ant by apache.
the class FilenameSelector method isSelected.
/**
* The heart of the matter. This is where the selector gets to decide
* on the inclusion of a file in a particular fileset. Most of the work
* for this selector is offloaded into SelectorUtils, a static class
* that provides the same services for both FilenameSelector and
* DirectoryScanner.
*
* @param basedir the base directory the scan is being done from
* @param filename is the name of the file to check
* @param file is a java.io.File object the selector can use
* @return whether the file should be selected or not
*/
public boolean isSelected(File basedir, String filename, File file) {
validate();
if (pattern != null) {
return SelectorUtils.matchPath(pattern, filename, casesensitive) == !(negated);
}
if (reg == null) {
reg = new RegularExpression();
reg.setPattern(regex);
expression = reg.getRegexp(getProject());
}
int options = RegexpUtil.asOptions(casesensitive);
return expression.matches(filename, options) == !negated;
}
use of org.apache.tools.ant.types.RegularExpression in project ant-ivy by apache.
the class IvyExtractFromSources method configureConcat.
private void configureConcat() {
concat.setProject(getProject());
concat.setTaskName(getTaskName());
FilterChain filterChain = new FilterChain();
LineContainsRegExp lcre = new LineContainsRegExp();
RegularExpression regexp = new RegularExpression();
regexp.setPattern("^import .+;");
lcre.addConfiguredRegexp(regexp);
filterChain.add(lcre);
TokenFilter tf = new TokenFilter();
TokenFilter.ReplaceRegex rre = new TokenFilter.ReplaceRegex();
rre.setPattern("import (.+);.*");
rre.setReplace("\\1");
tf.add(rre);
filterChain.add(tf);
concat.addFilterChain(filterChain);
}
use of org.apache.tools.ant.types.RegularExpression in project JikesRVM by JikesRVM.
the class LineFilterTask method execute.
public void execute() throws BuildException {
if (null == src)
throw new BuildException("src not set.");
if (null == dest)
throw new BuildException("dest not set.");
if (0 == patterns.size())
throw new BuildException("No patterns specified.");
final ArrayList<Regexp> regexpList = new ArrayList<Regexp>();
for (final RegularExpression pattern : patterns) {
regexpList.add(pattern.getRegexp(getProject()));
}
final Regexp[] regexps = regexpList.toArray(new Regexp[regexpList.size()]);
BufferedReader reader = null;
BufferedWriter writer = null;
try {
reader = new BufferedReader(new FileReader(src));
writer = new BufferedWriter(new FileWriter(dest));
String line = reader.readLine();
while (null != line) {
if (!lineMatches(line, regexps)) {
writer.write(line);
writer.write('\n');
}
line = reader.readLine();
}
} catch (IOException e) {
throw new BuildException("Error truncating file " + src, e);
} finally {
if (null != reader) {
try {
reader.close();
} catch (IOException e) {
}
}
if (null != writer) {
try {
writer.close();
} catch (final IOException ioe) {
throw new BuildException(ioe);
}
}
}
}
Aggregations