summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/tasks/system/AvailableTask.php
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/phing/classes/phing/tasks/system/AvailableTask.php')
-rwxr-xr-x[-rw-r--r--]buildscripts/phing/classes/phing/tasks/system/AvailableTask.php76
1 files changed, 58 insertions, 18 deletions
diff --git a/buildscripts/phing/classes/phing/tasks/system/AvailableTask.php b/buildscripts/phing/classes/phing/tasks/system/AvailableTask.php
index 76de3e40..bd5701e4 100644..100755
--- a/buildscripts/phing/classes/phing/tasks/system/AvailableTask.php
+++ b/buildscripts/phing/classes/phing/tasks/system/AvailableTask.php
@@ -1,6 +1,6 @@
<?php
/*
- * $Id: AvailableTask.php 59 2006-04-28 14:49:47Z mrook $
+ * $Id: 7388bc66c9574987edd02ad3b2d6f14462f6b157 $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@@ -28,23 +28,25 @@ include_once 'phing/tasks/system/condition/ConditionBase.php';
* Note: implements condition interface (see condition/Condition.php)
*
* @author Andreas Aderhold <andi@binarycloud.com>
- * @copyright © 2001,2002 THYRELL. All rights reserved
- * @version $Revision: 1.11 $
+ * @copyright 2001,2002 THYRELL. All rights reserved
+ * @version $Id$
* @package phing.tasks.system
*/
class AvailableTask extends Task {
/** Property to check for. */
private $property;
-
+
/** Value property should be set to. */
private $value = "true";
-
+
/** Resource to check for */
private $resource;
-
+
private $type = null;
private $filepath = null;
+
+ private $followSymlinks = false;
function setProperty($property) {
$this->property = (string) $property;
@@ -65,6 +67,36 @@ class AvailableTask extends Task {
function setType($type) {
$this->type = (string) strtolower($type);
}
+
+ public function setFollowSymlinks($followSymlinks)
+ {
+ $this->followSymlinks = (bool) $followSymlinks;
+ }
+
+ /**
+ * Set the path to use when looking for a file.
+ *
+ * @param Path $filepath a Path instance containing the search path for files.
+ */
+ public function setFilepath(Path $filepath) {
+ if ($this->filepath === null) {
+ $this->filepath = $filepath;
+ } else {
+ $this->filepath->append($filepath);
+ }
+ }
+
+ /**
+ * Creates a path to be configured
+ *
+ * @return Path
+ */
+ public function createFilepath() {
+ if ($this->filepath === null) {
+ $this->filepath = new Path($this->project);
+ }
+ return $this->filepath->createPath();
+ }
function main() {
if ($this->property === null) {
@@ -77,20 +109,20 @@ class AvailableTask extends Task {
function evaluate() {
if ($this->file === null && $this->resource === null) {
- throw new BuildException("At least one of (file|resource) is required", $this->location);
+ throw new BuildException("At least one of (file|resource) is required", $this->location);
}
if ($this->type !== null && ($this->type !== "file" && $this->type !== "dir")) {
throw new BuildException("Type must be one of either dir or file", $this->location);
}
-
+
if (($this->file !== null) && !$this->_checkFile()) {
- $this->log("Unable to find " . $this->file->__toString() . " to set property " . $this->property, PROJECT_MSG_VERBOSE);
+ $this->log("Unable to find " . $this->file->__toString() . " to set property " . $this->property, Project::MSG_VERBOSE);
return false;
}
if (($this->resource !== null) && !$this->_checkResource($this->resource)) {
- $this->log("Unable to load resource " . $this->resource . " to set property " . $this->property, PROJECT_MSG_VERBOSE);
+ $this->log("Unable to load resource " . $this->resource . " to set property " . $this->property, Project::MSG_VERBOSE);
return false;
}
@@ -98,13 +130,13 @@ class AvailableTask extends Task {
}
// this is prepared for the path type
- function _checkFile() {
+ private function _checkFile() {
if ($this->filepath === null) {
return $this->_checkFile1($this->file);
} else {
- $paths = $this->filepath->listDir();
+ $paths = $this->filepath->listPaths();
for($i=0,$pcnt=count($paths); $i < $pcnt; $i++) {
- $this->log("Searching " . $paths[$i], PROJECT_MSG_VERBOSE);
+ $this->log("Searching " . $paths[$i], Project::MSG_VERBOSE);
$tmp = new PhingFile($paths[$i], $this->file->getName());
if($tmp->isFile()) {
return true;
@@ -114,7 +146,12 @@ class AvailableTask extends Task {
return false;
}
- function _checkFile1($file) {
+ private function _checkFile1(PhingFile $file) {
+ // Resolve symbolic links
+ if ($this->followSymlinks && $file->isLink()) {
+ $file = new PhingFile($file->getLinkTarget());
+ }
+
if ($this->type !== null) {
if ($this->type === "dir") {
return $file->isDirectory();
@@ -124,9 +161,12 @@ class AvailableTask extends Task {
}
return $file->exists();
}
-
- function _checkResource($resource) {
- return $this->_checkFile1(new PhingFile(Phing::getResourcePath($resource)));
+
+ private function _checkResource($resource) {
+ if (null != ($resourcePath = Phing::getResourcePath($resource))) {
+ return $this->_checkFile1(new PhingFile($resourcePath));
+ } else {
+ return false;
+ }
}
-
}