1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372 |
- <?php
- require_once 'phing/Project.php';
- require_once 'phing/ProjectComponent.php';
- require_once 'phing/Target.php';
- require_once 'phing/Task.php';
- include_once 'phing/BuildException.php';
- include_once 'phing/ConfigurationException.php';
- include_once 'phing/BuildEvent.php';
- include_once 'phing/parser/Location.php';
- include_once 'phing/parser/ExpatParser.php';
- include_once 'phing/parser/AbstractHandler.php';
- include_once 'phing/parser/ProjectConfigurator.php';
- include_once 'phing/parser/RootHandler.php';
- include_once 'phing/parser/ProjectHandler.php';
- include_once 'phing/parser/TaskHandler.php';
- include_once 'phing/parser/TargetHandler.php';
- include_once 'phing/parser/DataTypeHandler.php';
- include_once 'phing/parser/NestedElementHandler.php';
- include_once 'phing/system/util/Properties.php';
- include_once 'phing/util/StringHelper.php';
- include_once 'phing/system/io/PhingFile.php';
- include_once 'phing/system/io/OutputStream.php';
- include_once 'phing/system/io/FileOutputStream.php';
- include_once 'phing/system/io/FileReader.php';
- include_once 'phing/system/util/Register.php';
- class Phing {
-
- const DEFAULT_BUILD_FILENAME = "build.xml";
-
- private static $msgOutputLevel = Project::MSG_INFO;
-
- private $buildFile = null;
-
- private $targets = array();
-
- private static $definedProps;
-
- private $listeners = array();
- private $loggerClassname = null;
-
- private $inputHandlerClassname;
-
- private $readyToRun = false;
-
- private $projectHelp = false;
-
- private static $importPaths;
-
- private static $properties = array();
-
- private static $timer;
-
- private static $currentProject;
-
- private static $phpErrorCapture = false;
-
- private static $capturedPhpErrors = array();
-
- private static $out;
-
- private static $err;
-
- private static $isLogFileUsed = false;
-
- private static $origIniSettings = array();
-
- public static function start($args, array $additionalUserProperties = null) {
- try {
- $m = new Phing();
- $m->execute($args);
- } catch (Exception $exc) {
- self::handleLogfile();
- throw $exc;
- }
- if ($additionalUserProperties !== null) {
- foreach($additionalUserProperties as $key => $value) {
- $m->setDefinedProperty($key, $value);
- }
- }
- try {
- $m->runBuild();
- } catch(Exception $exc) {
- self::handleLogfile();
- throw $exc;
- }
-
- self::handleLogfile();
- }
-
- public static function printMessage(Exception $t) {
- if (self::$err === null) {
- self::initializeOutputStreams();
- }
- if (self::getMsgOutputLevel() >= Project::MSG_VERBOSE) {
- self::$err->write($t->__toString() . PHP_EOL);
- } else {
- self::$err->write($t->getMessage() . PHP_EOL);
- }
- }
-
- private static function initializeOutputStreams() {
- if (self::$out === null) {
- self::$out = new OutputStream(fopen("php://stdout", "w"));
- }
- if (self::$err === null) {
- self::$err = new OutputStream(fopen("php://stderr", "w"));
- }
- }
-
- public static function setOutputStream(OutputStream $stream) {
- self::$out = $stream;
- }
-
- public static function getOutputStream() {
- return self::$out;
- }
-
- public static function setErrorStream(OutputStream $stream) {
- self::$err = $stream;
- }
-
- public static function getErrorStream() {
- return self::$err;
- }
-
- private static function handleLogfile() {
- if (self::$isLogFileUsed) {
- self::$err->close();
- self::$out->close();
- }
- }
-
- public static function getMsgOutputLevel() {
- return self::$msgOutputLevel;
- }
-
- public static function fire($args) {
- self::start($args, null);
- }
-
- public function execute($args) {
- self::$definedProps = new Properties();
- $this->searchForThis = null;
-
-
- if (in_array('-help', $args) || in_array('-h', $args)) {
- $this->printUsage();
- return;
- }
- if (in_array('-version', $args) || in_array('-v', $args)) {
- $this->printVersion();
- return;
- }
-
-
- if (false !== ($key = array_search('-quiet', $args, true))) {
- self::$msgOutputLevel = Project::MSG_WARN;
- unset($args[$key]);
- }
- if (false !== ($key = array_search('-verbose', $args, true))) {
- self::$msgOutputLevel = Project::MSG_VERBOSE;
- unset($args[$key]);
- }
- if (false !== ($key = array_search('-debug', $args, true))) {
- self::$msgOutputLevel = Project::MSG_DEBUG;
- unset($args[$key]);
- }
-
-
- $keys = array_keys($args);
- $max = $keys ? max($keys) : -1;
- for($i=0; $i <= $max; $i++) {
- if (!array_key_exists($i, $args)) {
-
- continue;
- }
- $arg = $args[$i];
- if ($arg == "-logfile") {
- try {
-
- if (!isset($args[$i+1])) {
- $msg = "You must specify a log file when using the -logfile argument\n";
- throw new ConfigurationException($msg);
- } else {
- $logFile = new PhingFile($args[++$i]);
- $out = new FileOutputStream($logFile);
- self::setOutputStream($out);
- self::setErrorStream($out);
- self::$isLogFileUsed = true;
- }
- } catch (IOException $ioe) {
- $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions.";
- throw new ConfigurationException($msg, $ioe);
- }
- } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") {
- if (!isset($args[$i+1])) {
- $msg = "You must specify a buildfile when using the -buildfile argument.";
- throw new ConfigurationException($msg);
- } else {
- $this->buildFile = new PhingFile($args[++$i]);
- }
- } elseif ($arg == "-listener") {
- if (!isset($args[$i+1])) {
- $msg = "You must specify a listener class when using the -listener argument";
- throw new ConfigurationException($msg);
- } else {
- $this->listeners[] = $args[++$i];
- }
- } elseif (StringHelper::startsWith("-D", $arg)) {
- $name = substr($arg, 2);
- $value = null;
- $posEq = strpos($name, "=");
- if ($posEq !== false) {
- $value = substr($name, $posEq+1);
- $name = substr($name, 0, $posEq);
- } elseif ($i < count($args)-1 && !StringHelper::startsWith("-D", $arg)) {
- $value = $args[++$i];
- }
- self::$definedProps->setProperty($name, $value);
- } elseif ($arg == "-logger") {
- if (!isset($args[$i+1])) {
- $msg = "You must specify a classname when using the -logger argument";
- throw new ConfigurationException($msg);
- } else {
- $this->loggerClassname = $args[++$i];
- }
- } elseif ($arg == "-inputhandler") {
- if ($this->inputHandlerClassname !== null) {
- throw new ConfigurationException("Only one input handler class may be specified.");
- }
- if (!isset($args[$i+1])) {
- $msg = "You must specify a classname when using the -inputhandler argument";
- throw new ConfigurationException($msg);
- } else {
- $this->inputHandlerClassname = $args[++$i];
- }
- } elseif ($arg == "-longtargets") {
- self::$definedProps->setProperty('phing.showlongtargets', 1);
- } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") {
-
- $this->projectHelp = true;
- } elseif ($arg == "-find") {
-
- if ($i < count($args)-1) {
- $this->searchForThis = $args[++$i];
- } else {
- $this->searchForThis = self::DEFAULT_BUILD_FILENAME;
- }
- } elseif (substr($arg,0,1) == "-") {
-
- self::$err->write("Unknown argument: $arg" . PHP_EOL);
- self::printUsage();
- return;
- } else {
-
- array_push($this->targets, $arg);
- }
- }
-
- if ($this->buildFile === null) {
-
- if ($this->searchForThis !== null) {
- $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis);
- } else {
- $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME);
- }
- }
-
- if (!$this->buildFile->exists()) {
- throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " does not exist!");
- }
-
- if ($this->buildFile->isDirectory()) {
- throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!");
- }
- $this->readyToRun = true;
- }
-
- private function _getParentFile(PhingFile $file) {
- $filename = $file->getAbsolutePath();
- $file = new PhingFile($filename);
- $filename = $file->getParent();
- return ($filename === null) ? null : new PhingFile($filename);
- }
-
- private function _findBuildFile($start, $suffix) {
- $startf = new PhingFile($start);
- $parent = new PhingFile($startf->getAbsolutePath());
- $file = new PhingFile($parent, $suffix);
-
- while (!$file->exists()) {
-
- $parent = $this->_getParentFile($parent);
-
-
- if ($parent === null) {
- throw new ConfigurationException("Could not locate a build file!");
- }
-
- $file = new PhingFile($parent, $suffix);
- }
- return $file;
- }
-
- function runBuild() {
- if (!$this->readyToRun) {
- return;
- }
- $project = new Project();
- self::setCurrentProject($project);
- set_error_handler(array('Phing', 'handlePhpError'));
- $error = null;
- $this->addBuildListeners($project);
- $this->addInputHandler($project);
-
- $project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath());
- try {
- $project->fireBuildStarted();
- $project->init();
- } catch (Exception $exc) {
- $project->fireBuildFinished($exc);
- throw $exc;
- }
- $project->setUserProperty("phing.version", $this->getPhingVersion());
- $e = self::$definedProps->keys();
- while (count($e)) {
- $arg = (string) array_shift($e);
- $value = (string) self::$definedProps->getProperty($arg);
- $project->setUserProperty($arg, $value);
- }
- unset($e);
- $project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath());
-
-
- try {
- ProjectConfigurator::configureProject($project, $this->buildFile);
- } catch (Exception $exc) {
- $project->fireBuildFinished($exc);
- restore_error_handler();
- self::unsetCurrentProject();
- throw $exc;
- }
-
- if (count($this->targets) === 0) {
- $this->targets[] = $project->getDefaultTarget();
- }
-
- try {
- $this->comparePhingVersion($project->getPhingVersion());
- } catch(Exception $exc) {
- $project->fireBuildFinished($exc);
- restore_error_handler();
- self::unsetCurrentProject();
- throw $exc;
- }
-
- if (!$this->projectHelp) {
- try {
- $project->executeTargets($this->targets);
- } catch (Exception $exc) {
- $project->fireBuildFinished($exc);
- restore_error_handler();
- self::unsetCurrentProject();
- throw $exc;
- }
- }
-
- if ($this->projectHelp) {
- try {
- $this->printDescription($project);
- $this->printTargets($project);
- } catch (Exception $exc) {
- $project->fireBuildFinished($exc);
- restore_error_handler();
- self::unsetCurrentProject();
- throw $exc;
- }
- }
-
- if (!$this->projectHelp) {
- $project->fireBuildFinished(null);
- }
- restore_error_handler();
- self::unsetCurrentProject();
- }
- private function comparePhingVersion($version) {
- $current = strtolower(self::getPhingVersion());
- $current = trim(str_replace('phing', '', $current));
-
- if('dev' === $current) {
- return 1;
- }
- if(-1 == version_compare($current, $version)) {
- throw new BuildException(
- sprintf('Incompatible Phing version (%s). Version "%s" required.', $current, $version));
- }
- }
-
- private function addBuildListeners(Project $project) {
-
- $project->addBuildListener($this->createLogger());
- foreach($this->listeners as $listenerClassname) {
- try {
- $clz = Phing::import($listenerClassname);
- } catch (Exception $x) {
- $msg = "Unable to instantiate specified listener "
- . "class " . $listenerClassname . " : "
- . $e->getMessage();
- throw new ConfigurationException($msg);
- }
- $listener = new $clz();
- if ($listener instanceof StreamRequiredBuildLogger) {
- throw new ConfigurationException("Unable to add " . $listenerClassname . " as a listener, since it requires explicit error/output streams. (You can specify it as a -logger.)");
- }
- $project->addBuildListener($listener);
- }
- }
-
- private function addInputHandler(Project $project) {
- if ($this->inputHandlerClassname === null) {
- $handler = new DefaultInputHandler();
- } else {
- try {
- $clz = Phing::import($this->inputHandlerClassname);
- $handler = new $clz();
- if ($project !== null && method_exists($handler, 'setProject')) {
- $handler->setProject($project);
- }
- } catch (Exception $e) {
- $msg = "Unable to instantiate specified input handler "
- . "class " . $this->inputHandlerClassname . " : "
- . $e->getMessage();
- throw new ConfigurationException($msg);
- }
- }
- $project->setInputHandler($handler);
- }
-
- private function createLogger() {
- if ($this->loggerClassname !== null) {
- self::import($this->loggerClassname);
-
- $classname = self::import($this->loggerClassname);
- $logger = new $classname;
- if (!($logger instanceof BuildLogger)) {
- throw new BuildException($classname . ' does not implement the BuildLogger interface.');
- }
- } else {
- require_once 'phing/listener/DefaultLogger.php';
- $logger = new DefaultLogger();
- }
- $logger->setMessageOutputLevel(self::$msgOutputLevel);
- $logger->setOutputStream(self::$out);
- $logger->setErrorStream(self::$err);
- return $logger;
- }
-
- public static function setCurrentProject($p) {
- self::$currentProject = $p;
- }
-
- public static function unsetCurrentProject() {
- self::$currentProject = null;
- }
-
- public static function getCurrentProject() {
- return self::$currentProject;
- }
-
- public static function log($message, $priority = Project::MSG_INFO) {
- $p = self::getCurrentProject();
- if ($p) {
- $p->log($message, $priority);
- }
- }
-
- public static function handlePhpError($level, $message, $file, $line) {
-
- if (error_reporting() > 0) {
- if (self::$phpErrorCapture) {
- self::$capturedPhpErrors[] = array('message' => $message, 'level' => $level, 'line' => $line, 'file' => $file);
- } else {
- $message = '[PHP Error] ' . $message;
- $message .= ' [line ' . $line . ' of ' . $file . ']';
- switch ($level) {
- case 16384:
- case 8192:
- case E_STRICT:
- case E_NOTICE:
- case E_USER_NOTICE:
- self::log($message, Project::MSG_VERBOSE);
- break;
- case E_WARNING:
- case E_USER_WARNING:
- self::log($message, Project::MSG_WARN);
- break;
- case E_ERROR:
- case E_USER_ERROR:
- default:
- self::log($message, Project::MSG_ERR);
- }
- }
- }
- }
-
- public static function startPhpErrorCapture() {
- self::$phpErrorCapture = true;
- self::$capturedPhpErrors = array();
- }
-
- public static function stopPhpErrorCapture() {
- self::$phpErrorCapture = false;
- }
-
- public static function clearCapturedPhpErrors() {
- self::$capturedPhpErrors = array();
- }
-
- public static function getCapturedPhpErrors() {
- return self::$capturedPhpErrors;
- }
-
- public static function printUsage() {
- $msg = "";
- $msg .= "phing [options] [target [target2 [target3] ...]]" . PHP_EOL;
- $msg .= "Options: " . PHP_EOL;
- $msg .= " -h -help print this message" . PHP_EOL;
- $msg .= " -l -list list available targets in this project" . PHP_EOL;
- $msg .= " -v -version print the version information and exit" . PHP_EOL;
- $msg .= " -q -quiet be extra quiet" . PHP_EOL;
- $msg .= " -verbose be extra verbose" . PHP_EOL;
- $msg .= " -debug print debugging information" . PHP_EOL;
- $msg .= " -longtargets show target descriptions during build" . PHP_EOL;
- $msg .= " -logfile <file> use given file for log" . PHP_EOL;
- $msg .= " -logger <classname> the class which is to perform logging" . PHP_EOL;
- $msg .= " -f -buildfile <file> use given buildfile" . PHP_EOL;
- $msg .= " -D<property>=<value> use value for given property" . PHP_EOL;
- $msg .= " -find <file> search for buildfile towards the root of the" . PHP_EOL;
- $msg .= " filesystem and use it" . PHP_EOL;
- $msg .= " -inputhandler <file> the class to use to handle user input" . PHP_EOL;
-
- $msg .= PHP_EOL;
- $msg .= "Report bugs to <dev@phing.tigris.org>".PHP_EOL;
- self::$err->write($msg);
- }
-
- public static function printVersion() {
- self::$out->write(self::getPhingVersion().PHP_EOL);
- }
-
- public static function getPhingVersion() {
- $versionPath = self::getResourcePath("phing/etc/VERSION.TXT");
- if ($versionPath === null) {
- $versionPath = self::getResourcePath("etc/VERSION.TXT");
- }
- if ($versionPath === null) {
- throw new ConfigurationException("No VERSION.TXT file found; try setting phing.home environment variable.");
- }
- try {
- $buffer = null;
- $file = new PhingFile($versionPath);
- $reader = new FileReader($file);
- $reader->readInto($buffer);
- $buffer = trim($buffer);
-
- $phingVersion = $buffer;
- } catch (IOException $iox) {
- throw new ConfigurationException("Can't read version information file");
- }
- return $phingVersion;
- }
-
- public static function printDescription(Project $project) {
- if ($project->getDescription() !== null) {
- self::$out->write($project->getDescription() . PHP_EOL);
- }
- }
-
- function printTargets($project) {
-
- $maxLength = 0;
- $targets = $project->getTargets();
- $targetNames = array_keys($targets);
- $targetName = null;
- $targetDescription = null;
- $currentTarget = null;
-
-
- $subNames = array();
- $topNameDescMap = array();
- foreach($targets as $currentTarget) {
- $targetName = $currentTarget->getName();
- $targetDescription = $currentTarget->getDescription();
-
- if ($targetDescription === null) {
- $subNames[] = $targetName;
- } else {
-
-
- $topNameDescMap[$targetName] = $targetDescription;
- if (strlen($targetName) > $maxLength) {
- $maxLength = strlen($targetName);
- }
- }
- }
-
- sort($subNames);
- ksort($topNameDescMap);
- $topNames = array_keys($topNameDescMap);
- $topDescriptions = array_values($topNameDescMap);
- $defaultTarget = $project->getDefaultTarget();
- if ($defaultTarget !== null && $defaultTarget !== "") {
- $defaultName = array();
- $defaultDesc = array();
- $defaultName[] = $defaultTarget;
- $indexOfDefDesc = array_search($defaultTarget, $topNames, true);
- if ($indexOfDefDesc !== false && $indexOfDefDesc >= 0) {
- $defaultDesc = array();
- $defaultDesc[] = $topDescriptions[$indexOfDefDesc];
- }
- $this->_printTargets($defaultName, $defaultDesc, "Default target:", $maxLength);
- }
- $this->_printTargets($topNames, $topDescriptions, "Main targets:", $maxLength);
- $this->_printTargets($subNames, null, "Subtargets:", 0);
- }
-
- private function _printTargets($names, $descriptions, $heading, $maxlen) {
- $spaces = ' ';
- while (strlen($spaces) < $maxlen) {
- $spaces .= $spaces;
- }
- $msg = "";
- $msg .= $heading . PHP_EOL;
- $msg .= str_repeat("-",79) . PHP_EOL;
- $total = count($names);
- for($i=0; $i < $total; $i++) {
- $msg .= " ";
- $msg .= $names[$i];
- if (!empty($descriptions)) {
- $msg .= substr($spaces, 0, $maxlen - strlen($names[$i]) + 2);
- $msg .= $descriptions[$i];
- }
- $msg .= PHP_EOL;
- }
- if ($total > 0) {
- self::$out->write($msg . PHP_EOL);
- }
- }
-
- public static function import($dotPath, $classpath = null) {
-
- if (strpos($dotPath, '.') === false && strpos($dotPath, '_') !== false) {
- $classname = $dotPath;
- $dotPath = str_replace('_', '.', $dotPath);
- } else {
- $classname = StringHelper::unqualify($dotPath);
- }
-
-
-
- if (class_exists($classname, false)) {
- return $classname;
- }
- $dotClassname = basename($dotPath);
- $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
-
- $tmp = str_replace('\.', '##', $dotClassname);
-
- $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
-
- $tmp = str_replace('##', '.', $tmp);
- $classFile = $tmp . ".php";
- $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
- Phing::__import($path, $classpath);
- return $classname;
- }
-
- public static function __import($path, $classpath = null) {
- if ($classpath) {
-
- if (is_object($classpath)) {
- $classpath = $classpath->__toString();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- $curr_parts = explode(PATH_SEPARATOR, get_include_path());
- $add_parts = explode(PATH_SEPARATOR, $classpath);
- $new_parts = array_diff($add_parts, $curr_parts);
- if ($new_parts) {
- set_include_path(implode(PATH_SEPARATOR, array_merge($new_parts, $curr_parts)));
- }
- }
-
- $ret = include_once($path);
- if ($ret === false) {
- $msg = "Error importing $path";
- if (self::getMsgOutputLevel() >= Project::MSG_DEBUG) {
- $x = new Exception("for-path-trace-only");
- $msg .= $x->getTraceAsString();
- }
- throw new ConfigurationException($msg);
- }
- }
-
- public static function getResourcePath($path) {
- if (self::$importPaths === null) {
- $paths = get_include_path();
- self::$importPaths = explode(PATH_SEPARATOR, ini_get("include_path"));
- }
- $path = str_replace('\\', DIRECTORY_SEPARATOR, $path);
- $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
- foreach (self::$importPaths as $prefix) {
- $testPath = $prefix . DIRECTORY_SEPARATOR . $path;
- if (file_exists($testPath)) {
- return $testPath;
- }
- }
-
- $homeDir = self::getProperty('phing.home');
- if ($homeDir) {
- $testPath = $homeDir . DIRECTORY_SEPARATOR . $path;
- if (file_exists($testPath)) {
- return $testPath;
- }
- }
-
-
-
- $dataDir = '/usr/share/php/data';
- if ($dataDir{0} != '@') {
- $testPath = $dataDir . DIRECTORY_SEPARATOR . $path;
- if (file_exists($testPath)) {
- return $testPath;
- }
- } else {
-
-
- $maybeHomeDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
- $testPath = $maybeHomeDir . DIRECTORY_SEPARATOR . $path;
- if (file_exists($testPath)) {
- return $testPath;
- }
- }
- return null;
- }
-
-
-
-
- private static function setSystemConstants() {
-
- self::setProperty('host.os', PHP_OS);
-
- self::setProperty('os.name', PHP_OS);
-
-
-
- if (!defined('PHP_CLASSPATH')) {
- define('PHP_CLASSPATH', get_include_path());
- }
- self::setProperty('php.classpath', PHP_CLASSPATH);
-
-
-
- switch (strtoupper(PHP_OS)) {
- case 'WINNT':
- self::setProperty('host.fstype', 'WINNT');
- self::setProperty('php.interpreter', getenv('PHP_COMMAND'));
- break;
- case 'WIN32':
- self::setProperty('host.fstype', 'WIN32');
- break;
- default:
- self::setProperty('host.fstype', 'UNIX');
- break;
- }
- self::setProperty('line.separator', PHP_EOL);
- self::setProperty('php.version', PHP_VERSION);
- self::setProperty('user.home', getenv('HOME'));
- self::setProperty('application.startdir', getcwd());
- self::setProperty('phing.startTime', gmdate('D, d M Y H:i:s', time()) . ' GMT');
-
- $sysInfo = array();
- if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && function_exists("posix_uname")) {
- $sysInfo = posix_uname();
- } else {
- $sysInfo['nodename'] = php_uname('n');
- $sysInfo['machine']= php_uname('m') ;
-
- $sysInfo['domain'] = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : "unknown";
- $sysInfo['release'] = php_uname('r');
- $sysInfo['version'] = php_uname('v');
- }
- self::setProperty("host.name", isset($sysInfo['nodename']) ? $sysInfo['nodename'] : "unknown");
- self::setProperty("host.arch", isset($sysInfo['machine']) ? $sysInfo['machine'] : "unknown");
- self::setProperty("host.domain",isset($sysInfo['domain']) ? $sysInfo['domain'] : "unknown");
- self::setProperty("host.os.release", isset($sysInfo['release']) ? $sysInfo['release'] : "unknown");
- self::setProperty("host.os.version", isset($sysInfo['version']) ? $sysInfo['version'] : "unknown");
- unset($sysInfo);
- }
-
- public static function getDefinedProperty($name) {
- return self::$definedProps->getProperty($name);
- }
-
- public static function setDefinedProperty($name, $value) {
- return self::$definedProps->setProperty($name, $value);
- }
-
- public static function getProperty($propName) {
-
-
-
- $val = isset(self::$properties[$propName]) ? self::$properties[$propName] : null;
-
- switch($propName) {
- case 'user.dir':
- $val = getcwd();
- break;
- }
- return $val;
- }
-
- public static function &getProperties() {
- return self::$properties;
- }
- public static function setProperty($propName, $propValue) {
- $propName = (string) $propName;
- $oldValue = self::getProperty($propName);
- self::$properties[$propName] = $propValue;
- return $oldValue;
- }
- public static function currentTimeMillis() {
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
-
- private static function setIncludePaths() {
- if (defined('PHP_CLASSPATH')) {
- $result = set_include_path(PHP_CLASSPATH);
- if ($result === false) {
- throw new ConfigurationException("Could not set PHP include_path.");
- }
- self::$origIniSettings['include_path'] = $result;
- }
- }
-
- private static function setIni() {
- self::$origIniSettings['error_reporting'] = error_reporting(E_ALL);
-
-
-
-
- set_time_limit(0);
- self::$origIniSettings['magic_quotes_gpc'] = ini_set('magic_quotes_gpc', 'off');
- self::$origIniSettings['short_open_tag'] = ini_set('short_open_tag', 'off');
- self::$origIniSettings['default_charset'] = ini_set('default_charset', 'iso-8859-1');
- self::$origIniSettings['register_globals'] = ini_set('register_globals', 'off');
- self::$origIniSettings['allow_call_time_pass_reference'] = ini_set('allow_call_time_pass_reference', 'on');
- self::$origIniSettings['track_errors'] = ini_set('track_errors', 1);
-
- $mem_limit = (int) ini_get('memory_limit');
- if ($mem_limit < 32 && $mem_limit > -1) {
-
-
- ini_set('memory_limit', '32M');
- }
- }
-
- private static function restoreIni()
- {
- foreach(self::$origIniSettings as $settingName => $settingValue) {
- switch($settingName) {
- case 'error_reporting':
- error_reporting($settingValue);
- break;
- default:
- ini_set($settingName, $settingValue);
- }
- }
- }
-
- public static function getTimer() {
- if (self::$timer === null) {
- include_once 'phing/system/util/Timer.php';
- self::$timer= new Timer();
- }
- return self::$timer;
- }
-
- public static function startup() {
-
- self::initializeOutputStreams();
-
- self::getTimer()->start();
- self::setSystemConstants();
- self::setIncludePaths();
- self::setIni();
- }
-
- public static function halt() {
- self::shutdown();
- }
-
- public static function shutdown() {
- self::restoreIni();
- self::getTimer()->stop();
- }
- }
|