/** * {@inheritdoc} */ public function run() { if (is_null($this->dst) || "" === $this->dst) { return Result::error($this, 'You must specify a destination file with to() method.'); } if (!$this->checkResources($this->files, 'file')) { return Result::error($this, 'Source files are missing!'); } if (file_exists($this->dst) && !is_writable($this->dst)) { return Result::error($this, 'Destination already exists and cannot be overwritten.'); } $dump = ''; foreach ($this->files as $path) { foreach (glob($path) as $file) { $dump .= file_get_contents($file) . "\n"; } } $this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]); $dst = $this->dst . '.part'; $write_result = file_put_contents($dst, $dump); if (false === $write_result) { @unlink($dst); return Result::error($this, 'File write failed.'); } // Cannot be cross-volume; should always succeed. @rename($dst, $this->dst); return Result::success($this); }
/** * @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); } } }
/** * Log the result of a Robo task that was successful. */ protected function printSuccess(Result $result) { $task = $result->getTask(); $context = $result->getContext() + ['timer-label' => 'in']; $time = $result->getExecutionTime(); if ($time) { $this->printMessage(ConsoleLogLevel::SUCCESS, 'Done', $context); } return false; }
public function testStopOnFail() { $exceptionClass = false; $task = new ResultDummyTask(); Result::$stopOnFail = true; $result = Result::success($task, "Something that worked"); try { $result = Result::error($task, "Something that did not work"); // stopOnFail will cause Result::error() to throw an exception, // so we will never get here. If we did, the assert below would fail. $this->assertTrue($result->wasSuccessful()); $this->assertTrue(false); } catch (\Exception $e) { $exceptionClass = get_class($e); } $this->assertEquals(TaskExitException::class, $exceptionClass); $this->assertTrue($result->wasSuccessful()); /* // This gives an error: // Exception of class Robo\Exception\TaskExitException expected to // be thrown, but PHPUnit_Framework_Exception caught // This happens whether or not the expected exception is thrown $this->guy->expectException(TaskExitException::class, function() { // $result = Result::error($task, "Something that did not work"); $result = Result::success($task, "Something that worked"); }); */ Result::$stopOnFail = false; }
/** * {@inheritdoc} */ public function run() { if (!$this->skip()) { return $this->exec()->arg('locale-update')->run(); } return Result::success($this); }
public function run() { foreach ($this->dirs as $dir) { $this->fs->remove($dir); $this->printTaskInfo("deleted <info>{$dir}</info>..."); } return Result::success($this); }
public function run() { foreach ($this->dirs as $dir) { $this->emptyDir($dir); $this->printTaskInfo("Cleaned <info>{$dir}</info>"); } return Result::success($this); }
/** * {@inheritdoc} */ public function run() { Environment::set($this->environment); if (Environment::isDevdesktop()) { $this->ensureDevdesktopPath(); } return Result::success($this); }
public function run() { foreach ($this->dirs as $src => $dst) { $this->copyDir($src, $dst); $this->printTaskInfo("Copied from <info>{$src}</info> to <info>{$dst}</info>"); } return Result::success($this); }
public function run() { foreach ($this->dirs as $src => $dst) { $this->fs->mirror($src, $dst, null, ['override' => true, 'copy_on_windows' => true, 'delete' => true]); $this->printTaskInfo("Mirrored from {source} to {destination}", ['source' => $src, 'destination' => $dst]); } return Result::success($this); }
public function run() { foreach ($this->dirs as $src => $dst) { $this->fs->mirror($src, $dst, null, ['override' => true, 'copy_on_windows' => true, 'delete' => true]); $this->printTaskInfo("Mirrored from <info>{$src}</info> to <info>{$dst}</info>"); } return Result::success($this); }
public function run() { $delegate = new \ReflectionClass($this->className); $replacements = []; $leadingCommentChars = " * "; $methodDescriptions = []; $methodImplementations = []; $immediateMethods = []; foreach ($delegate->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { $methodName = $method->name; $getter = preg_match('/^(get|has|is)/', $methodName); $setter = preg_match('/^(set|unset)/', $methodName); $argPrototypeList = []; $argNameList = []; $needsImplementation = false; foreach ($method->getParameters() as $arg) { $argDescription = '$' . $arg->name; $argNameList[] = $argDescription; if ($arg->isOptional()) { $argDescription = $argDescription . ' = ' . str_replace("\n", "", var_export($arg->getDefaultValue(), true)); // We will create wrapper methods for any method that // has default parameters. $needsImplementation = true; } $argPrototypeList[] = $argDescription; } $argPrototypeString = implode(', ', $argPrototypeList); $argNameListString = implode(', ', $argNameList); if ($methodName[0] != '_') { $methodDescriptions[] = "@method {$methodName}({$argPrototypeString})"; if ($getter) { $immediateMethods[] = " public function {$methodName}({$argPrototypeString})\n {\n return \$this->delegate->{$methodName}({$argNameListString});\n }"; } elseif ($setter) { $immediateMethods[] = " public function {$methodName}({$argPrototypeString})\n {\n \$this->delegate->{$methodName}({$argNameListString});\n return \$this;\n }"; } elseif ($needsImplementation) { // Include an implementation for the wrapper method if necessary $methodImplementations[] = " protected function _{$methodName}({$argPrototypeString})\n {\n \$this->delegate->{$methodName}({$argNameListString});\n }"; } } } $classNameParts = explode('\\', $this->className); $delegate = array_pop($classNameParts); $delegateNamespace = implode('\\', $classNameParts); if (empty($this->wrapperClassName)) { $this->wrapperClassName = $delegate; } $replacements['{delegateNamespace}'] = $delegateNamespace; $replacements['{delegate}'] = $delegate; $replacements['{wrapperClassName}'] = $this->wrapperClassName; $replacements['{taskname}'] = "task{$delegate}"; $replacements['{methodList}'] = $leadingCommentChars . implode("\n{$leadingCommentChars}", $methodDescriptions); $replacements['{immediateMethods}'] = "\n\n" . implode("\n\n", $immediateMethods); $replacements['{methodImplementations}'] = "\n\n" . implode("\n\n", $methodImplementations); $template = file_get_contents(__DIR__ . "/GeneratedWrapper.tmpl"); $template = str_replace(array_keys($replacements), array_values($replacements), $template); // Returning data in the $message will cause it to be printed. return Result::success($this, $template); }
public function run() { $this->printTaskInfo("Writing {$this->filename}"); $res = file_put_contents($this->filename, $this->body); if ($res === false) { return Result::error($this, "File {$this->filename} couldnt be created"); } return Result::success($this); }
/** * Check for availablilty of PHP extensions. */ protected function checkExtension($service, $extensionList) { foreach ((array) $extensionList as $ext) { if (!extension_loaded($ext)) { return Result::error($this, "You must use PHP with the {$ext} extension enabled to use {$service}"); } } 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 (IOExceptionInterface $e) { $this->printTaskInfo("<error>" . $e->getMessage() . "</error>"); return Result::error($this, $e->getMessage(), $e->getPath()); } }
public function process($result, array $args) { if ($result instanceof TaskInterface) { try { return $result->run(); } catch (\Exception $e) { return Result::fromException($result, $e); } } }
/** * {@inheritdoc} */ public function run() { if (!$this->checkResources($this->dirs, 'dir')) { return Result::error($this, 'Source directories are missing!'); } foreach ($this->dirs as $dir) { $this->fs->remove($dir); $this->printTaskInfo("Deleted {dir}...", ['dir' => $dir]); } return Result::success($this); }
public function run() { if (!$this->checkResources($this->dirs, 'dir')) { return Result::error($this, 'Source directories are missing!'); } foreach ($this->dirs as $src => $dst) { $this->copyDir($src, $dst); $this->printTaskInfo("Copied from <info>{$src}</info> to <info>{$dst}</info>"); } return Result::success($this); }
/** * {@inheritdoc} */ public function run() { if (!$this->checkResources($this->dirs, 'dir')) { return Result::error($this, 'Source directories are missing!'); } foreach ($this->dirs as $src => $dst) { $this->copyDir($src, $dst); $this->printTaskInfo('Copied from {source} to {destination}', ['source' => $src, 'destination' => $dst]); } return Result::success($this); }
public function __construct($username = '', $password = '', $pathToSvn = 'svn') { $this->executable = $pathToSvn; if (!empty($username)) { $this->executable .= " --username {$username}"; } if (!empty($password)) { $this->executable .= " --password {$password}"; } $this->result = Result::success($this); }
public function run() { if (!$this->checkResources($this->dirs, 'dir')) { return Result::error($this, 'Source directories are missing!'); } foreach ($this->dirs as $dir) { $this->emptyDir($dir); $this->printTaskInfo("Cleaned <info>{$dir}</info>"); } return Result::success($this); }
public function run() { if ($this->check()) { return Result::success($this); } $message = 'One or more requirements failed'; if ($this->stopOnFail) { $requirements = array_keys($this->results); $message = array_pop($requirements); } return Result::error($this, $message); }
public function run() { $openCommand = $this->getOpenCommand(); if (empty($openCommand)) { return Result::error($this, 'no suitable browser opening command found'); } foreach ($this->urls as $url) { passthru(sprintf($openCommand, ProcessUtils::escapeArgument($url))); $this->printTaskInfo("Opened <info>{$url}</info>"); } return Result::success($this); }
/** * Create our temporary directory. */ public function run() { // Save the current working directory $this->savedWorkingDirectory = getcwd(); foreach ($this->dirs as $dir) { $this->fs->mkdir($dir); $this->printTaskInfo("Created <info>{$dir}</info>..."); // Change the current working directory, if requested if ($this->cwd) { chdir($dir); } } return Result::success($this, '', ['path' => $this->getPath()]); }
function execute($opts) { $answer = $this->ask("Bulding Docker container takes some time, you can use already provisioned image instead.\nDo you want to continue? (y/n)"); if (trim(strtolower($answer)) != 'y') { return; } Result::$stopOnFail = true; $recipes = $opts['recipes'] ?: implode(',', Config::$travisRecipes); (new BuildRecipe('base'))->tag('roboci_base')->run(); $res = (new DockerRun('base'))->option('-i')->option('--privileged')->exec('/usr/bin/chef-solo -j /travis.json -o ' . $recipes)->run(); $this->taskDeleteDir(Config::$buildDir)->run(); $data = $res->getData(); $this->yell("Container built in successfully. Run `docker commit {$data['cid']} yourname/imagename` to save it"); }
/** * Demonstrates Robo input APIs. */ public function tryInput() { $answer = $this->ask('how are you?'); $this->say('You are ' . $answer); $yes = $this->confirm('Do you want one more question?'); if (!$yes) { return Result::cancelled(); } $lang = $this->askDefault('what is your favorite scripting language?', 'PHP'); $this->say($lang); $pin = $this->askHidden('Ok, now tell your PIN code (it is hidden)'); $this->yell('Ha-ha, your pin code is: ' . $pin); $this->say('Bye!'); }
public function run() { $watcher = new ResourceWatcher(); foreach ($this->monitor as $k => $monitor) { $closure = $monitor[1]; $closure->bindTo($this->bindTo); foreach ($monitor[0] as $i => $dir) { $watcher->track("fs.{$k}.{$i}", $dir, FilesystemEvent::MODIFY); $this->printTaskInfo("watching <info>{$dir}</info> for changes..."); $watcher->addListener("fs.{$k}.{$i}", $closure); } } $watcher->start(); return Result::success($this); }
public function run() { $result = call_user_func($this->fn); // If the function returns no result, then count it // as a success. 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); } return $result; }
/** * Create our working directory. * * @return \Robo\Result */ public function run() { // Destination cannot be empty if (empty($this->finalDestination)) { return Result::error($this, "Destination directory not specified."); } // Before we do anything else, ensure that any directory in the // final destination is writable, so that we can at a minimum // move it out of the way before placing our results there. if (is_dir($this->finalDestination)) { if (!is_writable($this->finalDestination)) { return Result::error($this, "Destination directory {dir} exists and cannot be overwritten.", ['dir' => $this->finalDestination]); } } return parent::run(); }
public function run() { if (empty($this->exec)) { throw new TaskException($this, 'You must add at least one command'); } if (!$this->stopOnFail) { return $this->taskExec($this->getCommand())->printed($this->isPrinted)->dir($this->workingDirectory)->run(); } foreach ($this->exec as $command) { $result = $this->taskExec($command)->printed($this->isPrinted)->dir($this->workingDirectory)->run(); if (!$result->wasSuccessful()) { return $result; } } return Result::success($this); }