Пример #1
0
 public function update(&$rev)
 {
     // We can't use "git --git-dir={$this->getLocal()} pull", it's wrong
     $drive = '';
     if (Framework_HostOs::isWindows()) {
         $drive = substr($this->getLocal(), 0, strpos($this->getLocal(), ':') + 1) . ' && ';
     }
     $command = (empty($this->_envVars) ? '' : $this->getEnvVars() . ' && ') . "{$drive} cd {$this->getLocal()} && {$GLOBALS['settings'][SystemSettings::EXECUTABLE_GIT]} pull";
     $proc = new Framework_Process();
     $proc->setExecutable($command, false);
     // false for no escapeshellcmd() (because of the ';')
     $proc->run();
     if (($return = $proc->getReturnValue()) != 0) {
         SystemEvent::raise(SystemEvent::ERROR, "Could not update local working copy. [COMMAND=\"{$command}\"] [RET={$return}] [STDERR=\"{$proc->getStderr()}\"] [STDOUT=\"{$proc->getStdout()}\"]", __METHOD__);
         return false;
     }
     $rev = $this->_getLocalRevision();
     SystemEvent::raise(SystemEvent::DEBUG, "Updated local. [REV={$rev}] [COMMAND=\"{$command}\"] [RET={$return}] [STDERR=\"{$proc->getStderr()}\"] [STDOUT=\"{$proc->getStdout()}\"]", __METHOD__);
     return true;
 }
Пример #2
0
 public function init()
 {
     //
     // Get the ID, first and foremost. Also this is the start datetime
     //
     $this->setDate($this->getNowDatetime());
     if (!$this->_save(true)) {
         return false;
     }
     $project = $this->getPtrProject();
     // Easier handling
     //
     // A few more sanity checks
     //
     $integrationBuilder = $project->getIntegrationBuilder();
     if (!$integrationBuilder instanceof Build_BuilderElement_Project) {
         SystemEvent::raise(SystemEvent::DEBUG, "No valid integration builder specified. [PROJECTID={$this->getProjectId()}]", __METHOD__);
         return false;
     }
     if ($integrationBuilder->isEmpty()) {
         SystemEvent::raise(SystemEvent::DEBUG, "Empty integration builder. [PROJECTID={$this->getProjectId()}]", __METHOD__);
         return false;
     }
     //
     // Check for special tasks and run pre build actions
     //
     $specialTasks = $this->getSpecialTasks();
     if (!empty($specialTasks)) {
         foreach ($specialTasks as $task) {
             if (!class_exists($task)) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task. [PID={$project->getId()}] [BUILD={$this->getId()}] [TASK={$task}]", __METHOD__);
                 return false;
             }
             $o = new $task($this);
             if (!$o->preBuild()) {
                 SystemEvent::raise(SystemEvent::ERROR, "Special task's pre build execution aborted. [PID={$project->getId()}] [BUILD={$this->getId()}] [TASK={$task}]", __METHOD__);
                 return false;
             }
         }
     }
     //
     // Export and execute the builder's source code
     //
     $builderCode = $integrationBuilder->toPhp();
     SystemEvent::raise(SystemEvent::DEBUG, "Integration builder source code:" . PHP_EOL . print_r($builderCode, true), __METHOD__);
     // Execute as an external process in order to have a clean sandboxed
     // environment. eval($builderCode) is no more.
     $builderProcess = new Framework_Process($GLOBALS['settings'][SystemSettings::EXECUTABLE_PHP]);
     $builderProcess->setStdin($builderCode);
     $builderProcess->run();
     $this->setDuration(time() - strtotime($this->getDate()));
     // Setup the first finish time. If we get to the end of this method, update again at the end
     //
     // Import back into Cintient space the external builder's output
     // TODO: we should probably have this somewhere better than
     // $GLOBALS['result']...
     //
     // Also check BuilderElement_Project for the expected
     // $GLOBALS['result'] vars...
     //
     $output = explode("\n", str_replace("\r", "", $builderProcess->getStdout()));
     $GLOBALS['result'] = array();
     $GLOBALS['result']['ok'] = false;
     foreach ($output as $line) {
         $line = trim($line);
         $neck = strpos($line, '=');
         $key = substr($line, 0, $neck);
         $value = substr($line, $neck + 1);
         $value = str_replace(CINTIENT_NEWLINE_TOKEN, "\n", $value);
         if (!empty($key)) {
             $GLOBALS['result'][$key] = $value;
         }
     }
     if (!empty($GLOBALS['result']['stacktrace'])) {
         $this->addToOutput($GLOBALS['result']['stacktrace']);
     }
     if (!$builderProcess->emptyStderr()) {
         $this->addToOutput($builderProcess->getStderr());
     }
     if ($GLOBALS['result']['ok'] != true) {
         if (!empty($GLOBALS['result']['task'])) {
             SystemEvent::raise(SystemEvent::INFO, "Failed executing task {$GLOBALS['result']['task']}.", __METHOD__);
         } else {
             SystemEvent::raise(SystemEvent::INFO, "Failed for unknown reasons.", __METHOD__);
         }
         SystemEvent::raise(SystemEvent::DEBUG, "Possible stacktrace: " . print_r($GLOBALS['result'], true), __METHOD__);
         return false;
     }
     $this->setDuration(time() - strtotime($this->getDate()));
     //
     // Create this build's report dir, backing up an existing one, just in case
     //
     if (is_dir($this->getBuildDir())) {
         $backupOldBuildDir = rtrim($this->getBuildDir(), '/') . '_old_' . uniqid() . '/';
         if (!@rename($this->getBuildDir(), $backupOldBuildDir)) {
             SystemEvent::raise(SystemEvent::ERROR, "Couldn't create backup of existing build dir found. [PID={$project->getId()}] [DIR={$this->getBuildDir()}] [BUILD={$this->getId()}]", __METHOD__);
             return false;
         }
     }
     if (!@mkdir($this->getBuildDir(), DEFAULT_DIR_MASK, true)) {
         SystemEvent::raise(SystemEvent::ERROR, "Couldn't create build dir. [PID={$project->getId()}] [DIR={$this->getBuildDir()}] [BUILD={$this->getId()}]", __METHOD__);
         return false;
     }
     //
     // Run post build actions
     //
     reset($specialTasks);
     $result = true;
     if (!empty($specialTasks)) {
         foreach ($specialTasks as $task) {
             if (!class_exists($task)) {
                 SystemEvent::raise(SystemEvent::ERROR, "Unexisting special task. [PID={$project->getId()}] [BUILD={$this->getId()}] [TASK={$task}]", __METHOD__);
                 continue;
             }
             $o = new $task($this);
             $result = $result & $o->postBuild();
         }
     }
     if (!$result) {
         // Don't abort, since this is just the post build actions, not the build itself.
         SystemEvent::raise(SystemEvent::ERROR, "Special task's post build execution had problems. [PID={$project->getId()}] [BUILD={$this->getId()}] [TASK={$task}]", __METHOD__);
     }
     $this->setStatus(self::STATUS_OK_WITHOUT_PACKAGE);
     $this->setDuration(time() - strtotime($this->getDate()));
     // Final duration time refresh
     return true;
 }
Пример #3
0
 public function isModified()
 {
     $credentials = $this->_getCredentialsArgs();
     //
     // svn info the local sources
     //
     /*
     # svn info http://cintient.googlecode.com/svn/trunk/ ./
     svn: warning: cannot set LC_CTYPE locale
     svn: warning: environment variable LC_CTYPE is US-ASCII
     svn: warning: please check that your locale name is correct
     Path: trunk
     URL: http://cintient.googlecode.com/svn/trunk
     Repository Root: http://cintient.googlecode.com/svn
     Repository UUID: b5843765-8500-0169-a8a4-cd43f2d668ef
     Revision: 359
     Node Kind: directory
     Last Changed Author: pedro.matamouros
     Last Changed Rev: 359
     Last Changed Date: 2011-09-18 11:32:48 +0100 (Sun, 18 Sep 2011)
     
     Path: .
     URL: http://cintient.googlecode.com/svn/trunk
     Repository Root: http://cintient.googlecode.com/svn
     Repository UUID: b5843765-8500-0169-a8a4-cd43f2d668ef
     Revision: 358
     Node Kind: directory
     Schedule: normal
     Last Changed Author: pedro.matamouros
     Last Changed Rev: 358
     Last Changed Date: 2011-09-18 11:30:30 +0100 (Sun, 18 Sep 2011)
     */
     $command = (empty($this->_envVars) ? '' : $this->getEnvVars() . ' && ') . "{$GLOBALS['settings'][SystemSettings::EXECUTABLE_SVN]} info {$credentials}--non-interactive {$this->getRemote()} {$this->getLocal()}";
     $proc = new Framework_Process();
     $proc->setExecutable($command, false);
     $proc->run();
     if (($return = $proc->getReturnValue()) != 0) {
         SystemEvent::raise(SystemEvent::ERROR, "Could not check info on repository. [COMMAND=\"{$command}\"] [RET={$return}] [STDERR=\"{$proc->getStderr()}\"] [STDOUT=\"{$proc->getStdout()}\"]", __METHOD__);
         return false;
     }
     $output = $proc->getStdout();
     if (!preg_match_all('/^Revision: (\\d+)$/m', $output, $matches) || !isset($matches[1][0]) || !isset($matches[1][1])) {
         SystemEvent::raise(SystemEvent::ERROR, "Could not check for modifications. [OUTPUT=\"{$output}\"]", __METHOD__);
         return false;
     }
     #if DEBUG
     SystemEvent::raise(SystemEvent::DEBUG, "Repository " . ($matches[1][0] != $matches[1][1] ? '' : 'not ') . "changed.", __METHOD__);
     #endif
     return $matches[1][0] != $matches[1][1];
 }