Пример #1
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $command = null;
     $execTask = new ExecTask();
     $execTask->setProject($this->getProject());
     switch ($this->taoDbConfig->getDbDriver()) {
         case 'pdo_pgsql':
             $command = vsprintf("createdb %s --host=%s --username=%s --no-password", [$this->taoDbConfig->getDbName(), $this->taoDbConfig->getDbHost(), $this->taoDbConfig->getDbUser()]);
             break;
         case 'pdo_mysql':
             $command = vsprintf("echo 'create database %s ' | mysql -u%s -p%s", [$this->taoDbConfig->getDbName(), $this->taoDbConfig->getDbUser(), $this->taoDbConfig->getDbPass()]);
             break;
         default:
             throw new BuildException('DB Driver is not supported');
             break;
     }
     if ($command) {
         $execTask->setCommand($command);
         $execTask->main();
         $this->log(sprintf('Database %s has been created', $this->taoDbConfig->getDbName()));
     }
 }
Пример #2
0
 protected function _exec($command)
 {
     $replaces = array('{build_dir}' => $this->_buildDir, '{branch}' => $this->_branch);
     $command = str_replace(array_keys($replaces), array_values($replaces), $command);
     $this->log($command);
     $returnProp = 'build.update.return';
     $outputProp = 'build.update.output';
     $obj = new ExecTask();
     $obj->setProject($this->project);
     $obj->setCommand($command);
     $obj->setLogoutput(true);
     $obj->setReturnProperty($returnProp);
     $obj->setOutputProperty($outputProp);
     $obj->setPassthru(true);
     $obj->main();
 }
Пример #3
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $command = null;
     $execTask = new ExecTask();
     $execTask->setProject($this->getProject());
     $restoreGZ = $this->getDir() . DIRECTORY_SEPARATOR . $this->taoDbConfig->getDbName() . '.gz';
     switch ($this->taoDbConfig->getDbDriver()) {
         case 'pdo_pgsql':
             $command = vsprintf("gunzip -c %s | psql %s --host=%s --username=%s --no-password", [$restoreGZ, $this->taoDbConfig->getDbName(), $this->taoDbConfig->getDbHost(), $this->taoDbConfig->getDbUser()]);
             break;
         case 'pdo_mysql':
             $command = vsprintf("gunzip -c %s | mysql -u %s -p%s %s", [$restoreGZ, $this->taoDbConfig->getDbUser(), $this->taoDbConfig->getDbPass(), $this->taoDbConfig->getDbName()]);
             break;
         default:
             throw new BuildException('DB Driver is not supported');
             break;
     }
     if ($command) {
         $execTask->setCommand($command);
         $execTask->main();
         $this->log(sprintf('Backup for %s restored at %s', $this->taoDbConfig->getDbName(), $restoreGZ));
     }
 }
Пример #4
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $command = null;
     $execTask = new ExecTask();
     $execTask->setProject($this->getProject());
     $backupPath = $this->dir . DIRECTORY_SEPARATOR . $this->taoDbConfig->getDbName() . '.gz';
     switch ($this->taoDbConfig->getDbDriver()) {
         case 'pdo_pgsql':
             $command = vsprintf("pg_dump --clean --host=%s --username=%s --no-password --dbname=%s | gzip > %s", [$this->taoDbConfig->getDbHost(), $this->taoDbConfig->getDbUser(), $this->taoDbConfig->getDbName(), $backupPath]);
             break;
         case 'pdo_mysql':
             $command = vsprintf("mysqldump -u%s -p%s %s --add-drop-table | gzip > %s", [$this->taoDbConfig->getDbUser(), $this->taoDbConfig->getDbPass(), $this->taoDbConfig->getDbName(), $backupPath]);
             break;
         default:
             throw new BuildException('DB Driver is not supported');
             break;
     }
     if ($command) {
         $execTask->setCommand($command);
         $execTask->main();
         $this->log(sprintf('Backup for %s created at %s', $this->taoDbConfig->getDbName(), $backupPath));
     }
 }
Пример #5
0
 public function main()
 {
     if (empty($this->_target)) {
         $message = 'Param "target" not found.';
         throw new BuildException($message);
     }
     $this->_checkHost($this->_host);
     $msg = sprintf("Host: %s, IPs found: %s", $host, implode(' ', $this->_ips));
     $this->log($msg);
     $msg = sprintf('Target: %s', $this->_target);
     $this->log($msg);
     $commandAr = array();
     $buildDirRoot = $this->getProject()->getProperty('build.dir.root');
     $commandAr[] = $buildDirRoot . '/bin/phing';
     $projectBasedir = $this->getProject()->getProperty('project.basedir');
     $commandAr[] = sprintf('-f %s/build.xml', $projectBasedir);
     $commandAr[] = $this->_target;
     $buildType = $this->getProject()->getProperty('build.type');
     $commandAr[] = sprintf('-Dbt=%s', $buildType);
     $buildUser = $this->getProject()->getProperty('build.user');
     if ($buildUser) {
         $commandAr[] = sprintf('-Dbu=%s', $buildUser);
     }
     $buildBranch = $this->getProject()->getProperty('build.branch');
     if ($buildBranch) {
         $commandAr[] = sprintf('-Dbb=%s', $buildBranch);
     }
     foreach ($this->_ips as $ip) {
         $command = sprintf('ssh %s %s', $ip, implode(' ', $commandAr));
         $msg = 'Run command ' . $command;
         $this->log($msg);
         $returnProp = 'remote.return';
         $outputProp = 'remote.output';
         $obj = new ExecTask();
         $obj->setProject($this->project);
         $obj->setCommand($command);
         $obj->setLogoutput(true);
         $obj->setReturnProperty($returnProp);
         $obj->setOutputProperty($outputProp);
         $obj->setCheckreturn($this->_checkreturn);
         $obj->setPassthru(true);
         $obj->setLevel('info');
         $obj->main();
     }
 }
Пример #6
0
 protected function _exec($command)
 {
     $task = new ExecTask();
     $task->setProject($this->project);
     $task->setCommand($command);
     $task->setCheckreturn(true);
     $task->setLogoutput(true);
     $task->setLevel('info');
     $this->log($command, Project::MSG_INFO);
     return $task->main();
 }
Пример #7
0
 /**
  * Sets up the environment for toExecute and then runs it.
  * @param Commandline $toExecute
  * @throws BuildException
  */
 protected function runCommand(Commandline $toExecute)
 {
     // We are putting variables into the script's environment
     // and not removing them (!)  This should be fine, but is
     // worth remembering and testing.
     if ($this->port > 0) {
         putenv("CVS_CLIENT_PORT=" . $this->port);
     }
     // Need a better cross platform integration with <cvspass>, so
     // use the same filename.
     if ($this->passFile === null) {
         $defaultPassFile = new PhingFile(Phing::getProperty("cygwin.user.home", Phing::getProperty("user.home")) . DIRECTORY_SEPARATOR . ".cvspass");
         if ($defaultPassFile->exists()) {
             $this->setPassfile($defaultPassFile);
         }
     }
     if ($this->passFile !== null) {
         if ($this->passFile->isFile() && $this->passFile->canRead()) {
             putenv("CVS_PASSFILE=" . $this->passFile->__toString());
             $this->log("Using cvs passfile: " . $this->passFile->__toString(), Project::MSG_INFO);
         } elseif (!$this->passFile->canRead()) {
             $this->log("cvs passfile: " . $this->passFile->__toString() . " ignored as it is not readable", Project::MSG_WARN);
         } else {
             $this->log("cvs passfile: " . $this->passFile->__toString() . " ignored as it is not a file", Project::MSG_WARN);
         }
     }
     if ($this->cvsRsh !== null) {
         putenv("CVS_RSH=" . $this->cvsRsh);
     }
     // Use the ExecTask to handle execution of the command
     $exe = new ExecTask($this->project);
     $exe->setProject($this->project);
     //exe.setAntRun(project);
     if ($this->dest === null) {
         $this->dest = $this->project->getBaseDir();
     }
     if (!$this->dest->exists()) {
         $this->dest->mkdirs();
     }
     if ($this->output !== null) {
         $exe->setOutput($this->output);
     }
     if ($this->error !== null) {
         $exe->setError($this->error);
     }
     $exe->setDir($this->dest);
     if (is_object($toExecute)) {
         $toExecuteStr = $toExecute->__toString();
         // unfortunately no more automagic for initial 5.0.0 release :(
     }
     $exe->setCommand($toExecuteStr);
     try {
         $actualCommandLine = $toExecuteStr;
         // we converted to string above
         $this->log($actualCommandLine, Project::MSG_INFO);
         $retCode = $exe->execute();
         $this->log("retCode=" . $retCode, Project::MSG_DEBUG);
         /*Throw an exception if cvs exited with error. (Iulian)*/
         if ($this->failOnError && $retCode !== 0) {
             throw new BuildException("cvs exited with error code " . $retCode . PHP_EOL . "Command line was [" . $toExecute->describeCommand() . "]", $this->getLocation());
         }
     } catch (IOException $e) {
         if ($this->failOnError) {
             throw new BuildException($e, $this->getLocation());
         } else {
             $this->log("Caught exception: " . $e, Project::MSG_WARN);
         }
     } catch (BuildException $e) {
         if ($this->failOnError) {
             throw $e;
         } else {
             $t = $e->getCause();
             if ($t === null) {
                 $t = $e;
             }
             $this->log("Caught exception: " . $t, Project::MSG_WARN);
         }
     } catch (Exception $e) {
         if ($this->failOnError) {
             throw new BuildException($e, $this->getLocation());
         } else {
             $this->log("Caught exception: " . $e, Project::MSG_WARN);
         }
     }
 }
Пример #8
0
 private function _delete(SimpleXMLElement $lib, &$items, $keepOldVersions)
 {
     $res = array();
     $libName = strval($lib->getName());
     $tmp = is_array($items[$libName]) ? $items[$libName] : array();
     $tmp = array_slice($tmp, $keepOldVersions);
     $deleteHelper = new ExecTask();
     $deleteHelper->setProject($this->_project);
     $deleteHelper->setLogoutput = true;
     $deleteHelper->setCheckreturn = true;
     foreach ($tmp as $deletedItem) {
         $dst = $deletedItem['dst'];
         $tag = $deletedItem['tag'];
         if ($dst != $lib->deploy->dst) {
             if (strpos(Phing::getProperty('host.fstype'), 'WIN') === 0) {
                 $deleteHelper->setCommand('rmdir /S /Q ' . escapeshellarg($dst));
             } else {
                 $deleteHelper->setCommand('rm -rf ' . escapeshellarg($dst));
             }
             $deleteHelper->main();
             unset($items[$libName][$tag]);
             $res[] = $dst;
         }
     }
     unset($deleteHelper);
     return $res;
 }
Пример #9
0
 /**
  * Fulfill the condition interface.
  * @return boolean the result of evaluating the specified return code.
  */
 public function evaluate()
 {
     return ExecTask::isFailureCode($this->code);
 }