public static function call_phing($task, $target, $build_file = '', $options = array()) { $args = array(); foreach ($options as $key => $value) { $args[] = "-D{$key}={$value}"; } if ($build_file) { $args[] = '-f'; $args[] = realpath($build_file); } if (!$task->is_verbose()) { $args[] = '-q'; } if (is_array($target)) { $args = array_merge($args, $target); } else { $args[] = $target; } if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) { $args[] = '-logger'; $args[] = 'phing.listener.AnsiColorLogger'; } Phing::startup(); Phing::setProperty('phing.home', getenv('PHING_HOME')); $m = new pakePhing(); $m->execute($args); $m->runBuild(); }
public function setUp() { Phing::startup(); $this->project = $this->getMockBuilder('Project')->setMethods(array('getBasedir'))->getMock(); $this->task = new GuessExtensionKeyTask(); $this->task->setProject($this->project); }
/** * @dataProvider fileSystemMappingsDataProvider */ public function testGetFileSystemReturnsCorrect($expectedFileSystemClass, $fsTypeKey) { $this->_resetFileSystem(); Phing::setProperty('host.fstype', $fsTypeKey); $system = FileSystem::getFileSystem(); $this->assertInstanceOf($expectedFileSystemClass, $system); }
function targetFinished(BuildEvent $event) { $msg .= PHP_EOL . "Target time: " . self::formatTime(Phing::currentTimeMillis() - $this->targetStartTime) . PHP_EOL; $event->setMessage($msg, Project::MSG_INFO); $this->messageLogged($event); $this->targetName = null; }
public static function call_phing($task, $target, $build_file = '', $options = array()) { $args = array(); foreach ($options as $key => $value) { $args[] = "-D{$key}={$value}"; } if ($build_file) { $args[] = '-f'; $args[] = realpath($build_file); } if (!$task->is_verbose()) { $args[] = '-q'; } if (is_array($target)) { $args = array_merge($args, $target); } else { $args[] = $target; } Phing::startup(); Phing::setProperty('phing.home', getenv('PHING_HOME')); ob_start(array('pakePhingTask', 'colorize'), 2); $m = new pakePhing(); $m->execute($args); $m->runBuild(); ob_end_clean(); }
/** * Set the colors to use from a property file specified in the * special phing property file "phing/listener/defaults.properties". */ private final function setColors() { $systemColorFile = new PhingFile(Phing::getResourcePath("phing/listener/defaults.properties")); try { $prop = new Properties(); $prop->load($systemColorFile); $err = $prop->getProperty("HtmlColorLogger.ERROR_CLASS"); $warn = $prop->getProperty("HtmlColorLogger.WARNING_CLASS"); $info = $prop->getProperty("HtmlColorLogger.INFO_CLASS"); $verbose = $prop->getProperty("HtmlColorLogger.VERBOSE_CLASS"); $debug = $prop->getProperty("HtmlColorLogger.DEBUG_CLASS"); if ($err !== null) { $this->errColor = self::PREFIX . $err . self::SUFFIX; } if ($warn !== null) { $this->warnColor = self::PREFIX . $warn . self::SUFFIX; } if ($info !== null) { $this->infoColor = self::PREFIX . $info . self::SUFFIX; } if ($verbose !== null) { $this->verboseColor = self::PREFIX . $verbose . self::SUFFIX; } if ($debug !== null) { $this->debugColor = self::PREFIX . $debug . self::SUFFIX; } } catch (IOException $ioe) { //Ignore exception - we will use the defaults. } }
/** * Calls function and returns results. * @return mixed */ protected function callFunction() { if ($this->class !== null) { // import the classname & unqualify it, if necessary $this->class = Phing::import($this->class); $user_func = array($this->class, $this->function); $h_func = $this->class . '::' . $this->function; // human-readable (for log) } else { $user_func = $this->function; $h_func = $user_func; // human-readable (for log) } // put parameters into simple array $params = array(); foreach ($this->params as $p) { $params[] = $p->getValue(); } $this->log("Calling PHP function: " . $h_func . "()"); foreach ($params as $p) { $this->log(" param: " . $p, PROJECT_MSG_VERBOSE); } $return = call_user_func_array($user_func, $params); return $return; }
public function execute($command) { // test if os match $myos = Phing::getProperty("os.name"); $this->log("Myos = " . $myos, Project::MSG_VERBOSE); if ($this->os !== null && strpos($this->os, $myos) === false) { // this command will be executed only on the specified OS $this->log("Not found in " . $this->os, Project::MSG_VERBOSE); return 0; } if ($this->dir !== null) { if ($this->dir->isDirectory()) { $currdir = getcwd(); @chdir($this->dir->getPath()); } else { throw new BuildException("Can't chdir to:" . $this->dir->__toString()); } } if ($this->escape == true) { // FIXME - figure out whether this is correct behavior $command = escapeshellcmd($command); } if ($this->error !== null) { $command .= ' 2> ' . $this->error->getPath(); $this->log("Writing error output to: " . $this->error->getPath()); } if ($this->output !== null) { $command .= ' 1> ' . $this->output->getPath(); $this->log("Writing standard output to: " . $this->output->getPath()); } elseif ($this->spawn) { $command .= ' 1>/dev/null'; $this->log("Sending ouptut to /dev/null"); } // If neither output nor error are being written to file // then we'll redirect error to stdout so that we can dump // it to screen below. if ($this->output === null && $this->error === null) { $command .= ' 2>&1'; } // we ignore the spawn boolean for windows if ($this->spawn) { $command .= ' &'; } $this->log("Executing command: " . $command); $return = null; if ($this->passthru) { passthru($command, $return); } else { $output = array(); exec($command, $output, $return); } if ($this->dir !== null) { @chdir($currdir); } if ($return != 0 && $this->checkreturn) { throw new BuildException("Task exited with code {$return}"); } return $return; }
protected function setUp() { if (version_compare(PHP_VERSION, '5.3.2') < 0) { define('E_DEPRECATED', 8192); } chdir(dirname(__FILE__)); Phing::setProperty('phing.home', ZECLIB_TEST_VENDOR_DIR . '/phing'); Phing::startup(); }
public function setUp() { Phing::startup(); $this->base = $this->getMockBuilder('PhingFile')->setConstructorArgs(array(dirname(__FILE__) . '/../Fixtures/BaseLocalConfiguration.php'))->setMethods(NULL)->getMock(); $this->update = $this->getMockBuilder('PhingFile')->setConstructorArgs(array(dirname(__FILE__) . '/../Fixtures/UpdateLocalConfiguration.php'))->setMethods(NULL)->getMock(); $_tempTargetFile = tempnam('/tmp', 'tmp'); $tempTargetFile = $this->getMockBuilder('PhingFile')->setConstructorArgs(array($_tempTargetFile))->setMethods(NULL)->getMock(); $this->fileWriter = $this->getMockBuilder('FileWriter')->setConstructorArgs(array($tempTargetFile))->getMock(); $this->task = new MergeLocalConfigurationTask(); }
public function __construct() { // @todo These should have an auto-loader require_once 'phing/Phing.php'; require_once 'phing/Project.php'; require_once 'phing/types/FileSet.php'; require_once 'phing/system/io/PhingFile.php'; require_once 'phing/system/util/Properties.php'; // Needs calling quite early (e.g. PhingFile won't work without it) Phing::startup(); }
/** * @see Phing */ public function runBuild() { // workaround for included phing 2.3 which by default loads many tasks // that are not needed and incompatible (eg phing.tasks.ext.FtpDeployTask) // by placing current directory on the include path our defaults will be loaded // see ticket #5054 $includePath = get_include_path(); set_include_path(dirname(__FILE__) . PATH_SEPARATOR . $includePath); parent::runBuild(); set_include_path($includePath); }
public function setUp() { Phing::startup(); $this->project = $this->getMockBuilder('Project')->setMethods(NULL)->getMock(NULL); $tempTargetFile = tempnam('/tmp', 'tmp'); $this->file = $this->getMockBuilder('PhingFile')->setConstructorArgs(array($tempTargetFile))->setMethods(NULL)->getMock(); $propertyTask = $this->getMockBuilder('PropertyTask')->setMethods(NULL)->getMock(); $propertyTask->setProject($this->project); $propertyTask->setFile(dirname(__FILE__) . '/../Fixtures/LocalConfiguration.properties'); $propertyTask->setPrefix('LocalConfiguration.'); $propertyTask->main(); $this->task = new GenerateLocalConfigurationTask(); $this->task->setProject($this->project); }
/** * Does the work. * * @throws BuildException if someting goes wrong with the build */ public final function main() { if ($this->cvsRoot === null) { throw new BuildException("cvsroot is required"); } if ($this->password === null) { throw new BuildException("password is required"); } $this->log("cvsRoot: " . $this->cvsRoot, PROJECT_MSG_DEBUG); $this->log("password: "******"passFile: " . $this->passFile->__toString(), PROJECT_MSG_DEBUG); $reader = null; $writer = null; try { $buf = ""; if ($this->passFile->exists()) { $reader = new BufferedReader(new FileReader($this->passFile)); $line = null; while (($line = $reader->readLine()) !== null) { if (!StringHelper::startsWith($this->cvsRoot, $line)) { $buf .= $line . Phing::getProperty("line.separator"); } } } $pwdfile = $buf . $this->cvsRoot . " A" . $this->mangle($this->password); $this->log("Writing -> " . $pwdfile, PROJECT_MSG_DEBUG); $writer = new BufferedWriter(new FileWriter($this->passFile)); $writer->write($pwdfile); $writer->newLine(); $writer->close(); if ($reader) { $reader->close(); } } catch (IOException $e) { if ($reader) { try { $reader->close(); } catch (Exception $e) { } } if ($writer) { try { $writer->close(); } catch (Exception $e) { } } throw new BuildException($e); } }
function evaluate() { $osName = strtolower(Phing::getProperty("os.name")); if ($this->family !== null) { if ($this->family === "windows") { return StringHelper::startsWith("win", $osName); } elseif ($this->family === "mac") { return strpos($osName, "mac") !== false || strpos($osName, "darwin") !== false; } elseif ($this->family === "unix") { return StringHelper::endsWith("ix", $osName) || StringHelper::endsWith("ux", $osName) || StringHelper::endsWith("bsd", $osName) || StringHelper::startsWith("sunos", $osName) || StringHelper::startsWith("darwin", $osName); } throw new BuildException("Don't know how to detect os family '" . $this->family . "'"); } return false; }
/** * Instantiates the identified custom selector class. */ public function selectorCreate() { if ($this->classname !== null && $this->classname !== "") { try { // assume it's fully qualified, import it $cls = Phing::import($this->classname); // make sure class exists if (class_exists($cls)) { $this->dynselector = new $cls(); } else { $this->setError("Selector " . $this->classname . " not initialized, no such class"); } } catch (Exception $e) { $this->setError("Selector " . $this->classname . " not initialized, could not create class: " . $e->getMessage()); } } else { $this->setError("There is no classname specified"); } }
/** * Returns the path to the XSL stylesheet */ private function getStyleSheet() { $xslname = "phpunit2-" . $this->format . ".xsl"; if ($this->styleDir) { $file = new PhingFile($this->styleDir, $xslname); } else { $path = Phing::getResourcePath("phing/etc/{$xslname}"); if ($path === NULL) { $path = Phing::getResourcePath("etc/{$xslname}"); if ($path === NULL) { throw new BuildException("Could not find {$xslname} in resource path"); } } $file = new PhingFile($path); } if (!$file->exists()) { throw new BuildException("Could not find file " . $file->getPath()); } return $file; }
/** * Construct new MailLogger */ public function __construct() { parent::__construct(); @(require_once 'Mail.php'); if (!class_exists('Mail')) { throw new BuildException('Need the PEAR Mail package to send logs'); } $from = Phing::getDefinedProperty('phing.log.mail.from'); $subject = Phing::getDefinedProperty('phing.log.mail.subject'); $tolist = Phing::getDefinedProperty('phing.log.mail.recipients'); if (!empty($from)) { $this->_from = $from; } if (!empty($subject)) { $this->_subject = $subject; } if (!empty($tolist)) { $this->_tolist = $tolist; } }
/** * This method is called to load the sources from the reader * into the buffer of the source. */ function load() { // Create new Reader if ($this->classname === null) { throw new BuildException("No Classname given to TokenSource."); } $classname = Phing::import($this->classname); $this->reader = new $classname($this->project); // Configure Reader $this->configureTokenReader($this->reader); // Load Tokens try { while ($token = $this->reader->readToken()) { $this->tokens[] = $token; } } catch (BuildException $e) { $this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN); } catch (IOException $e) { $this->log("Error reading TokenSource: " . $e->getMessage(), PROJECT_MSG_WARN); } }
/** * Executes this task. */ public function main() { if ($this->file === null) { throw new BuildException('The file attribute must be specified'); } $return = getcwd(); try { /* Resolve paths correctly: Everything we do as far as * configuration is concerned should be relative to the * new project file. */ chdir($this->file->getAbsoluteFile()->getParent()); $project = new AgaviProxyProject($this->project); $project->addReference('phing.parsing.context', new AgaviProxyXmlContext($project)); $project->setUserProperty('phing.file', $this->file->getAbsolutePath()); $project->init(); Phing::setCurrentProject($project); ProjectConfigurator::configureProject($project, $this->file); foreach ($project->getTargets() as $name => $target) { /* Make sure we don't add proxy targets back to our own project. */ if ($target instanceof AgaviProxyTarget && $target->getTarget()->getProject() === $this->project) { continue; } if (array_key_exists($name, $this->project->getTargets())) { throw new BuildException(sprintf('Target conflict: %s already exists in project (attempted to add from %s)', $name, $this->file->getAbsolutePath())); } $proxy = new AgaviProxyTarget(); $proxy->setName($name); $proxy->setDescription($target->getDescription()); $proxy->setTarget($target); $this->project->addTarget($name, $proxy); } Phing::setCurrentProject($this->project); $this->log(sprintf('Importing external build file %s', $this->file->getAbsolutePath()), Project::MSG_INFO); } catch (Exception $e) { $this->log(sprintf('Could not read %s: %s (skipping)', $this->file->getAbsolutePath(), $e->getMessage()), Project::MSG_WARN); } /* Go back from whence we came. */ chdir($return); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { try { $args = $this->preparePhingArgs($input, $output); $phingClasspath = $this->getContainer()->getParameter('rhapsody_phing.phing_classpath'); $phingHome = $this->getContainer()->getParameter('rhapsody_phing.phing_home'); if ($output->getVerbosity() == OutputInterface::VERBOSITY_VERBOSE) { $commandline = 'phing ' . implode(' ', $args); $output->writeln('Executing Phing with: ' . $commandline); } //require_once('phing/Phing.php'); \Phing::startup(); \Phing::setProperty('rhapsody_phing.home', $phingHome); \Phing::fire($args); \Phing::shutdown(); } catch (ConfigurationException $x) { Phing::printMessage($x); exit(-1); } catch (Exception $x) { exit(1); } }
/** * Fired when the build finishes, this adds the time taken and any * error stacktrace to the build element and writes the document to disk. * * @param BuildEvent $event An event with any relevant extra information. * Will not be <code>null</code>. * @throws BuildException */ public function buildFinished(BuildEvent $event) { $elapsedTime = Phing::currentTimeMillis() - $this->getBuildTimerStart(); $this->getBuildElement()->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime)); if ($event->getException() != null) { $this->getBuildElement()->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage()); $errText = $this->getDoc()->createCDATASection($event->getException()->getTraceAsString()); $stacktrace = $this->getDoc()->createElement(XmlLogger::STACKTRACE_TAG); $stacktrace->appendChild($errText); $this->getBuildElement()->appendChild($stacktrace); } $this->getDoc()->appendChild($this->getBuildElement()); $outFilename = $event->getProject()->getProperty("JsonLogger.file"); if ($outFilename == null) { $outFilename = "log.json"; } try { $stream = $this->getOut(); if ($stream === null) { $stream = new FileOutputStream($outFilename); } $writer = new OutputStreamWriter($stream); $writer->write($this->xml2js(simplexml_import_dom($this->getDoc()))); $writer->close(); } catch (IOException $exc) { try { $stream->close(); // in case there is a stream open still ... } catch (Exception $x) { } throw new BuildException("Unable to write log file.", $exc); } // cleanup:remove the buildElement $this->setBuildElement(null); array_pop($this->getElementStack()); array_pop($this->getTimesStack()); }
/** * @param string the filename * @param Path optional classpath * @return array list of classes defined in the file */ static function getDefinedClasses($filename, $classpath = NULL) { $filename = realpath($filename); if (!file_exists($filename)) { throw new Exception("File '" . $filename . "' does not exist"); } if (isset(self::$definedClasses[$filename])) { return self::$definedClasses[$filename]; } Phing::__import($filename, $classpath); $declaredClasses = get_declared_classes(); foreach ($declaredClasses as $classname) { $reflect = new ReflectionClass($classname); self::$definedClasses[$reflect->getFilename()][] = $classname; if (is_array(self::$definedClasses[$reflect->getFilename()])) { self::$definedClasses[$reflect->getFilename()] = array_unique(self::$definedClasses[$reflect->getFilename()]); } } if (isset(self::$definedClasses[$filename])) { return self::$definedClasses[$filename]; } else { return array(); } }
/** * Method that gets invoked when the parser runs over CDATA. * * This method is called by PHP's internal parser functions and registered * in the actual parser implementation. * * It gives control to the current active handler object by calling the * <code>characters()</code> method. That processes the given CDATA. * * BECAUSE OF PROBLEMS WITH EXCEPTIONS BUBBLING UP THROUGH xml_parse() THIS * METHOD WILL CALL Phing::halt(-1) ON EXCEPTION. * * @param resource $parser php's internal parser handle. * @param string $data the CDATA */ function characters($parser, $data) { try { $this->handler->characters($data); } catch (Exception $e) { print "[Exception in XML parsing]\n"; print $e; Phing::halt(-1); } }
/** * Logs whether the build succeeded or failed, and any errors that * occured during the build. Also outputs the total build-time. * * @param BuildEvent The BuildEvent * * @see BuildEvent::getException() */ public function buildFinished(BuildEvent $event) { $error = $event->getException(); if ($error === null) { $msg = "Finished successful build."; } else { $msg = "Build failed. [reason: " . $error->getMessage() . "]"; } $this->logger()->log($msg . " Total time: " . DefaultLogger::formatTime(Phing::currentTimeMillis() - $this->startTime)); }
function getAssembledReader() { $instream = $this->primaryReader; $filterReadersCount = count($this->filterChains); $finalFilters = array(); // Collect all filter readers of all filter chains used ... for ($i = 0; $i < $filterReadersCount; $i++) { $filterchain =& $this->filterChains[$i]; $filterReaders = $filterchain->getFilterReaders(); $readerCount = count($filterReaders); for ($j = 0; $j < $readerCount; $j++) { $finalFilters[] = $filterReaders[$j]; } } // ... then chain the filter readers. $filtersCount = count($finalFilters); if ($filtersCount > 0) { for ($i = 0; $i < $filtersCount; $i++) { $filter = $finalFilters[$i]; if ($filter instanceof PhingFilterReader) { // This filter reader is an external class. $className = $filter->getClassName(); $classpath = $filter->getClasspath(); $project = $filter->getProject(); if ($className !== null) { $cls = Phing::import($className, $classpath); $impl = new $cls(); } if (!$impl instanceof FilterReader) { throw new Exception($className . " does not extend phing.system.io.FilterReader"); } $impl->setReader($instream); // chain $impl->setProject($this->getProject()); // what about $project above ? if ($impl instanceof Parameterizable) { $impl->setParameters($filter->getParams()); } $instream = $impl; // now that it's been chained } elseif ($filter instanceof ChainableReader && $filter instanceof Reader) { if ($this->getProject() !== null && $filter instanceof BaseFilterReader) { $filter->setProject($this->getProject()); } $instream = $filter->chain($instream); } else { throw new Exception("Cannot chain invalid filter: " . get_class($filter)); } } } return $instream; }
/** * Returns reference to Timer object. * @return Timer */ public static function getTimer() { if (self::$timer === null) { include_once 'phing/system/util/Timer.php'; self::$timer = new Timer(); } return self::$timer; }
function _getUserPath() { //For both compatibility and security, we must look this up every time return (string) $this->normalize(Phing::getProperty("user.dir")); }
/** * Prints whether the build succeeded or failed, and any errors that * occured during the build. Also outputs the total build-time. * * @param object The BuildEvent * @see BuildEvent::getException() */ public function buildFinished(BuildEvent $event) { $error = $event->getException(); if ($error === null) { $msg = PHP_EOL . $this->getBuildSuccessfulMessage() . PHP_EOL; } else { $msg = PHP_EOL . $this->getBuildFailedMessage() . PHP_EOL; if (Project::MSG_VERBOSE <= $this->msgOutputLevel || !$error instanceof BuildException) { $msg .= $error->__toString() . PHP_EOL; } else { $msg .= $error->getMessage(); } } $msg .= PHP_EOL . "Total time: " . self::formatTime(Phing::currentTimeMillis() - $this->startTime) . PHP_EOL; if ($error === null) { $this->printMessage($msg, $this->out, Project::MSG_VERBOSE); } else { $this->printMessage($msg, $this->err, Project::MSG_ERR); } }
private function _checkResource($resource) { if (null != ($resourcePath = Phing::getResourcePath($resource))) { return $this->_checkFile1(new PhingFile($resourcePath)); } else { return false; } }