|
|
@@ -27,6 +27,9 @@ import java.io.InputStreamReader; |
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
|
import org.apache.tools.ant.types.Parameter; |
|
|
|
import org.apache.tools.ant.types.RegularExpression; |
|
|
|
import org.apache.tools.ant.types.Resource; |
|
|
|
import org.apache.tools.ant.types.resources.FileResource; |
|
|
|
import org.apache.tools.ant.types.resources.selectors.ResourceSelector; |
|
|
|
import org.apache.tools.ant.util.regexp.Regexp; |
|
|
|
|
|
|
|
/** |
|
|
@@ -34,7 +37,8 @@ import org.apache.tools.ant.util.regexp.Regexp; |
|
|
|
* |
|
|
|
* @since Ant 1.6 |
|
|
|
*/ |
|
|
|
public class ContainsRegexpSelector extends BaseExtendSelector { |
|
|
|
public class ContainsRegexpSelector extends BaseExtendSelector |
|
|
|
implements ResourceSelector { |
|
|
|
|
|
|
|
private String userProvidedExpression = null; |
|
|
|
private RegularExpression myRegExp = null; |
|
|
@@ -107,6 +111,16 @@ public class ContainsRegexpSelector extends BaseExtendSelector { |
|
|
|
* @return whether the file should be selected or not |
|
|
|
*/ |
|
|
|
public boolean isSelected(File basedir, String filename, File file) { |
|
|
|
return isSelected(new FileResource(file)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 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) { |
|
|
|
String teststr = null; |
|
|
|
BufferedReader in = null; |
|
|
|
|
|
|
@@ -114,7 +128,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector { |
|
|
|
|
|
|
|
validate(); |
|
|
|
|
|
|
|
if (file.isDirectory()) { |
|
|
|
if (r.isDirectory()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@@ -125,9 +139,12 @@ public class ContainsRegexpSelector extends BaseExtendSelector { |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
in = new BufferedReader(new InputStreamReader( |
|
|
|
new FileInputStream(file))); |
|
|
|
|
|
|
|
in = new BufferedReader(new InputStreamReader(r.getInputStream())); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new BuildException("Could not get InputStream from " |
|
|
|
+ r.toLongString(), e); |
|
|
|
} |
|
|
|
try { |
|
|
|
teststr = in.readLine(); |
|
|
|
|
|
|
|
while (teststr != null) { |
|
|
@@ -140,14 +157,14 @@ public class ContainsRegexpSelector extends BaseExtendSelector { |
|
|
|
|
|
|
|
return false; |
|
|
|
} catch (IOException ioe) { |
|
|
|
throw new BuildException("Could not read file " + filename); |
|
|
|
throw new BuildException("Could not read " + r.toLongString()); |
|
|
|
} finally { |
|
|
|
if (in != null) { |
|
|
|
try { |
|
|
|
in.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new BuildException("Could not close file " |
|
|
|
+ filename); |
|
|
|
throw new BuildException("Could not close " |
|
|
|
+ r.toLongString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|