public function process($result, array $args) { if ($result instanceof TaskInterface) { try { return $result->run(); } catch (\Exception $e) { return Result::fromException($result, $e); } } }
/** * @param \Robo\Result|\Robo\Contract\TaskInterface $result * @param \Consolidation\AnnotatedCommand\CommandData $commandData * * @return null|\Robo\Result */ public function process($result, CommandData $commandData) { if ($result instanceof TaskInterface) { try { return $result->run(); } catch (\Exception $e) { return Result::fromException($result, $e); } } }
protected function findFiles($dirs) { $files = array(); // find the files foreach ($dirs as $k => $v) { // reset finder $finder = new Finder(); $dir = $k; $to = $v; // check if target was given with the to() method instead of key/value pairs if (is_int($k)) { $dir = $v; if (isset($this->to)) { $to = $this->to; } else { throw new TaskException($this, 'target directory is not defined'); } } try { $finder->files()->in($dir); } catch (\InvalidArgumentException $e) { // if finder cannot handle it, try with in()->name() if (strpos($dir, '/') === false) { $dir = './' . $dir; } $parts = explode('/', $dir); $new_dir = implode('/', array_slice($parts, 0, -1)); try { $finder->files()->in($new_dir)->name(array_pop($parts)); } catch (\InvalidArgumentException $e) { return Result::fromException($this, $e); } } foreach ($finder as $file) { // store the absolute path as key and target as value in the files array $files[$file->getRealpath()] = $this->getTarget($file->getRealPath(), $to); } $fileNoun = count($files) == 1 ? ' file' : ' files'; $this->printTaskInfo("Found {count} {$fileNoun} in {dir}", ['count' => count($files), 'dir' => $dir]); } return $files; }
/** * Run every task in a list, but only up to the first failure. * Return the failing result, or success if all tasks run. * * @param string $name * @param TaskInterface[] $taskList * @param \Robo\Result $result * * @return \Robo\Result * * @throws \Robo\Exception\TaskExitException */ private function runTaskList($name, array $taskList, Result $result) { try { foreach ($taskList as $taskName => $task) { $taskResult = $this->runSubtask($task); $this->advanceProgressIndicator(); // If the current task returns an error code, then stop // execution and signal a rollback. if (!$taskResult->wasSuccessful()) { return $taskResult; } // We accumulate our results into a field so that tasks that // have a reference to the collection may examine and modify // the incremental results, if they wish. $key = Result::isUnnamed($taskName) ? $name : $taskName; $result->accumulate($key, $taskResult); } } catch (TaskExitException $exitException) { $this->fail(); throw $exitException; } catch (\Exception $e) { // Tasks typically should not throw, but if one does, we will // convert it into an error and roll back. return Result::fromException($task, $e, $result->getData()); } return $result; }
/** * {@inheritdoc} */ public function run() { $finalResult = Result::success($this); $this->startProgressIndicator(); foreach ($this->iterable as $key => $value) { $this->showIterationMessage($key, $value); try { foreach ($this->functionStack as $fn) { $result = call_user_func($fn, $key, $value); $this->advanceProgressIndicator(); if (!isset($result)) { $result = Result::success($this); } // If the function returns a result, it must either return // a \Robo\Result or an exit code. In the later case, we // convert it to a \Robo\Result. if (!$result instanceof Result) { $result = new Result($this, $result); } if (!$result->wasSuccessful()) { return $result; } $finalResult = $result->merge($finalResult); } } catch (\Exception $e) { return Result::fromException($result, $e); } } $this->stopProgressIndicator(); return $finalResult; }
/** * {@inheritdoc} */ public function run() { $this->printAction(); $this->process = new Process($this->getCommand()); $this->process->setTimeout($this->timeout); $this->process->setIdleTimeout($this->idleTimeout); $this->process->setWorkingDirectory($this->workingDirectory); if (isset($this->env)) { $this->process->setEnv($this->env); } if (!$this->background and !$this->isPrinted) { $this->startTimer(); $this->process->run(); $this->stopTimer(); return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]); } if (!$this->background and $this->isPrinted) { $this->startTimer(); $this->process->run(function ($type, $buffer) { $progressWasVisible = $this->hideTaskProgress(); print $buffer; $this->showTaskProgress($progressWasVisible); }); $this->stopTimer(); return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]); } try { $this->process->start(); } catch (\Exception $e) { return Result::fromException($this, $e); } return Result::success($this); }
/** * Execute one task method */ protected function callTaskMethod($command, $action) { try { $function_result = call_user_func_array($command, $action); return $this->processResult($function_result); } catch (\Exception $e) { $this->printTaskError($e->getMessage()); return Result::fromException($this, $e); } }