Changeset 323
- Timestamp:
- 12/20/07 15:13:19 (7 months ago)
- Files:
-
- branches/2.3/bin/phing.php (modified) (3 diffs)
- branches/2.3/classes/phing/Phing.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.3/bin/phing.php
r322 r323 13 13 /* set classpath */ 14 14 if (getenv('PHP_CLASSPATH')) { 15 define('PHP_CLASSPATH', getenv('PHP_CLASSPATH') . PATH_SEPARATOR . get_include_path());15 if (!defined('PHP_CLASSPATH')) { define('PHP_CLASSPATH', getenv('PHP_CLASSPATH') . PATH_SEPARATOR . get_include_path()); } 16 16 ini_set('include_path', PHP_CLASSPATH); 17 17 } else { 18 define('PHP_CLASSPATH', get_include_path());18 if (!defined('PHP_CLASSPATH')) { define('PHP_CLASSPATH', get_include_path()); } 19 19 } 20 20 … … 31 31 32 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)33 $args = isset($argv) ? $argv : $_SERVER['argv']; // $_SERVER['argv'] seems to not work (sometimes?) when argv is registered 34 34 array_shift($args); // 1st arg is script name, so drop it 35 35 … … 40 40 Phing::shutdown(); 41 41 42 } catch (ConfigurationException $x) { 43 44 Phing::printMessage($x); 45 exit(-1); // This was convention previously for configuration errors. 46 42 47 } 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 } 48 49 // Assume the message was already printed as part of the build and 50 // exit with non-0 error code. 51 52 exit(1); 53 50 54 } 51 55 branches/2.3/classes/phing/Phing.php
r322 r323 128 128 */ 129 129 private static $isLogFileUsed = false; 130 131 /** 132 * Array to hold original ini settings that Phing changes (and needs 133 * to restore in restoreIni() method). 134 * 135 * @var array Struct of array(setting-name => setting-value) 136 * @see restoreIni() 137 */ 138 private static $origIniSettings = array(); 130 139 131 140 /** … … 134 143 * This method encapsulates the complete build lifecycle. 135 144 * 136 * @param array &$args The commandline args passed to phing shell script.145 * @param array $args The commandline args passed to phing shell script. 137 146 * @param array $additionalUserProperties Any additional properties to be passed to Phing (alternative front-end might implement this). 138 147 * These additional properties will be available using the getDefinedProperty() method and will … … 142 151 * @throws Exception - if there is an error during build 143 152 */ 144 public static function start( &$args, $additionalUserProperties = null) {145 153 public static function start($args, $additionalUserProperties = null) { 154 146 155 try { 147 156 $m = new Phing(); 148 157 $m->execute($args); 149 158 } catch (Exception $exc) { 150 self::handleLogfile(); // clean up log file before attempting to print message 151 $m->printMessage($exc); 159 self::handleLogfile(); 152 160 throw $exc; 153 161 } … … 165 173 $m->runBuild(); 166 174 } 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 175 self::handleLogfile(); 175 176 throw $exc; … … 185 186 */ 186 187 public static function printMessage(Exception $t) { 187 if (self::getMsgOutputLevel() <= Project::MSG_DEBUG) { 188 self::$err->write($t->__toString()); 188 if (self::$err === null) { // Make sure our error output is initialized 189 self::initializeOutputStreams(); 190 } 191 if (self::getMsgOutputLevel() >= Project::MSG_VERBOSE) { 192 self::$err->write($t->__toString() . PHP_EOL); 189 193 } else { 190 self::$err->write($t->getMessage() );194 self::$err->write($t->getMessage() . PHP_EOL); 191 195 } 192 196 } … … 279 283 self::$definedProps = new Properties(); 280 284 $this->searchForThis = null; 281 282 // cycle through given args 283 for ($i = 0, $argcount = count($args); $i < $argcount; ++$i) { 284 // ++$i intentional here, as first param is script name 285 $arg = $args[$i]; 286 287 if ($arg == "-help" || $arg == "-h") { 288 $this->printUsage(); 289 return; 290 } elseif ($arg == "-version" || $arg == "-v") { 291 $this->printVersion(); 292 return; 293 } elseif ($arg == "-quiet" || $arg == "-q") { 294 self::$msgOutputLevel = Project::MSG_WARN; 295 } elseif ($arg == "-verbose") { 296 $this->printVersion(); 297 self::$msgOutputLevel = Project::MSG_VERBOSE; 298 } elseif ($arg == "-debug") { 299 $this->printVersion(); 300 self::$msgOutputLevel = Project::MSG_DEBUG; 301 } elseif ($arg == "-logfile") { 285 286 // 1) First handle any options which should always 287 // Note: The order in which these are executed is important (if multiple of these options are specified) 288 289 if (in_array('-help', $args) || in_array('-h', $args)) { 290 $this->printUsage(); 291 return; 292 } 293 294 if (in_array('-version', $args) || in_array('-v', $args)) { 295 $this->printVersion(); 296 return; 297 } 298 299 // 2) Next pull out stand-alone args. 300 // Note: The order in which these are executed is important (if multiple of these options are specified) 301 302 if (false !== ($key = array_search('-quiet', $args, true))) { 303 self::$msgOutputLevel = Project::MSG_WARN; 304 unset($args[$key]); 305 } 306 307 if (false !== ($key = array_search('-verbose', $args, true))) { 308 self::$msgOutputLevel = Project::MSG_VERBOSE; 309 unset($args[$key]); 310 } 311 312 if (false !== ($key = array_search('-debug', $args, true))) { 313 self::$msgOutputLevel = Project::MSG_DEBUG; 314 unset($args[$key]); 315 } 316 317 // 3) Finally, cycle through to parse remaining args 318 foreach ($args as $i => $arg) { 319 320 if ($arg == "-logfile") { 302 321 try { 303 322 // see: http://phing.info/trac/ticket/65 … … 1185 1204 1186 1205 /** 1187 * Sets the include path based on PHP_CLASSPATH constant (set in phing.php).1206 * Sets the include path to PHP_CLASSPATH constant (if this has been defined). 1188 1207 * @return void 1189 * @throws BuildException - if the include_path could not be set (for some bizarre reason)1208 * @throws ConfigurationException - if the include_path could not be set (for some bizarre reason) 1190 1209 */ 1191 1210 private static function setIncludePaths() { 1192 $success = false;1193 1194 1211 if (defined('PHP_CLASSPATH')) { 1195 $success = set_include_path(PHP_CLASSPATH); 1196 } else { 1197 // don't do anything, just assume that include_path has been properly set. 1198 $success = true; 1199 } 1200 1201 if ($success === false) { 1202 throw new BuildException("Could not set PHP include path"); 1212 $result = set_include_path(PHP_CLASSPATH); 1213 if ($result === false) { 1214 throw new ConfigurationException("Could not set PHP include_path."); 1215 } 1216 self::$origIniSettings['include_path'] = $result; // save original value for setting back later 1203 1217 } 1204 1218 } … … 1209 1223 */ 1210 1224 private static function setIni() { 1211 error_reporting(E_ALL); 1225 1226 self::$origIniSettings['error_reporting'] = error_reporting(E_ALL); 1227 1228 // We won't bother storing original max_execution_time, since 1) the value in 1229 // php.ini may be wrong (and there's no way to get the current value) and 1230 // 2) it would mean something very strange to set it to a value less than time script 1231 // has already been running, which would be the likely change. 1232 1212 1233 set_time_limit(0); 1213 ini_set('magic_quotes_gpc', 'off'); 1214 ini_set('short_open_tag', 'off'); 1215 ini_set('default_charset', 'iso-8859-1'); 1216 ini_set('register_globals', 'off'); 1217 ini_set('allow_call_time_pass_reference', 'on'); 1218 ini_set('track_errors', 1); 1234 1235 self::$origIniSettings['magic_quotes_gpc'] = ini_set('magic_quotes_gpc', 'off'); 1236 self::$origIniSettings['short_open_tag'] = ini_set('short_open_tag', 'off'); 1237 self::$origIniSettings['default_charset'] = ini_set('default_charset', 'iso-8859-1'); 1238 self::$origIniSettings['register_globals'] = ini_set('register_globals', 'off'); 1239 self::$origIniSettings['allow_call_time_pass_reference'] = ini_set('allow_call_time_pass_reference', 'on'); 1240 self::$origIniSettings['track_errors'] = ini_set('track_errors', 1); 1219 1241 1220 1242 // should return memory limit in MB 1221 1243 $mem_limit = (int) ini_get('memory_limit'); 1222 1244 if ($mem_limit < 32) { 1245 // We do *not* need to save the original value here, since we don't plan to restore 1246 // this after shutdown (we don't trust the effectiveness of PHP's garbage collection). 1223 1247 ini_set('memory_limit', '32M'); // nore: this may need to be higher for many projects 1248 } 1249 } 1250 1251 /** 1252 * Restores [most] PHP INI values to their pre-Phing state. 1253 * 1254 * Currently the following settings are not restored: 1255 * - max_execution_time (because getting current time limit is not possible) 1256 * - memory_limit (which may have been increased by Phing) 1257 * 1258 * @return void 1259 */ 1260 private static function restoreIni() 1261 { 1262 foreach(self::$origIniSettings as $settingName => $settingValue) { 1263 switch($settingName) { 1264 case 'error_reporting': 1265 error_reporting($settingValue); 1266 break; 1267 default: 1268 ini_set($settingName, $settingValue); 1269 } 1224 1270 } 1225 1271 } … … 1239 1285 /** 1240 1286 * Start up Phing. 1241 * Sets up the Phing environment -- does NOTinitiate the build process.1287 * Sets up the Phing environment but does not initiate the build process. 1242 1288 * @return void 1289 * @throws Exception - If the Phing environment cannot be initialized. 1243 1290 */ 1244 1291 public static function startup() { 1245 1246 register_shutdown_function(array('Phing', 'shutdown'));1247 1292 1248 1293 // setup STDOUT and STDERR defaults … … 1259 1304 /** 1260 1305 * Halts the system. 1306 * @deprecated This method is deprecated and is no longer called by Phing internally. Any 1307 * normal shutdown routines are handled by the shutdown() method. 1261 1308 * @see shutdown() 1262 1309 */ 1263 public static function halt( $code=0) {1264 self::shutdown( $code);1265 } 1266 1267 /** 1268 * Stops timers & exits.1310 public static function halt() { 1311 self::shutdown(); 1312 } 1313 1314 /** 1315 * Performs any shutdown routines, such as stopping timers. 1269 1316 * @return void 1270 1317 */ 1271 public static function shutdown($exitcode = 0) { 1318 public static function shutdown() { 1319 self::restoreIni(); 1272 1320 self::getTimer()->stop(); 1273 //exit($exitcode); // final point where everything stops1274 1321 } 1275 1322
