/**
* The heart of the matter. This is where the selector gets to decide
* on the inclusion of a file in a particular fileset.
*
* @param PhingFile $basedir base directory the scan is being done from
* @param string $filename the name of the file to check
* @param PhingFile $file PhingFile object the selector can use
*
* @throws BuildException
*
* @return bool whether the file should be selected or not
*/
public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
{
$this->validate();
if ($file->isDirectory()) {
return true;
}
if ($this->myRegExp === null) {
$this->myRegExp = new RegularExpression();
$this->myRegExp->setPattern($this->userProvidedExpression);
if (!$this->casesensitive) {
$this->myRegExp->setIgnoreCase(true);
}
$this->myExpression = $this->myRegExp->getRegexp($this->getProject());
}
$in = null;
try {
$in = new BufferedReader(new FileReader($file));
$teststr = $in->readLine();
while ($teststr !== null) {
if ($this->myExpression->matches($teststr)) {
return true;
}
$teststr = $in->readLine();
}
$in->close();
return false;
} catch (IOException $ioe) {
if ($in) {
$in->close();
}
throw new BuildException("Could not read file " . $filename);
}
}