Changeset 290

Show
Ignore:
Timestamp:
11/04/07 15:04:36 (9 months ago)
Author:
hans
Message:

Merging changes from fix to #177

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/BuildException.php

    r123 r290  
    2929class BuildException extends Exception { 
    3030 
    31     /** location in the xml file */ 
    32     protected $location = null;  
     31    /** 
     32         * Location in the xml file. 
     33         * @var Location 
     34         */ 
     35    protected $location; 
    3336             
    34     /** The nested "cause" exception. */ 
     37    /** 
     38         * The nested "cause" exception. 
     39         * @var Exception 
     40         */ 
    3541    protected $cause; 
    3642     
     
    8591    } 
    8692     
    87     function getCause() { 
     93    /** 
     94     * Gets the cause exception. 
     95     * 
     96     * @return Exception 
     97     */ 
     98    public function getCause() { 
    8899        return $this->cause; 
    89100    } 
    90101     
    91     function getLocation() { 
     102    /** 
     103     * Gets the location of error in XML file. 
     104     * 
     105     * @return Location 
     106     */ 
     107    public function getLocation() { 
    92108        return $this->location; 
    93109    } 
    94110 
    95     function setLocation($loc) {         
     111    /** 
     112     * Sets the location of error in XML file. 
     113     * 
     114     * @param Locaiton $loc 
     115     */ 
     116    public function setLocation(Location $loc) {         
    96117        $this->location = $loc; 
    97118        $this->message = $loc->toString() . ': ' . $this->message; 
  • trunk/classes/phing/Phing.php

    r230 r290  
    1919 * <http://phing.info>. 
    2020 */ 
    21   
     21 
    2222require_once 'phing/Project.php'; 
    2323require_once 'phing/ProjectComponent.php'; 
     
    2626 
    2727include_once 'phing/BuildException.php'; 
     28include_once 'phing/ConfigurationException.php'; 
    2829include_once 'phing/BuildEvent.php'; 
    2930 
     
    4849 
    4950/** 
    50  * Entry point into Phing.  This class handles the full lifecycle of a build -- from  
     51 * Entry point into Phing.  This class handles the full lifecycle of a build -- from 
    5152 * parsing & handling commandline arguments to assembling the project to shutting down 
    5253 * and cleaning up in the end. 
     
    6364class Phing { 
    6465 
    65     /** The default build file name */ 
    66     const DEFAULT_BUILD_FILENAME = "build.xml"; 
    67          
    68     /** Our current message output status. Follows Project::MSG_XXX */ 
    69     private static $msgOutputLevel = Project::MSG_INFO; 
    70  
    71     /** PhingFile that we are using for configuration */ 
    72     private $buildFile = null; 
    73  
    74     /** The build targets */ 
    75     private $targets = array(); 
    76  
    77     /** 
    78     * Set of properties that are passed in from commandline or invoking code. 
    79     * @var Properties 
    80     */ 
    81     private static $definedProps; 
    82  
    83     /** Names of classes to add as listeners to project */ 
    84     private $listeners = array(); 
    85  
    86     private $loggerClassname = null; 
    87  
    88     /** The class to handle input (can be only one). */ 
    89     private $inputHandlerClassname; 
    90      
    91     /** Indicates if this phing should be run */ 
    92     private $readyToRun = false; 
    93  
    94     /** Indicates we should only parse and display the project help information */ 
    95     private $projectHelp = false; 
    96          
    97     /** Used by utility function getResourcePath() */ 
    98     private static $importPaths; 
    99      
    100     /** System-wide static properties (moved from System) */ 
    101     private static $properties = array(); 
    102      
    103     /** Static system timer. */ 
    104     private static $timer; 
    105      
     66       /** The default build file name */ 
     67       const DEFAULT_BUILD_FILENAME = "build.xml"; 
     68 
     69       /** Our current message output status. Follows Project::MSG_XXX */ 
     70       private static $msgOutputLevel = Project::MSG_INFO; 
     71 
     72       /** PhingFile that we are using for configuration */ 
     73       private $buildFile = null; 
     74 
     75       /** The build targets */ 
     76       private $targets = array(); 
     77 
     78       /** 
     79        * Set of properties that are passed in from commandline or invoking code. 
     80        * @var Properties 
     81        */ 
     82       private static $definedProps; 
     83 
     84       /** Names of classes to add as listeners to project */ 
     85       private $listeners = array(); 
     86 
     87       private $loggerClassname = null; 
     88 
     89       /** The class to handle input (can be only one). */ 
     90       private $inputHandlerClassname; 
     91 
     92       /** Indicates if this phing should be run */ 
     93       private $readyToRun = false; 
     94 
     95       /** Indicates we should only parse and display the project help information */ 
     96       private $projectHelp = false; 
     97 
     98       /** Used by utility function getResourcePath() */ 
     99       private static $importPaths; 
     100 
     101       /** System-wide static properties (moved from System) */ 
     102       private static $properties = array(); 
     103 
     104       /** Static system timer. */ 
     105       private static $timer; 
     106 
    106107        /** The current Project */ 
    107108        private static $currentProject; 
    108          
     109 
    109110        /** Whether to capture PHP errors to buffer. */ 
    110111        private static $phpErrorCapture = false; 
    111          
     112 
    112113        /** Array of captured PHP errors */ 
    113114        private static $capturedPhpErrors = array(); 
     
    117118         */ 
    118119        private static $out; 
    119          
     120 
    120121        /** 
    121122         * @var OutputStream Stream for error output. 
    122123         */ 
    123124        private static $err; 
    124          
     125 
    125126        /** 
    126127         * @var boolean Whether we are using a logfile. 
    127128         */ 
    128129        private static $isLogFileUsed = false; 
    129                  
    130     /**  
    131      * Entry point allowing for more options from other front ends. 
    132      *  
    133      * This method encapsulates the complete build lifecycle. 
    134      *  
    135      * @param array &$args The commandline args passed to phing shell script. 
    136      * @param array $additionalUserProperties   Any additional properties to be passed to Phing (alternative front-end might implement this). 
    137      *                                          These additional properties will be available using the getDefinedProperty() method and will 
    138      *                                          be added to the project's "user" properties. 
    139      * @return void 
    140      * @see execute() 
    141      * @see runBuild() 
    142      */ 
    143     public static function start(&$args, $additionalUserProperties = null) { 
    144  
    145         try { 
    146             $m = new Phing(); 
    147             $m->execute($args); 
    148         } catch (Exception $exc) { 
    149                 self::handleLogfile(); // clean up log file before attempting to print message 
    150             $m->printMessage($exc); 
    151             self::halt(-1); // Parameter error 
    152         } 
    153  
    154         if ($additionalUserProperties !== null) { 
    155             $keys = $m->additionalUserProperties->keys(); 
    156             while(count($keys)) { 
    157                 $key = array_shift($keys); 
    158                 $property = $m->additionalUserProperties->getProperty($key); 
    159                 $m->setDefinedProperty($key, $property); 
    160             } 
    161         } 
    162  
    163         try { 
    164             $m->runBuild(); 
    165         } catch(Exception $exc) { 
    166                 self::handleLogfile(); 
    167             self::halt(1); // Errors occured 
    168         } 
    169          
    170         // everything fine, shutdown 
     130 
     131        /** 
     132         * Entry point allowing for more options from other front ends. 
     133         * 
     134         * This method encapsulates the complete build lifecycle. 
     135         * 
     136         * @param array &$args The commandline args passed to phing shell script. 
     137         * @param array $additionalUserProperties   Any additional properties to be passed to Phing (alternative front-end might implement this). 
     138         *                                          These additional properties will be available using the getDefinedProperty() method and will 
     139         *                                          be added to the project's "user" properties. 
     140         * @return void 
     141         * @see execute() 
     142         * @see runBuild() 
     143         */ 
     144        public static function start(&$args, $additionalUserProperties = null) { 
     145 
     146                try { 
     147                        $m = new Phing(); 
     148                        $m->execute($args); 
     149                } catch (Exception $exc) { 
     150                        self::handleLogfile(); // clean up log file before attempting to print message 
     151                        $m->printMessage($exc); 
     152                        self::halt(-1); // Parameter error 
     153                } 
     154 
     155                if ($additionalUserProperties !== null) { 
     156                        $keys = $m->additionalUserProperties->keys(); 
     157                        while(count($keys)) { 
     158                                $key = array_shift($keys); 
     159                                $property = $m->additionalUserProperties->getProperty($key); 
     160                                $m->setDefinedProperty($key, $property); 
     161                        } 
     162                } 
     163 
     164                try { 
     165                        $m->runBuild(); 
     166                } catch(Exception $exc) { 
     167                        if ($exc instanceof ConfigurationException) { 
     168                                if (self::$msgOutputLevel >= Project::MSG_VERBOSE) { 
     169                                        self::$out->write($exc->__toString() . PHP_EOL); 
     170                                } else { 
     171                                        self::$out->write($exc->getMessage() . PHP_EOL); 
     172                                } 
     173                        } 
     174                        self::handleLogfile(); 
     175                        self::halt(1); // Errors occured 
     176                } 
     177 
     178                // everything fine, shutdown 
    171179                self::handleLogfile(); 
    172         self::halt(0); 
    173    
    174  
    175     /** 
    176     * Prints the message of the Exception if it's not null. 
    177     * @param Exception $t 
    178     */ 
    179     public static function printMessage(Exception $t) { 
    180               if (self::getMsgOutputLevel() <= Project::MSG_DEBUG) { 
    181                       self::$err->write($t->__toString()); 
    182               } else { 
    183                       self::$err->write($t->getMessage()); 
    184               } 
    185    
    186      
    187     /** 
    188     * Sets the stdout and stderr streams if they are not already set. 
    189     */ 
    190     private static function initializeOutputStreams() { 
    191         if (self::$out === null) { 
    192               self::$out = new OutputStream(fopen("php://stdout", "w")); 
    193        
    194         if (self::$err === null) { 
    195               self::$err = new OutputStream(fopen("php://stderr", "w")); 
    196        
    197    
    198      
    199     /** 
    200     * Sets the stream to use for standard (non-error) output. 
    201     * @param OutputStream $stream The stream to use for standard output. 
    202     */ 
    203     public static function setOutputStream(OutputStream $stream) { 
    204       self::$out = $stream; 
    205    
    206      
    207     /** 
    208     * Gets the stream to use for standard (non-error) output. 
    209     * @return OutputStream 
    210     */ 
    211       public static function getOutputStream() { 
    212               return self::$out; 
    213       } 
    214      
    215     /** 
    216     * Sets the stream to use for error output. 
    217     * @param OutputStream $stream The stream to use for error output. 
    218     */ 
    219     public static function setErrorStream(OutputStream $stream) { 
    220       self::$err = $stream; 
    221    
    222      
    223     /** 
    224     * Gets the stream to use for error output. 
    225     * @return OutputStream 
    226     */ 
    227       public static function getErrorStream() { 
    228               return self::$err; 
    229       } 
    230      
    231     /** 
    232     * Close logfiles, if we have been writing to them. 
    233    
    234     * @since Phing 2.3.0 
    235     */ 
    236     private static function handleLogfile() { 
    237         if (self::$isLogFileUsed) { 
    238               self::$err->close(); 
    239               self::$out->close(); 
    240        
    241    
    242      
    243     /** 
    244     * Making output level a static property so that this property 
    245     * can be accessed by other parts of the system, enabling 
    246     * us to display more information -- e.g. backtraces -- for "debug" level. 
    247     * @return int 
    248     */ 
    249     public static function getMsgOutputLevel() { 
    250         return self::$msgOutputLevel; 
    251     }         
    252      
    253     /** 
    254     * Command line entry point. This method kicks off the building 
    255     * of a project object and executes a build using either a given 
    256     * target or the default target. 
    257    
    258     * @param array $args Command line args. 
    259     * @return void 
    260     */ 
    261     public static function fire($args) { 
    262         self::start($args, null); 
    263    
    264      
    265     /** 
    266     * Setup/initialize Phing environment from commandline args. 
    267     * @param array $args commandline args passed to phing shell. 
    268     * @return void 
    269     */ 
    270     public function execute($args) { 
    271      
    272         self::$definedProps = new Properties(); 
    273         $this->searchForThis = null; 
    274  
    275         // cycle through given args 
    276         for ($i = 0, $argcount = count($args); $i < $argcount; ++$i) {  
    277                             // ++$i intentional here, as first param is script name 
    278             $arg = $args[$i]; 
    279  
    280             if ($arg == "-help" || $arg == "-h") { 
    281                 $this->printUsage(); 
    282                 return; 
    283             } elseif ($arg == "-version" || $arg == "-v") { 
    284                 $this->printVersion(); 
    285                 return; 
    286             } elseif ($arg == "-quiet" || $arg == "-q") { 
    287                 self::$msgOutputLevel = Project::MSG_WARN; 
    288             } elseif ($arg == "-verbose") { 
    289                 $this->printVersion(); 
    290                 self::$msgOutputLevel = Project::MSG_VERBOSE; 
    291             } elseif ($arg == "-debug") { 
    292                 $this->printVersion(); 
    293                 self::$msgOutputLevel = Project::MSG_DEBUG; 
    294             } elseif ($arg == "-logfile") { 
    295                 try { 
    296                       // see: http://phing.info/trac/ticket/65 
    297                     if (!isset($args[$i+1])) { 
    298                         $msg = "You must specify a log file when using the -logfile argument\n"; 
    299                         throw new BuildException($msg); 
    300                     } else { 
    301                         $logFile = new PhingFile($args[++$i]); 
    302                         $out = new FileOutputStream($logFile); // overwrite 
    303                         self::setOutputStream($out); 
    304                         self::setErrorStream($out); 
    305                         self::$isLogFileUsed = true; 
    306                    
    307                 } catch (IOException $ioe) { 
    308                     $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions."; 
    309                     throw new BuildException($msg, $ioe); 
    310                
    311             } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") { 
    312                 if (!isset($args[$i+1])) { 
    313                     $msg = "You must specify a buildfile when using the -buildfile argument."; 
    314                     throw new BuildException($msg); 
    315                 } else { 
    316                     $this->buildFile = new PhingFile($args[++$i]); 
    317                
    318             } elseif ($arg == "-listener") { 
    319                 if (!isset($args[$i+1])) { 
    320                     $msg = "You must specify a listener class when using the -listener argument"; 
    321                     throw new BuildException($msg); 
    322                 } else { 
    323                     $this->listeners[] = $args[++$i]; 
    324                
    325             } elseif (StringHelper::startsWith("-D", $arg)) { 
    326                 $name = substr($arg, 2); 
    327                 $value = null; 
    328                 $posEq = strpos($name, "="); 
    329                 if ($posEq !== false) { 
    330                     $value = substr($name, $posEq+1); 
    331                     $name  = substr($name, 0, $posEq); 
    332                 } elseif ($i < count($args)-1) { 
    333                     $value = $args[++$i]; 
    334                
    335                 self::$definedProps->setProperty($name, $value); 
    336             } elseif ($arg == "-logger") { 
    337                 if (!isset($args[$i+1])) { 
    338                     $msg = "You must specify a classname when using the -logger argument"; 
    339                     throw new BuildException($msg); 
    340                 } else { 
    341                     $this->loggerClassname = $args[++$i]; 
    342                
    343             } elseif ($arg == "-inputhandler") { 
    344                 if ($this->inputHandlerClassname !== null) { 
    345                     throw new BuildException("Only one input handler class may be specified."); 
    346                
    347                 if (!isset($args[$i+1])) { 
    348                     $msg = "You must specify a classname when using the -inputhandler argument"; 
    349                     throw new BuildException($msg); 
    350                 } else { 
    351                     $this->inputHandlerClassname = $args[++$i]; 
    352                
    353             } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") { 
    354                 // set the flag to display the targets and quit 
    355                 $this->projectHelp = true; 
    356             } elseif ($arg == "-find") { 
    357                 // eat up next arg if present, default to build.xml 
    358                 if ($i < count($args)-1) { 
    359                     $this->searchForThis = $args[++$i]; 
    360                 } else { 
    361                     $this->searchForThis = self::DEFAULT_BUILD_FILENAME; 
    362                
    363             } elseif (substr($arg,0,1) == "-") { 
    364                 // we don't have any more args 
     180               self::halt(0); 
     181       
     182 
     183       /** 
     184        * Prints the message of the Exception if it's not null. 
     185        * @param Exception $t 
     186        */ 
     187       public static function printMessage(Exception $t) { 
     188              if (self::getMsgOutputLevel() <= Project::MSG_DEBUG) { 
     189                      self::$err->write($t->__toString()); 
     190              } else { 
     191                      self::$err->write($t->getMessage()); 
     192              } 
     193       
     194 
     195       /** 
     196        * Sets the stdout and stderr streams if they are not already set. 
     197        */ 
     198       private static function initializeOutputStreams() { 
     199               if (self::$out === null) { 
     200                      self::$out = new OutputStream(fopen("php://stdout", "w")); 
     201               
     202               if (self::$err === null) { 
     203                      self::$err = new OutputStream(fopen("php://stderr", "w")); 
     204               
     205       
     206 
     207       /** 
     208        * Sets the stream to use for standard (non-error) output. 
     209        * @param OutputStream $stream The stream to use for standard output. 
     210        */ 
     211       public static function setOutputStream(OutputStream $stream) { 
     212              self::$out = $stream; 
     213       
     214 
     215       /** 
     216        * Gets the stream to use for standard (non-error) output. 
     217        * @return OutputStream 
     218        */ 
     219      public static function getOutputStream() { 
     220              return self::$out; 
     221      } 
     222 
     223       /** 
     224        * Sets the stream to use for error output. 
     225        * @param OutputStream $stream The stream to use for error output. 
     226        */ 
     227       public static function setErrorStream(OutputStream $stream) { 
     228              self::$err = $stream; 
     229       
     230 
     231       /** 
     232        * Gets the stream to use for error output. 
     233        * @return OutputStream 
     234        */ 
     235      public static function getErrorStream() { 
     236              return self::$err; 
     237      } 
     238 
     239       /** 
     240        * Close logfiles, if we have been writing to them. 
     241       
     242        * @since Phing 2.3.0 
     243        */ 
     244       private static function handleLogfile() { 
     245               if (self::$isLogFileUsed) { 
     246                      self::$err->close(); 
     247                      self::$out->close(); 
     248               
     249       
     250 
     251       /** 
     252        * Making output level a static property so that this property 
     253        * can be accessed by other parts of the system, enabling 
     254        * us to display more information -- e.g. backtraces -- for "debug" level. 
     255        * @return int 
     256        */ 
     257       public static function getMsgOutputLevel() { 
     258               return self::$msgOutputLevel; 
     259        } 
     260 
     261       /** 
     262        * Command line entry point. This method kicks off the building 
     263        * of a project object and executes a build using either a given 
     264        * target or the default target. 
     265       
     266        * @param array $args Command line args. 
     267        * @return void 
     268        */ 
     269       public static function fire($args) { 
     270               self::start($args, null); 
     271       
     272 
     273       /** 
     274        * Setup/initialize Phing environment from commandline args. 
     275        * @param array $args commandline args passed to phing shell. 
     276        * @return void 
     277        */ 
     278       public function execute($args) { 
     279 
     280               self::$definedProps = new Properties(); 
     281               $this->searchForThis = null; 
     282 
     283               // cycle through given args 
     284                for ($i = 0, $argcount = count($args); $i < $argcount; ++$i) { 
     285                       // ++$i intentional here, as first param is script name 
     286                       $arg = $args[$i]; 
     287 
     288                       if ($arg == "-help" || $arg == "-h") { 
     289                               $this->printUsage(); 
     290                               return; 
     291                       } elseif ($arg == "-version" || $arg == "-v") { 
     292                               $this->printVersion(); 
     293                               return; 
     294                       } elseif ($arg == "-quiet" || $arg == "-q") { 
     295                               self::$msgOutputLevel = Project::MSG_WARN; 
     296                       } elseif ($arg == "-verbose") { 
     297                               $this->printVersion(); 
     298                               self::$msgOutputLevel = Project::MSG_VERBOSE; 
     299                       } elseif ($arg == "-debug") { 
     300                               $this->printVersion(); 
     301                               self::$msgOutputLevel = Project::MSG_DEBUG; 
     302                       } elseif ($arg == "-logfile") { 
     303                               try { 
     304                                      // see: http://phing.info/trac/ticket/65 
     305                                       if (!isset($args[$i+1])) { 
     306                                               $msg = "You must specify a log file when using the -logfile argument\n"; 
     307                                               throw new ConfigurationException($msg); 
     308                                       } else { 
     309                                               $logFile = new PhingFile($args[++$i]); 
     310                                               $out = new FileOutputStream($logFile); // overwrite 
     311                                               self::setOutputStream($out); 
     312                                               self::setErrorStream($out); 
     313                                               self::$isLogFileUsed = true; 
     314                                       
     315                               } catch (IOException $ioe) { 
     316                                       $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions."; 
     317                                       throw new ConfigurationException($msg, $ioe); 
     318                               
     319                       } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") { 
     320                               if (!isset($args[$i+1])) { 
     321                                       $msg = "You must specify a buildfile when using the -buildfile argument."; 
     322                                       throw new ConfigurationException($msg); 
     323                               } else { 
     324                                       $this->buildFile = new PhingFile($args[++$i]); 
     325                               
     326                       } elseif ($arg == "-listener") { 
     327                               if (!isset($args[$i+1])) { 
     328                                       $msg = "You must specify a listener class when using the -listener argument"; 
     329                                       throw new ConfigurationException($msg); 
     330                               } else { 
     331                                       $this->listeners[] = $args[++$i]; 
     332                               
     333                       } elseif (StringHelper::startsWith("-D", $arg)) { 
     334                               $name = substr($arg, 2); 
     335                               $value = null; 
     336                               $posEq = strpos($name, "="); 
     337                               if ($posEq !== false) { 
     338                                       $value = substr($name, $posEq+1); 
     339                                       $name  = substr($name, 0, $posEq); 
     340                               } elseif ($i < count($args)-1) { 
     341                                       $value = $args[++$i]; 
     342                               
     343                               self::$definedProps->setProperty($name, $value); 
     344                       } elseif ($arg == "-logger") { 
     345                               if (!isset($args[$i+1])) { 
     346                                       $msg = "You must specify a classname when using the -logger argument"; 
     347                                       throw new ConfigurationException($msg); 
     348                               } else { 
     349                                       $this->loggerClassname = $args[++$i]; 
     350                               
     351                       } elseif ($arg == "-inputhandler") { 
     352                               if ($this->inputHandlerClassname !== null) { 
     353                                       throw new ConfigurationException("Only one input handler class may be specified."); 
     354                               
     355                               if (!isset($args[$i+1])) { 
     356                                       $msg = "You must specify a classname when using the -inputhandler argument"; 
     357                                       throw new ConfigurationException($msg); 
     358                               } else { 
     359                                       $this->inputHandlerClassname = $args[++$i]; 
     360                               
     361                       } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") { 
     362                               // set the flag to display the targets and quit 
     363                               $this->projectHelp = true; 
     364                       } elseif ($arg == "-find") { 
     365                               // eat up next arg if present, default to build.xml 
     366                               if ($i < count($args)-1) { 
     367                                       $this->searchForThis = $args[++$i]; 
     368                               } else { 
     369                                       $this->searchForThis = self::DEFAULT_BUILD_FILENAME; 
     370                               
     371                       } elseif (substr($arg,0,1) == "-") { 
     372                               // we don't have any more args 
    365373                                self::$err->write("Unknown argument: $arg"); 
    366                 self::printUsage(); 
    367                 return; 
    368             } else { 
    369                 // if it's no other arg, it may be the target 
    370                 array_push($this->targets, $arg); 
    371             } 
    372         } 
    373  
    374         // if buildFile was not specified on the command line, 
    375         if ($this->buildFile === null) { 
    376             // but -find then search for it 
    377             if ($this->searchForThis !== null) { 
    378                 $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis); 
    379             } else { 
    380                 $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME); 
    381             } 
    382         } 
    383         // make sure buildfile exists 
    384         if (!$this->buildFile->exists()) { 
    385             throw new BuildException("Buildfile: " . $this->buildFile->__toString() . " does not exist!"); 
    386         } 
    387  
    388         // make sure it's not a directory 
    389         if ($this->buildFile->isDirectory()) {    
    390             throw new BuildException("Buildfile: " . $this->buildFile->__toString() . " is a dir!"); 
    391         } 
    392  
    393         $this->readyToRun = true; 
    394     } 
    395  
    396     /** 
    397      * Helper to get the parent file for a given file. 
    398      * 
    399      * @param PhingFile $file 
    400      * @return PhingFile Parent file or null if none 
    401      */ 
    402     private function _getParentFile(PhingFile $file) { 
    403         $filename = $file->getAbsolutePath(); 
    404         $file     = new PhingFile($filename); 
    405         $filename = $file->getParent(); 
    406  
    407         if ($filename !== null && self::$msgOutputLevel >= Project::MSG_VERBOSE) { 
    408                 self::$out->write("Searching in $filename" . PHP_EOL); 
    409         } 
    410  
    411         return ($filename === null) ? null : new PhingFile($filename); 
    412     } 
    413  
    414     /** 
    415      * Search parent directories for the build file. 
    416      * 
    417      * Takes the given target as a suffix to append to each 
    418      * parent directory in search of a build file.  Once the 
    419      * root of the file-system has been reached an exception 
    420      * is thrown. 
    421      *  
    422      * @param string $start Start file path. 
    423      * @param string $suffix Suffix filename to look for in parents. 
    424      * @return PhingFile A handle to the build file 
    425      * 
    426      * @throws BuildException    Failed to locate a build file 
    427      */ 
    428     private function _findBuildFile($start, $suffix) { 
    429         if (self::$msgOutputLevel >= Project::MSG_INFO) { 
    430                 self::$out->write("Searching for $suffix ..." . PHP_EOL); 
    431         } 
    432         $startf = new PhingFile($start); 
    433         $parent = new PhingFile($startf->getAbsolutePath()); 
    434         $file   = new PhingFile($parent, $suffix); 
    435  
    436         // check if the target file exists in the current directory 
    437         while (!$file->exists()) { 
    438             // change to parent directory 
    439             $parent = $this->_getParentFile($parent); 
    440  
    441             // if parent is null, then we are at the root of the fs, 
    442             // complain that we can't find the build file. 
    443             if ($parent === null) { 
    444                 throw new BuildException("Could not locate a build file!"); 
    445             } 
    446             // refresh our file handle 
    447             $file = new PhingFile($parent, $suffix); 
    448         } 
    449         return $file; 
    450     } 
    451  
    452     /** 
    453      * Executes the build. 
    454      * @return void 
    455      */ 
    456     function runBuild() { 
    457  
    458         if (!$this->readyToRun) { 
    459             return; 
    460         } 
    461          
    462         $project = new Project(); 
    463                  
     374                                self::printUsage(); 
     375                                return; 
     376                        } else { 
     377                                // if it's no other arg, it may be the target 
     378                                array_push($this->targets, $arg); 
     379                        } 
     380                } 
     381 
     382                // if buildFile was not specified on the command line, 
     383                if ($this->buildFile === null) { 
     384                        // but -find then search for it 
     385                        if ($this->searchForThis !== null) { 
     386                                $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis); 
     387                        } else { 
     388                                $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME); 
     389                        } 
     390                } 
     391                // make sure buildfile exists 
     392                if (!$this->buildFile->exists()) { 
     393                        throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " does not exist!"); 
     394                } 
     395 
     396                // make sure it's not a directory 
     397                if ($this->buildFile->isDirectory()) { 
     398                        throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!"); 
     399                } 
     400 
     401                $this->readyToRun = true; 
     402        } 
     403 
     404        /** 
     405         * Helper to get the parent file for a given file. 
     406         * 
     407         * @param PhingFile $file 
     408         * @return PhingFile Parent file or null if none 
     409         */ 
     410        private function _getParentFile(PhingFile $file) { 
     411                $filename = $file->getAbsolutePath(); 
     412                $file     = new PhingFile($filename); 
     413                $filename = $file->getParent(); 
     414                return ($filename === null) ? null : new PhingFile($filename); 
     415        } 
     416 
     417        /** 
     418         * Search parent directories for the build file. 
     419         * 
     420         * Takes the given target as a suffix to append to each 
     421         * parent directory in search of a build file.  Once the 
     422         * root of the file-system has been reached an exception 
     423         * is thrown. 
     424         * 
     425         * @param string $start Start file path. 
     426         * @param string $suffix Suffix filename to look for in parents. 
     427         * @return PhingFile A handle to the build file 
     428         * 
     429         * @throws BuildException    Failed to locate a build file 
     430         */ 
     431        private function _findBuildFile($start, $suffix) { 
     432                $startf = new PhingFile($start); 
     433                $parent = new PhingFile($startf->getAbsolutePath()); 
     434                $file   = new PhingFile($parent, $suffix); 
     435 
     436                // check if the target file exists in the current directory 
     437                while (!$file->exists()) { 
     438                        // change to parent directory 
     439                        $parent = $this->_getParentFile($parent); 
     440 
     441                        // if parent is null, then we are at the root of the fs, 
     442                        // complain that we can't find the build file. 
     443                        if ($parent === null) { 
     444                                throw new ConfigurationException("Could not locate a build file!"); 
     445                        } 
     446                        // refresh our file handle 
     447                        $file = new PhingFile($parent, $suffix); 
     448                } 
     449                return $file; 
     450        } 
     451 
     452        /** 
     453         * Executes the build. 
     454         * @return void 
     455         */ 
     456        function runBuild() { 
     457 
     458                if (!$this->readyToRun) { 
     459                        return; 
     460                } 
     461 
     462                $project = new Project(); 
     463 
    464464                self::setCurrentProject($project); 
    465465                set_error_handler(array('Phing', 'handlePhpError')); 
    466                  
    467         $error = null; 
    468  
    469         $this->addBuildListeners($project); 
    470         $this->addInputHandler($project); 
    471          
    472         // set this right away, so that it can be used in logging. 
    473         $project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath()); 
    474  
    475         try { 
    476             $project->fireBuildStarted(); 
    477             $project->init(); 
    478         } catch (Exception $exc) { 
    479             $project->fireBuildFinished($exc); 
    480             throw $exc;         
    481        
    482  
    483         $project->setUserProperty("phing.version", $this->getPhingVersion()); 
    484  
    485         $e = self::$definedProps->keys(); 
    486         while (count($e)) { 
    487             $arg   = (string) array_shift($e); 
    488             $value = (string) self::$definedProps->getProperty($arg); 
    489             $project->setUserProperty($arg, $value); 
    490        
    491         unset($e); 
    492  
    493         $project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath()); 
    494  
    495         // first use the Configurator to create the project object 
    496         // from the given build file. 
    497                  
    498         try { 
    499             ProjectConfigurator::configureProject($project, $this->buildFile); 
    500         } catch (Exception $exc) { 
    501             $project->fireBuildFinished($exc); 
     466 
     467               $error = null; 
     468 
     469               $this->addBuildListeners($project); 
     470               $this->addInputHandler($project); 
     471 
     472               // set this right away, so that it can be used in logging. 
     473               $project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath()); 
     474 
     475               try { 
     476                       $project->fireBuildStarted(); 
     477                       $project->init(); 
     478               } catch (Exception $exc) { 
     479                       $project->fireBuildFinished($exc); 
     480                        throw $exc; 
     481