/** * Sets the required binary contents. * * @return void */ protected function setUp() { parent::setUp(); if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) { $this->validBin = "@echo off\n\recho version 1.2.0"; } }
/** * Performs the primary task and adds an execute publisher to the config.xml. * * @return void */ public function execute() { $out = phpucConsoleOutput::get(); $out->writeLine('Performing ezcGraph task.'); $installDir = $this->args->getArgument('cc-install-dir'); $projectName = $this->args->getOption('project-name'); $out->startList(); $out->writeListItem('Modifying config file: config.xml'); $configFile = new phpucConfigFile($installDir . '/config.xml'); $configProject = $configFile->getProject($projectName); $publisher = $configProject->createExecutePublisher(); $binary = sprintf('%s/phpuc', PHPUC_BIN_DIR); if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) { $binary .= '.bat'; } else { if (!file_exists($binary)) { $binary .= '.php'; } } // Build default command string $command = sprintf('%s graph logs/${project.name}', $binary); // Check for an artifacts directory if ($this->artifacts) { $command .= ' artifacts/${project.name}'; } $publisher->command = $command; $configFile->store(); $out->writeLine(); }
/** * Resets the path and os settings in {@link phpucFileUtil}. * * @return void */ protected function setUp() { parent::setUp(); phpucFileUtil::setOS(); phpucFileUtil::setPaths(); $this->cwd = getcwd(); chdir(PHPUC_TEST_DIR); }
/** * Performs a git checkout. * * @return void * @throws phpucErrorException * If the git checkout fails. */ public function checkout() { $git = phpucFileUtil::findExecutable('git'); $url = escapeshellarg($this->url); $cmd = "{$git} clone {$url} source"; popen("{$cmd} 2>&1", "r"); if (!file_exists('source')) { throw new phpucErrorException('The project checkout has failed.'); } $cwd = getcwd(); // Switch into checkout directory chdir('source'); // Add tracked remote branch shell_exec("{$git} remote add {$this->remote} {$url}"); chdir($cwd); }
/** * Performs a subversion checkout. * * @return void * @throws phpucErrorException * If the subversion checkout fails. */ public function checkout() { $options = ' --no-auth-cache --non-interactive'; if ($this->username !== null) { $options .= ' --username ' . escapeshellarg($this->username); } if ($this->password !== null) { $options .= ' --password ' . escapeshellarg($this->password); } $svn = phpucFileUtil::findExecutable('svn'); $url = escapeshellarg($this->url); $cmd = "{$svn} co {$options} {$url} source"; popen("{$cmd} 2>&1", "r"); if (!file_exists('source')) { throw new phpucErrorException('The project checkout has failed.'); } }
/** * Performs a project checkout against the specified repository. * * @return void */ public function execute() { $out = phpucConsoleOutput::get(); $out->writeLine('Performing checkout task.'); $out->startList(); // Get current working dir $cwd = getcwd(); $out->writeListItem('Checking out project.'); $projectPath = sprintf('%s/projects/%s', $this->args->getArgument('cc-install-dir'), $this->args->getOption('project-name')); // Switch working dir to the CruiseControl project directory chdir($projectPath); $checkout = phpucAbstractCheckout::createCheckout($this->args); $checkout->checkout(); chdir($cwd); $out->writeListItem('Preparing config.xml file.'); $fileName = sprintf('%s/config.xml', $this->args->getArgument('cc-install-dir')); $config = new phpucConfigFile($fileName); $project = $config->getProject($this->args->getOption('project-name')); $strapper = $project->createBootStrapper(); $strapper->localWorkingCopy = "{$projectPath}/source"; $strapper->strapperType = $this->args->getOption('version-control'); $trigger = $project->createBuildTrigger(); $trigger->localWorkingCopy = "{$projectPath}/source"; $trigger->triggerType = $this->args->getOption('version-control'); $config->store(); $out->writeListItem('Preparing build.xml checkout target.'); $buildFile = new phpucBuildFile("{$projectPath}/build.xml"); $buildTarget = $buildFile->createBuildTarget('checkout'); $execTask = phpucAbstractAntTask::create($buildFile, 'exec'); $execTask->executable = phpucFileUtil::findExecutable($this->args->getOption('version-control')); $execTask->argLine = $checkout->getUpdateCommand(); $execTask->failonerror = true; $buildTarget->addTask($execTask); $buildFile->store(); $out->writeLine(); }
/** * Validates the existing PHPUnit version. * * @return void */ protected function doValidate() { $binary = basename($this->executable); if (($execdir = dirname($this->executable)) !== '.') { chdir($execdir); if (phpucFileUtil::getOS() === phpucFileUtil::OS_UNIX) { $binary = "./{$binary}"; } } // Check Xdebug installation if (extension_loaded('xdebug') === false) { phpucConsoleOutput::get()->writeLine('NOTICE: The xdebug extension is not installed. For coverage'); phpucConsoleOutput::get()->writeLine('you must install xdebug with the following command:'); phpucConsoleOutput::get()->writeLine(' pecl install pecl/xdebug'); $this->properties['coverage'] = false; } }
/** * Does the primary validation that the command line tool exists. If the * tool exists this method passes the request to the internal template * method {@link doValidate()}. * * @return void * * @throws phpucValidateException If the validation fails. */ public final function validate() { // Get possible or configured pear path if ($this->pearBinaryDir === null) { $paths = explode(PATH_SEPARATOR, getenv('PATH')); } else { $paths = array($this->pearBinaryDir); } $paths = array_unique($paths); $windows = phpucFileUtil::getOS() == phpucFileUtil::OS_WINDOWS; foreach ($paths as $path) { $fileName = sprintf('%s/%s%s', $path, $this->cliTool, $windows === true ? '.bat' : ''); if (file_exists($fileName) === false) { continue; } if (is_executable($fileName) === false && $windows === false) { continue; } $this->properties['executable'] = $fileName; break; } if ($this->executable === null) { throw new phpucValidateException("Missing cli tool '{$this->cliTool}', check the PATH variable."); } else { if ($this->pearBinaryDir === null) { $dir = dirname($this->executable); if (strpos(getenv('PATH'), $dir) !== false) { $this->properties['executable'] = basename($this->executable); } } } $this->doValidate(); }
/** * Validates the existing code sniffer version. * * @return void */ protected function doValidate() { $cwd = $this->getWorkingDirectory(); $binary = basename($this->executable); if (($execdir = dirname($this->executable)) !== '.') { chdir($execdir); if (phpucFileUtil::getOS() === phpucFileUtil::OS_UNIX) { $binary = "./{$binary}"; } } $regexp = '/version\\s+([0-9\\.]+(RC[0-9])?)/'; $retval = exec(escapeshellcmd("{$binary} --version")); chdir($cwd); if (preg_match($regexp, $retval, $match) === 0) { phpucConsoleOutput::get()->writeLine('WARNING: Cannot identify PHP_CodeSniffer version.'); // Assume valid version $version = self::CODE_SNIFFER_VERSION; } else { $version = $match[1]; } if (version_compare($version, self::CODE_SNIFFER_VERSION) < 0) { throw new phpucValidateException(sprintf('PHP_CodeSniffer version %s or higher required.' . ' Given version is "%s".', self::CODE_SNIFFER_VERSION, $version)); } }
/** * Creates a fake executable. * * @param string $executable The executable name. * @param string $content Dummy/test content for the executable. * * @return void */ protected function createExecutable($executable, $content) { if (!is_dir(PHPUC_TEST_DIR . '/bin')) { mkdir(PHPUC_TEST_DIR . '/bin'); } if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) { $executable .= '.bat'; } $fileName = PHPUC_TEST_DIR . '/bin/' . $executable; file_put_contents($fileName, $content); chmod($fileName, 0755); }
/** * Allows to set some custom paths. This method is only need intended for * testing. * * @param array $paths List of environment paths. * * @return void */ public static function setPaths(array $paths = null) { self::$paths = $paths; }
/** * Constructs a new cvs checkout. */ public function __construct() { $this->properties['module'] = null; $this->passFile = tempnam(phpucFileUtil::getSysTempDir(), 'cvs'); }
/** * Tries to find the ant home directory. * * @param string $installDir The CruiseControl installation directory. * * @return string */ public function getAntHome($installDir) { if (count($ant = glob(sprintf('%s/apache-ant*', $installDir))) === 0) { if (file_exists($installDir . '/bin/ant')) { return $installDir; } $os = phpucFileUtil::getOS(); if ($os !== phpucFileUtil::OS_WINDOWS) { $ant = shell_exec('which ant'); } if (strstr(trim($ant), 'bin/ant')) { return substr($ant, 0, strlen($ant) - 7); } return false; } else { return array_pop($ant); } }
/** * Removes all project artifact subdirectories that match one of the given * timestamps. * * @param string $basePath * Base directory where the method starts to clean up. * @param array $timestamps * List of all removable timestamps. * * @return void */ protected function cleanArtifacts($basePath, array $timestamps) { foreach ($timestamps as $timestamp) { $path = "{$basePath}/{$timestamp}"; if (is_dir($path)) { phpucFileUtil::deleteDirectory($path); } } }
/** * Sets the required binary contents. * * @return void */ protected function setUp() { parent::setUp(); $this->clearTestContents(PHPUC_TEST_DIR . '/projects'); $this->clearTestContents(PHPUC_TEST_DIR . '/build'); $this->clearTestContents(PHPUC_TEST_DIR . '/logs'); if (phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS) { $this->badBin = "@echo off\n\recho version-3.2.0"; $this->validBin = "@echo off\n\recho version 3.2.0"; $this->invalidBin = "@echo off\n\recho version 3.1.9"; } }
/** * Initializes the test directories and files for the executable test. * * @param integer $os The operation system. * * @return void */ protected function initExecutableTest($os = phpucFileUtil::OS_UNIX) { // Set operation system to unix phpucFileUtil::setOS($os); // Set fake environment directories phpucFileUtil::setPaths($this->createTestDirectories(array('/usr/bin', '/usr/local/bin'))); if ($os === phpucFileUtil::OS_WINDOWS) { $this->createTestFile('/usr/bin/svn.cmd'); } else { $this->createTestFile('/usr/bin/svn'); } }
/** * Deletes the project directory for the context project. * * @param string $installDir * The CruiseControl installation directory. * @param string $projectName * The project name. * * @return void */ protected function deleteProjectDirectory($installDir, $projectName) { $artifacts = "{$installDir}/projects/{$projectName}"; if (is_dir($artifacts)) { phpucFileUtil::deleteDirectory($artifacts); } }
/** * Initializes the test environment. * * @return void */ public static function init() { // Load phpUnderControl base class include_once PHPUC_SOURCE . '/PhpUnderControl.php'; include_once PHPUC_SOURCE . '/Util/Autoloader.php'; // Register autoload $autoloader = new phpucAutoloader(); spl_autoload_register(array($autoloader, 'autoload')); // Load ezcBase class if (file_exists(PHPUC_EZC_BASE)) { include_once PHPUC_EZC_BASE; spl_autoload_register(array('ezcBase', 'autoload')); } include_once dirname(__FILE__) . '/ConsoleOutputBuffer.php'; phpucConsoleOutput::set(new phpucConsoleOutputBuffer()); if (!is_dir(PHPUC_TEST_DIR)) { mkdir(PHPUC_TEST_DIR); } self::$windows = phpucFileUtil::getOS() === phpucFileUtil::OS_WINDOWS; }