/** * 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); } } }