Changeset 287

Show
Ignore:
Timestamp:
11/04/07 14:59:39 (10 months ago)
Author:
hans
Message:

#177 - Add ConfigurationException and change handling for how those exceptions are displayed.

Files:

Legend:

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

    r123 r287  
    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; 
  • branches/2.3/classes/phing/Phing.php

    r280 r287  
    2626 
    2727include_once 'phing/BuildException.php'; 
     28include_once 'phing/ConfigurationException.php'; 
    2829include_once 'phing/BuildEvent.php'; 
    2930 
     
    164165                        $m->runBuild(); 
    165166                } catch(Exception $exc) { 
    166                         if (self::$msgOutputLevel >= Project::MSG_VERBOSE) { 
    167                                 self::$out->write($exc->__toString() . PHP_EOL); 
    168                         } else { 
    169                                 self::$out->write($exc->getMessage() . PHP_EOL); 
     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                                } 
    170173                        } 
    171174                        self::handleLogfile(); 
     
    302305                                        if (!isset($args[$i+1])) { 
    303306                                                $msg = "You must specify a log file when using the -logfile argument\n"; 
    304                                                 throw new BuildException($msg); 
     307                                                throw new ConfigurationException($msg); 
    305308                                        } else { 
    306309                                                $logFile = new PhingFile($args[++$i]); 
     
    312315                                } catch (IOException $ioe) { 
    313316                                        $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions."; 
    314                                         throw new BuildException($msg, $ioe); 
     317                                        throw new ConfigurationException($msg, $ioe); 
    315318                                } 
    316319                        } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") { 
    317320                                if (!isset($args[$i+1])) { 
    318321                                        $msg = "You must specify a buildfile when using the -buildfile argument."; 
    319                                         throw new BuildException($msg); 
     322                                        throw new ConfigurationException($msg); 
    320323                                } else { 
    321324                                        $this->buildFile = new PhingFile($args[++$i]); 
     
    324327                                if (!isset($args[$i+1])) { 
    325328                                        $msg = "You must specify a listener class when using the -listener argument"; 
    326                                         throw new BuildException($msg); 
     329                                        throw new ConfigurationException($msg); 
    327330                                } else { 
    328331                                        $this->listeners[] = $args[++$i]; 
     
    342345                                if (!isset($args[$i+1])) { 
    343346                                        $msg = "You must specify a classname when using the -logger argument"; 
    344                                         throw new BuildException($msg); 
     347                                        throw new ConfigurationException($msg); 
    345348                                } else { 
    346349                                        $this->loggerClassname = $args[++$i]; 
     
    348351                        } elseif ($arg == "-inputhandler") { 
    349352                                if ($this->inputHandlerClassname !== null) { 
    350                                         throw new BuildException("Only one input handler class may be specified."); 
     353                                        throw new ConfigurationException("Only one input handler class may be specified."); 
    351354                                } 
    352355                                if (!isset($args[$i+1])) { 
    353356                                        $msg = "You must specify a classname when using the -inputhandler argument"; 
    354                                         throw new BuildException($msg); 
     357                                        throw new ConfigurationException($msg); 
    355358                                } else { 
    356359                                        $this->inputHandlerClassname = $args[++$i]; 
     
    388391                // make sure buildfile exists 
    389392                if (!$this->buildFile->exists()) { 
    390                         throw new BuildException("Buildfile: " . $this->buildFile->__toString() . " does not exist!"); 
     393                        throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " does not exist!"); 
    391394                } 
    392395 
    393396                // make sure it's not a directory 
    394397                if ($this->buildFile->isDirectory()) { 
    395                         throw new BuildException("Buildfile: " . $this->buildFile->__toString() . " is a dir!"); 
     398                        throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!"); 
    396399                } 
    397400 
     
    439442                        // complain that we can't find the build file. 
    440443                        if ($parent === null) { 
    441                                 throw new BuildException("Could not locate a build file!"); 
     444                                throw new ConfigurationException("Could not locate a build file!"); 
    442445                        } 
    443446                        // refresh our file handle 
     
    561564                                . "class " . $listenerClassname . " : " 
    562565                                . $e->getMessage(); 
    563                                 throw new BuildException($msg); 
     566                                throw new ConfigurationException($msg); 
    564567                        } 
    565568                                 
     
    567570                                 
    568571                        if ($listener instanceof StreamRequiredBuildLogger) { 
    569                                 throw new BuildException("Unable to add " . $listenerClassname . " as a listener, since it requires explicit error/output streams. (You can specify it as a -logger.)"); 
     572                                throw new ConfigurationException("Unable to add " . $listenerClassname . " as a listener, since it requires explicit error/output streams. (You can specify it as a -logger.)"); 
    570573                        } 
    571574                        $project->addBuildListener($listener); 
     
    595598                                . "class " . $this->inputHandlerClassname . " : " 
    596599                                . $e->getMessage(); 
    597                                 throw new BuildException($msg); 
     600                                throw new ConfigurationException($msg); 
    598601                        } 
    599602                } 
     
    781784                        $phingVersion = $buffer; 
    782785                } catch (IOException $iox) { 
    783                         throw new BuildException("Can't read version information file"); 
     786                        throw new ConfigurationException("Can't read version information file"); 
    784787                } 
    785788                return $phingVersion; 
     
    977980                                $msg .= $x->getTraceAsString(); 
    978981                        } 
    979                         throw new BuildException($msg); 
     982                        throw new ConfigurationException($msg); 
    980983                } 
    981984        }