/** * 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(); }
/** * 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(); }
/** * Test that {@link phpucConfigProject#delete()} removes the context project * from the config.xml file. * * @return void */ public function testDeleteConfigProjectFromConfigFile() { // Create a dummy project new phpucConfigProject($this->config, 'phpUnderControl0'); new phpucConfigProject($this->config, 'phpUnderControl1'); $this->config->store(); $dom = new DOMDocument(); $dom->load($this->testFile); $this->assertEquals(2, $dom->getElementsByTagName('project')->length); // Load project again $config = new phpucConfigFile($this->testFile); $project = $config->getProject('phpUnderControl0'); // Remove project and save again $project->delete(); $config->store(); $dom = new DOMDocument(); $dom->load($this->testFile); $this->assertEquals(1, $dom->getElementsByTagName('project')->length); }
/** * This method tests that the {@link phpucConfigFile::getProject()} method * fails with an expection, if no project for the given name exists. * * @return void */ public function testGetProjectFail() { $this->setExpectedException('phpucErrorException'); $this->createTestFile('/config.xml', $this->testXml); $config = new phpucConfigFile($this->testFile); $config->getProject('phpUnderControl'); }
/** * Returns a configuration instance for the current project * * @return phpucConfigProject */ private function getCruiseControlProjectConfiguration() { $configFile = new phpucConfigFile($this->args->getArgument('cc-install-dir') . '/config.xml'); return $configFile->getProject($this->args->getOption('project-name')); }
/** * Creates the api documentation build directory. * * @return void * @throws phpucExecuteException If the execution fails. */ public function execute() { $out = phpucConsoleOutput::get(); $out->writeLine('Performing PhpDocumentor task.'); $installDir = $this->args->getArgument('cc-install-dir'); $projectName = $this->args->getOption('project-name'); $projectPath = sprintf('%s/projects/%s', $installDir, $projectName); $out->startList(); $out->writeListItem('Creating apidoc dir: project/{1}/build/api', $projectName); mkdir($projectPath . '/build/api', 0755, true); $out->writeListItem('Modifying build file: project/{1}/build.xml', $projectName); $buildFile = new phpucBuildFile($projectPath . '/build.xml'); $buildTarget = $buildFile->createBuildTarget('php-documentor'); $buildTarget->dependOn('lint'); $execTask = phpucAbstractAntTask::create($buildFile, 'exec'); $execTask->executable = $this->executable; $execTask->logerror = true; $execTask->argLine = sprintf('--title \'${ant.project.name}\' -ue on -t ${basedir}/build/api -d %s ' . '-tb \'%s/phpdoc\' -o HTML:Phpuc:phpuc', $this->args->getOption('source-dir'), PHPUC_DATA_DIR); $buildTarget->addTask($execTask); $buildFile->store(); $out->writeListItem('Modifying config file: config.xml'); $configFile = new phpucConfigFile($installDir . '/config.xml'); $configProject = $configFile->getProject($projectName); $publisher = $configProject->createArtifactsPublisher(); $publisher->dir = 'projects/${project.name}/build/api'; $publisher->subdirectory = 'api'; if ($this->artifacts) { $publisher->dest = 'artifacts/${project.name}'; } else { $publisher->dest = 'logs/${project.name}'; } $configFile->store(); $out->writeLine(); }
/** * Removes the project configuration from the config.xml file. * * @param string $installDir * The CruiseControl installation directory. * @param string $projectName * The project name. * * @return void */ protected function deleteProjectConfig($installDir, $projectName) { $config = new phpucConfigFile("{$installDir}/config.xml"); $config->getProject($projectName)->delete(); $config->store(); }
/** * Adds a new project to CruiseControl. * * This method creates the base directory structure for a CruiseControl * project and adds this project to the CruiseControl config.xml file. * * @return void */ public function execute() { $out = phpucConsoleOutput::get(); $out->writeLine('Performing project task.'); $installDir = $this->args->getArgument('cc-install-dir'); $projectName = $this->args->getOption('project-name'); $projectPath = sprintf('%s/projects/%s', $installDir, $projectName); $out->startList(); $out->writeListItem('Creating project directory: projects/{1}', $projectName); mkdir($projectPath); $out->writeListItem('Creating source directory: projects/{1}/source', $projectName); mkdir($projectPath . '/source'); $out->writeListItem('Creating build directory: projects/{1}/build', $projectName); mkdir($projectPath . '/build'); $out->writeListItem('Creating log directory: projects/{1}/build/logs', $projectName); mkdir($projectPath . '/build/logs'); $out->writeListItem('Creating build file: projects/{1}/build.xml', $projectName); $buildFile = new phpucBuildFile($projectPath . '/build.xml', $projectName); $buildFile->store(); $out->writeListItem('Creating backup of file: config.xml.orig'); @unlink($installDir . '/config.xml.orig'); copy($installDir . '/config.xml', $installDir . '/config.xml.orig'); $out->writeListItem('Searching ant directory'); if (!($anthome = $this->getAntHome($installDir))) { throw new phpucExecuteException('ERROR: Cannot locate ant directory.'); } $out->writeListItem('Modifying project file: config.xml'); $config = new phpucConfigFile($installDir . '/config.xml'); $project = $config->createProject($projectName); $project->interval = $this->args->getOption('schedule-interval'); $project->anthome = $anthome; if ($this->args->hasOption('ant-script')) { $project->antscript = $this->args->getOption('ant-script'); } $config->store(); $out->writeLine(); }