Changeset 333

Show
Ignore:
Timestamp:
12/28/07 21:30:09 (6 months ago)
Author:
hans
Message:

Refs #205 - Applying patch for AvailableTask checking resources.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.3/classes/phing/tasks/system/AvailableTask.php

    r144 r333  
    2929 * 
    3030 *  @author    Andreas Aderhold <andi@binarycloud.com> 
    31  *  @copyright © 2001,2002 THYRELL. All rights reserved 
     31 *  @copyright ᅵ 2001,2002 THYRELL. All rights reserved 
    3232 *  @version   $Revision: 1.11 $ 
    3333 *  @package   phing.tasks.system 
     
    3535class AvailableTask extends Task { 
    3636 
    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; 
    4839 
    49     function setProperty($property) { 
    50         $this->property = (string) $property; 
    51     } 
     40        /** Value property should be set to. */ 
     41        private $value = "true"; 
    5242 
    53     function setValue($value) { 
    54         $this->value = (string) $value; 
    55     } 
     43        /** Resource to check for */ 
     44        private $resource; 
    5645 
    57     function setFile(PhingFile $file) { 
    58         $this->file = $file; 
    59     } 
     46        private $type = null; 
     47        private $filepath = null; 
    6048 
    61     function setResource($resource) { 
    62         $this->resource = (string) $resource
    63    
     49       function setProperty($property) { 
     50               $this->property = (string) $property
     51       
    6452 
    65     function setType($type) { 
    66         $this->type = (string) strtolower($type)
    67    
     53       function setValue($value) { 
     54               $this->value = (string) $value
     55       
    6856 
    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        } 
    7760 
    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        } 
    8264 
    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        } 
    9168 
    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        } 
    9677 
    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                } 
    9982 
    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                } 
    11686 
    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                } 
    12791 
    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                } 
    13196 
     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        } 
    132135}