Example #1
0
 function __toString()
 {
     if ($this->isRoot()) {
         return __('Root directory');
     } else {
         return parent::__toString();
     }
 }
Example #2
0
 /**
  * Executes a program and returns the return code.
  * Output from command is logged at INFO level.
  * @return int Return code from execution.
  */
 public function execute()
 {
     // test if os match
     $myos = Phing::getProperty("os.name");
     $this->log("Myos = " . $myos, PROJECT_MSG_VERBOSE);
     if ($this->os !== null && strpos($os, $myos) === false) {
         // this command will be executed only on the specified OS
         $this->log("Not found in " . $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
         $this->command = escapeshellcmd($this->command);
     }
     if ($this->error !== null) {
         $this->command .= ' 2> ' . $this->error->getPath();
         $this->log("Writing error output to: " . $this->error->getPath());
     }
     if ($this->output !== null) {
         $this->command .= ' 1> ' . $this->output->getPath();
         $this->log("Writing standard output to: " . $this->output->getPath());
     } elseif ($this->spawn) {
         $this->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) {
         $this->command .= ' 2>&1';
     }
     // we ignore the spawn boolean for windows
     if ($this->spawn) {
         $this->command .= ' &';
     }
     $this->log("Executing command: " . $this->command);
     $output = array();
     $return = null;
     exec($this->command, $output, $return);
     if ($this->dir !== null) {
         @chdir($currdir);
     }
     foreach ($output as $line) {
         $this->log($line, $this->passthru ? PROJECT_MSG_INFO : PROJECT_MSG_VERBOSE);
     }
     if ($return != 0 && $this->checkreturn) {
         throw new BuildException("Task exited with code {$return}");
     }
     return $return;
 }
Example #3
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);
         }
     }
 }
 /**
  * Executes a program and returns the return code.
  * Output from command is logged at INFO level.
  * @return int Return code from execution.
  */
 public function execute()
 {
     // 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());
         }
     }
     $this->command = 'svn info -r HEAD ' . $this->dir;
     if ($this->error !== null) {
         $this->command .= ' 2> ' . $this->error->getPath();
         $this->log("Writing error output to: " . $this->error->getPath());
     }
     if ($this->output !== null) {
         $this->command .= ' 1> ' . $this->output->getPath();
         $this->log("Writing standard output to: " . $this->output->getPath());
     } elseif ($this->spawn) {
         $this->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) {
         $this->command .= ' 2>&1';
     }
     // we ignore the spawn boolean for windows
     if ($this->spawn) {
         $this->command .= ' &';
     }
     $this->log("Getting \"svn info -r HEAD\" on " . $this->dir);
     $output = array();
     $return = null;
     exec($this->command, $output, $return);
     if ($this->dir !== null) {
         @chdir($currdir);
     }
     foreach ($output as $line) {
         $this->log($line, $this->passthru ? Project::MSG_INFO : Project::MSG_VERBOSE);
     }
     $str = implode("\n", $output);
     $matches = array();
     if (preg_match('/Rev:[\\s]+([\\d]+)/', $str, $matches) && $this->revisionProperty) {
         $this->project->setProperty($this->revisionProperty, $matches[1]);
         $this->log("HEAD revision on " . $this->dir . " should be " . $matches[1]);
     }
     if ($this->returnProperty) {
         $this->project->setProperty($this->returnProperty, $return);
     }
     if ($return != 0 && $this->checkreturn) {
         throw new BuildException("Task exited with code {$return}");
     }
     return $return;
 }