Changeset 322

Show
Ignore:
Timestamp:
12/20/07 03:00:35 (7 months ago)
Author:
hans
Message:

Refs #201 - (IN PROGRESS!) Checking in in-progress work to improve Phing's ability to be embedded in other applications. ERROR HANDLING HAS NOT BEEN FULLY TESTED WITH THIS CHANGESET.

Files:

Legend:

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

    r123 r322  
    1111// --------------------------- 
    1212 
    13 ini_set('track_errors', 1); 
    14  
    1513/* set classpath */ 
    1614if (getenv('PHP_CLASSPATH')) { 
     
    2321require_once 'phing/Phing.php'; 
    2422 
    25 /* Setup Phing environment */ 
    26 Phing::startup(); 
     23try { 
     24         
     25        /* Setup Phing environment */ 
     26        Phing::startup(); 
    2727 
    28 /*  
    29   find phing home directory  
    30    -- if Phing is installed from PEAR this will probably be null, 
    31    which is fine (I think).  Nothing uses phing.home right now. 
    32 */ 
    33 Phing::setProperty('phing.home', getenv('PHING_HOME')); 
     28        // Set phing.home property to the value from environment 
     29        // (this may be NULL, but that's not a big problem.)  
     30        Phing::setProperty('phing.home', getenv('PHING_HOME')); 
    3431 
    35  
    36 /* polish CLI arguments */ 
    37 $args = isset($argv) ? $argv : $_SERVER['argv']; // $_SERVER['argv'] seems not to work when argv is registered (PHP5b4) 
    38 array_shift($args); // 1st arg is script name, so drop it 
    39  
    40 /* fire main application */ 
    41 Phing::fire($args); 
    42  
    43 /* 
    44   exit OO system if not already called by Phing 
    45    -- basically we should not need this due to register_shutdown_function in Phing 
    46  */ 
    47  Phing::halt(0); 
     32        // Grab and clean up the CLI arguments 
     33        $args = isset($argv) ? $argv : $_SERVER['argv']; // $_SERVER['argv'] seems not to work when argv is registered (PHP5b4) 
     34        array_shift($args); // 1st arg is script name, so drop it 
     35         
     36        // Invoke the commandline entry point 
     37        Phing::fire($args); 
     38         
     39        // Invoke any shutdown routines. 
     40        Phing::shutdown(); 
     41         
     42} catch (Exception $x) { 
     43        // There was a problem; it should have already been reported as part of the build 
     44        // results, so we just need to return the result code. 
     45        if ($x->getCode() != 0) { 
     46                exit($x->getCode()); 
     47        } else { 
     48                exit(1); 
     49        } 
     50
    4851 
    4952?> 
  • branches/2.3/classes/phing/Phing.php

    r295 r322  
    137137         * @param array $additionalUserProperties   Any additional properties to be passed to Phing (alternative front-end might implement this). 
    138138         *                                          These additional properties will be available using the getDefinedProperty() method and will 
    139          *                                          be added to the project's "user" properties. 
    140          * @return void 
     139         *                                          be added to the project's "user" properties 
    141140         * @see execute() 
    142141         * @see runBuild() 
     142         * @throws Exception - if there is an error during build 
    143143         */ 
    144144        public static function start(&$args, $additionalUserProperties = null) { 
     
    150150                        self::handleLogfile(); // clean up log file before attempting to print message 
    151151                        $m->printMessage($exc); 
    152                         self::halt(-1); // Parameter error 
     152                        throw $exc; 
    153153                } 
    154154 
     
    173173                        } 
    174174                        self::handleLogfile(); 
    175                         self::halt(1); // Errors occured 
     175                        throw $exc; 
    176176                } 
    177177 
    178178                // everything fine, shutdown 
    179179                self::handleLogfile(); 
    180                 self::halt(0); 
    181180        } 
    182181 
     
    371370                        } elseif (substr($arg,0,1) == "-") { 
    372371                                // we don't have any more args 
    373                                 self::$err->write("Unknown argument: $arg"); 
     372                                self::$err->write("Unknown argument: $arg" . PHP_EOL); 
    374373                                self::printUsage(); 
    375374                                return; 
     
    776775                        $versionPath = self::getResourcePath("etc/VERSION.TXT"); 
    777776                } 
     777                if ($versionPath === null) { 
     778                        throw new ConfigurationException("No VERSION.TXT file found; try setting phing.home environment variable."); 
     779                } 
    778780                try { // try to read file 
    779781                        $buffer = null; 
     
    10001002 
    10011003                foreach (self::$importPaths as $prefix) { 
    1002                         $foo_path = $prefix . DIRECTORY_SEPARATOR . $path; 
    1003                         if (file_exists($foo_path)) { 
    1004                                 return $foo_path; 
     1004                        $testPath = $prefix . DIRECTORY_SEPARATOR . $path; 
     1005                        if (file_exists($testPath)) { 
     1006                                return $testPath; 
    10051007                        } 
    10061008                } 
    10071009 
    10081010                // Check for the property phing.home 
    1009                 $home_dir = self::getProperty('phing.home'); 
    1010  
    1011                 if ($home_dir) 
    1012                 { 
    1013                         $home_path = $home_dir . DIRECTORY_SEPARATOR . $path; 
    1014  
    1015                         if (file_exists($home_path)) 
    1016                         { 
    1017                                 return $home_path; 
     1011                $homeDir = self::getProperty('phing.home'); 
     1012                if ($homeDir) { 
     1013                        $testPath = $homeDir . DIRECTORY_SEPARATOR . $path; 
     1014                        if (file_exists($testPath)) { 
     1015                                return $testPath; 
    10181016                        } 
    10191017                } 
     
    10221020                // This is a bit of a hack, but works better than previous solution of assuming 
    10231021                // data_dir is on the include_path. 
    1024                 $data_dir = '@DATA-DIR@'; 
    1025                 if ($data_dir{0} != '@') { // if we're using PEAR then the @ DATA-DIR @ token will have been substituted. 
    1026                         $data_path = $data_dir . DIRECTORY_SEPARATOR . $path; 
    1027                         if (file_exists($data_path)) { 
    1028                                 return $data_path; 
     1022                $dataDir = '@DATA-DIR@'; 
     1023                if ($dataDir{0} != '@') { // if we're using PEAR then the @ DATA-DIR @ token will have been substituted. 
     1024                        $testPath = $dataDir . DIRECTORY_SEPARATOR . $path; 
     1025                        if (file_exists($testPath)) { 
     1026                                return $testPath; 
     1027                        } 
     1028                } else { 
     1029                        // We're not using PEAR, so do one additional check based on path of  
     1030                        // current file (Phing.php) 
     1031                        $maybeHomeDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR  . '..'); 
     1032                        $testPath = $maybeHomeDir . DIRECTORY_SEPARATOR . $path;  
     1033                        if (file_exists($testPath)) { 
     1034                                return $testPath; 
    10291035                        } 
    10301036                } 
     
    11811187         * Sets the include path based on PHP_CLASSPATH constant (set in phing.php). 
    11821188         * @return void 
     1189         * @throws BuildException - if the include_path could not be set (for some bizarre reason) 
    11831190         */ 
    11841191        private static function setIncludePaths() { 
     
    11931200 
    11941201                if ($success === false) { 
    1195                         self::$err->write("SYSTEM FAILURE: Could not set PHP include path"); 
    1196                         self::halt(-1); 
     1202                        throw new BuildException("Could not set PHP include path"); 
    11971203                } 
    11981204        } 
     
    12101216                ini_set('register_globals', 'off'); 
    12111217                ini_set('allow_call_time_pass_reference', 'on'); 
    1212  
     1218                ini_set('track_errors', 1); 
     1219                 
    12131220                // should return memory limit in MB 
    12141221                $mem_limit = (int) ini_get('memory_limit'); 
     
    12641271        public static function shutdown($exitcode = 0) { 
    12651272                self::getTimer()->stop(); 
    1266                 exit($exitcode); // final point where everything stops 
     1273                //exit($exitcode); // final point where everything stops 
    12671274        } 
    12681275 
  • branches/2.3/classes/phing/parser/AbstractSAXParser.php

    r186 r322  
    2828 * @author    Andreas Aderhold <andi@binarycloud.com> 
    2929 * @author    Hans Lellelid <hans@xmpl.org> 
    30  * @copyright © 2001,2002 THYRELL. All rights reserved 
     30 * @copyright ᅵ 2001,2002 THYRELL. All rights reserved 
    3131 * @version   $Revision: 1.13 $ 
    3232 * @package   phing.parser 
     
    6666     * <code>startElement()</code> method. 
    6767     *  
    68      * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS 
    69      * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION. 
    70      * 
    7168     * @param  object  the php's internal parser handle 
    7269     * @param  string  the open tag name 
    7370     * @param  array   the tag's attributes if any 
     71     * @throws Exception - Exceptions may be thrown by the Handler 
    7472     */ 
    7573    function startElement($parser, $name, $attribs) { 
    76         try { 
    77             $this->handler->startElement($name, $attribs);         
    78         } catch (Exception $e) { 
    79             print "[Exception in XML parsing]\n"; 
    80             print $e; 
    81             Phing::halt(-1); 
    82         } 
     74        $this->handler->startElement($name, $attribs); 
    8375    } 
    8476 
     
    9284     * <code>endElement()</code> method. 
    9385     * 
    94      * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS 
    95      * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION. 
    96      *  
    9786     * @param   object  the php's internal parser handle 
    9887     * @param   string  the closing tag name 
     88     * @throws Exception - Exceptions may be thrown by the Handler 
    9989     */ 
    10090    function endElement($parser, $name) { 
    101         try { 
    102             $this->handler->endElement($name); 
    103         } catch (Exception $e) { 
    104             print "[Exception in XML parsing]\n"; 
    105             print $e; 
    106             Phing::halt(-1); 
    107         } 
     91        $this->handler->endElement($name); 
    10892    } 
    10993 
     
    117101     * <code>characters()</code> method. That processes the given CDATA. 
    118102     * 
    119      * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS 
    120      * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION. 
    121      *  
    122103     * @param resource $parser php's internal parser handle. 
    123104     * @param string $data the CDATA 
     105     * @throws Exception - Exceptions may be thrown by the Handler 
    124106     */ 
    125107    function characters($parser, $data) { 
    126         try {      
    127             $this->handler->characters($data);         
    128         } catch (Exception $e) { 
    129             print "[Exception in XML parsing]\n"; 
    130             print $e; 
    131             Phing::halt(-1); 
    132         } 
     108                $this->handler->characters($data); 
    133109    } 
    134110