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); }
/** * Invoke a regular expression (r) on a string (input) using * substitutions (s) for a matching regex. * * @param r a regular expression * @param s a Substitution * @param input the string to do the replacement on * @param options The options for the regular expression * @return the replacement result */ protected String doReplace(RegularExpression r, Substitution s, String input, int options) { String res = input; Regexp regexp = r.getRegexp(getProject()); if (regexp.matches(input, options)) { log("Found match; substituting", Project.MSG_DEBUG); res = regexp.substitute(input, s.getExpression(getProject()), options); } return res; }
/** * 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; }
private void initialize() { if (initialized) { return; } options = convertRegexOptions(flags); if (from == null) { throw new BuildException("Missing pattern in replaceregex"); } regularExpression = new RegularExpression(); regularExpression.setPattern(from); regexp = regularExpression.getRegexp(getProject()); if (to == null) { to = ""; } substitution = new Substitution(); substitution.setExpression(to); }
private void initialize() { if (initialized) { return; } options = convertRegexOptions(flags); if (from == null) { throw new BuildException("Missing from in containsregex"); } regularExpression = new RegularExpression(); regularExpression.setPattern(from); regexp = regularExpression.getRegexp(getProject()); if (to == null) { return; } substitution = new Substitution(); substitution.setExpression(to); }
public void setRegexp(String regex) { if (this.regexp != null) throw new BuildException("Cannot specify more than one regular expression"); this.regexp = new RegularExpression(); this.regexp.setPattern(regex); }
/** * A regular expression. * You can use this element to refer to a previously * defined regular expression datatype instance * @param regularExpression the regular expression object * to be configured as an element */ public void addRegexp(RegularExpression regularExpression) { if (this.regularExpression != null) { throw new BuildException( "Only one regular expression is allowed."); } this.regularExpression = regularExpression; }
/** * 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 { final int regexpsSize = regexps.size(); for (line = readLine(); line != null; line = readLine()) { boolean matches = true; for (int i = 0; matches && i < regexpsSize; i++) { RegularExpression regexp = (RegularExpression) regexps.elementAt(i); Regexp re = regexp.getRegexp(getProject()); matches = re.matches(line, regexpOptions); } if (matches ^ isNegated()) { break; } } if (line != null) { return read(); } } return ch; }
public void setMatch(String match) { this.match = new RegularExpression(); this.match.setPattern(match); }
/** * 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); }
public void setPattern(final String pattern) { this.pattern = new RegularExpression(); this.pattern.setPattern(pattern); }
public void addFilter(final RegularExpression regex) { patterns.add(regex); }
/** * the regular expression pattern to match in the file(s); * required if no nested <regexp> is used */ public void setMatch(String match) { RegularExpression regex = new RegularExpression(); regex.setPattern(match); addConfiguredRegexp(regex); }
/** * Adds a set of files to count. */ @SuppressWarnings("deprecation") public void addConfiguredRegexp(RegularExpression regex) { Regexp regexp = regex.getRegexp(project); regexList.add(regexp); }
/** * Adds a <code>regexp</code> element. * * @param regExp The <code>regexp</code> element to add. * Must not be <code>null</code>. */ public void addConfiguredRegexp(final RegularExpression regExp) { this.regexps.addElement(regExp); }
/** * Sets the vector of regular expressions which must be contained within * a line read from the original stream in order for it to match this * filter. * * @param regexps A vector of regular expressions which must be contained * within a line in order for it to match in this filter. Must not be * <code>null</code>. */ private void setRegexps(final Vector<RegularExpression> regexps) { this.regexps = regexps; }
/** * Returns the vector of regular expressions which must be contained within * a line read from the original stream in order for it to match this * filter. * * @return the vector of regular expressions which must be contained within * a line read from the original stream in order for it to match this * filter. The returned object is "live" - in other words, changes made to * the returned object are mirrored in the filter. */ private Vector<RegularExpression> getRegexps() { return regexps; }