Changeset 333
- Timestamp:
- 12/28/07 21:30:09 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.3/classes/phing/tasks/system/AvailableTask.php
r144 r333 29 29 * 30 30 * @author Andreas Aderhold <andi@binarycloud.com> 31 * @copyright ©2001,2002 THYRELL. All rights reserved31 * @copyright ᅵ 2001,2002 THYRELL. All rights reserved 32 32 * @version $Revision: 1.11 $ 33 33 * @package phing.tasks.system … … 35 35 class AvailableTask extends Task { 36 36 37 /** Property to check for. */ 38 private $property; 39 40 /** Value property should be set to. */ 41 private $value = "true"; 42 43 /** Resource to check for */ 44 private $resource; 45 46 private $type = null; 47 private $filepath = null; 37 /** Property to check for. */ 38 private $property; 48 39 49 function setProperty($property) { 50 $this->property = (string) $property; 51 } 40 /** Value property should be set to. */ 41 private $value = "true"; 52 42 53 function setValue($value) { 54 $this->value = (string) $value; 55 } 43 /** Resource to check for */ 44 private $resource; 56 45 57 function setFile(PhingFile $file) { 58 $this->file = $file; 59 } 46 private $type = null; 47 private $filepath = null; 60 48 61 function setResource($resource) {62 $this->resource = (string) $resource;63 }49 function setProperty($property) { 50 $this->property = (string) $property; 51 } 64 52 65 function setType($type) {66 $this->type = (string) strtolower($type);67 }53 function setValue($value) { 54 $this->value = (string) $value; 55 } 68 56 69 function main() { 70 if ($this->property === null) { 71 throw new BuildException("property attribute is required", $this->location); 72 } 73 if ($this->evaluate()) { 74 $this->project->setProperty($this->property, $this->value); 75 } 76 } 57 function setFile(PhingFile $file) { 58 $this->file = $file; 59 } 77 60 78 function evaluate() { 79 if ($this->file === null && $this->resource === null) { 80 throw new BuildException("At least one of (file|resource) is required", $this->location); 81 } 61 function setResource($resource) { 62 $this->resource = (string) $resource; 63 } 82 64 83 if ($this->type !== null && ($this->type !== "file" && $this->type !== "dir")) { 84 throw new BuildException("Type must be one of either dir or file", $this->location); 85 } 86 87 if (($this->file !== null) && !$this->_checkFile()) { 88 $this->log("Unable to find " . $this->file->__toString() . " to set property " . $this->property, Project::MSG_VERBOSE); 89 return false; 90 } 65 function setType($type) { 66 $this->type = (string) strtolower($type); 67 } 91 68 92 if (($this->resource !== null) && !$this->_checkResource($this->resource)) { 93 $this->log("Unable to load resource " . $this->resource . " to set property " . $this->property, Project::MSG_VERBOSE); 94 return false; 95 } 69 function main() { 70 if ($this->property === null) { 71 throw new BuildException("property attribute is required", $this->location); 72 } 73 if ($this->evaluate()) { 74 $this->project->setProperty($this->property, $this->value); 75 } 76 } 96 77 97 return true; 98 } 78 function evaluate() { 79 if ($this->file === null && $this->resource === null) { 80 throw new BuildException("At least one of (file|resource) is required", $this->location); 81 } 99 82 100 // this is prepared for the path type 101 function _checkFile() { 102 if ($this->filepath === null) { 103 return $this->_checkFile1($this->file); 104 } else { 105 $paths = $this->filepath->listDir(); 106 for($i=0,$pcnt=count($paths); $i < $pcnt; $i++) { 107 $this->log("Searching " . $paths[$i], Project::MSG_VERBOSE); 108 $tmp = new PhingFile($paths[$i], $this->file->getName()); 109 if($tmp->isFile()) { 110 return true; 111 } 112 } 113 } 114 return false; 115 } 83 if ($this->type !== null && ($this->type !== "file" && $this->type !== "dir")) { 84 throw new BuildException("Type must be one of either dir or file", $this->location); 85 } 116 86 117 function _checkFile1($file) { 118 if ($this->type !== null) { 119 if ($this->type === "dir") { 120 return $file->isDirectory(); 121 } else if ($this->type === "file") { 122 return $file->isFile(); 123 } 124 } 125 return $file->exists(); 126 } 87 if (($this->file !== null) && !$this->_checkFile()) { 88 $this->log("Unable to find " . $this->file->__toString() . " to set property " . $this->property, Project::MSG_VERBOSE); 89 return false; 90 } 127 91 128 function _checkResource($resource) { 129 return $this->_checkFile1(new PhingFile(Phing::getResourcePath($resource))); 130 } 92 if (($this->resource !== null) && !$this->_checkResource($this->resource)) { 93 $this->log("Unable to load resource " . $this->resource . " to set property " . $this->property, Project::MSG_VERBOSE); 94 return false; 95 } 131 96 97 return true; 98 } 99 100 // this is prepared for the path type 101 private function _checkFile() { 102 if ($this->filepath === null) { 103 return $this->_checkFile1($this->file); 104 } else { 105 $paths = $this->filepath->listDir(); 106 for($i=0,$pcnt=count($paths); $i < $pcnt; $i++) { 107 $this->log("Searching " . $paths[$i], Project::MSG_VERBOSE); 108 $tmp = new PhingFile($paths[$i], $this->file->getName()); 109 if($tmp->isFile()) { 110 return true; 111 } 112 } 113 } 114 return false; 115 } 116 117 private function _checkFile1(PhingFile $file) { 118 if ($this->type !== null) { 119 if ($this->type === "dir") { 120 return $file->isDirectory(); 121 } else if ($this->type === "file") { 122 return $file->isFile(); 123 } 124 } 125 return $file->exists(); 126 } 127 128 private function _checkResource($resource) { 129 if (null != ($resourcePath = Phing::getResourcePath($resource))) { 130 return $this->_checkFile1(new PhingFile($resourcePath)); 131 } else { 132 return false; 133 } 134 } 132 135 }
