Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task assembly #284

Merged
merged 34 commits into from Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cea3129
Create a task assembly step, and use it in all loadTasks. This allows…
greg-1-anderson Mar 7, 2016
084e165
Improve styling of simulator output.
greg-1-anderson Mar 7, 2016
3d59092
Fix Nitpick CI issues.
greg-1-anderson Mar 7, 2016
dcf1b03
Automatically exclude accessor methods from command list.
greg-1-anderson Mar 7, 2016
f0ae7e9
Use reverse styling instead of assuming the terminal colors.
greg-1-anderson Mar 7, 2016
dfff660
Switch to league/container for Dependency Injection.
greg-1-anderson Mar 10, 2016
d9c20af
Adjust whitespace for NitPick.
greg-1-anderson Mar 10, 2016
ec5d60f
Remove test code left in by accident.
greg-1-anderson Mar 11, 2016
4b3f964
Use ::class instead of strings when setting up DI container.
greg-1-anderson Mar 13, 2016
5f66ab3
Declare minimum php to be 5.5 now.
greg-1-anderson Mar 13, 2016
254c647
Don't test php 5.4.
greg-1-anderson Mar 13, 2016
009fcde
Remove all loadTask traits; fetch from our container instead.
greg-1-anderson Mar 14, 2016
269e6d0
Filter out accessor methods from command list.
greg-1-anderson Mar 14, 2016
40b1bf5
Fix spacing for NitPick.
greg-1-anderson Mar 15, 2016
ff7850b
Introdoce 'task' convenience function to make fetching task services …
greg-1-anderson Mar 15, 2016
eb0d5c7
Remove workaround in RoboContainer now that League/Container has been…
greg-1-anderson Mar 15, 2016
3990a7c
Simplify service providers with SimpleServiceProvider.php.
greg-1-anderson Mar 16, 2016
f7ef6dc
Fix NitPick style.
greg-1-anderson Mar 16, 2016
8e40124
Put back loadTasks traits.
greg-1-anderson Mar 16, 2016
729202a
Simplify CliHelper to just use Tasklib (with appropriate remaps to 'p…
greg-1-anderson Mar 16, 2016
8a014a8
Adjust spacing in Bower\loadTasks.
greg-1-anderson Mar 16, 2016
12b1255
Use __FUNCTION__ in loadTasks to ensure a strong corrolation between …
greg-1-anderson Mar 16, 2016
426cf5f
Restore RoboFile to previous version (resume use of loadTask shortcuts).
greg-1-anderson Mar 16, 2016
3ee6235
Be more consistent with container use for object initialization.
greg-1-anderson Mar 16, 2016
8388ce3
Formalize wrapped tasks.
greg-1-anderson Mar 16, 2016
cd4fbed
Do not wrap our wrappers. Do not unwrap the Simulator when adding to …
greg-1-anderson Mar 16, 2016
9e0c4b0
Ensure that logger is always configured for core Robo tasks. Emit a d…
greg-1-anderson Mar 16, 2016
bf25add
Use SimpleServiceProvider to register Collection services.
greg-1-anderson Mar 16, 2016
ac88ae9
SimpleServiceProvider does not need to be abstract.
greg-1-anderson Mar 16, 2016
9b31b4e
Move File ServiceProviders into loadTasks.
greg-1-anderson Mar 16, 2016
a1515f6
Move all of the ServiceProvider classes into loadTasks.
greg-1-anderson Mar 17, 2016
d141895
Fix a couple of style problems.
greg-1-anderson Mar 17, 2016
699d388
Use AbstractSignatureServiceProvider in SimpleServiceProvider so that…
greg-1-anderson Mar 17, 2016
cf079a1
Use league/container 2.2
greg-1-anderson Mar 17, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
Expand Down
40 changes: 40 additions & 0 deletions RoboFile.php
Expand Up @@ -346,4 +346,44 @@ public function trySuccess()
{
$result = $this->taskExec('pwd')->run();
}

public function tryDeprecated()
{
$result = (new \Robo\Task\Base\Exec('pwd'))->run();
}

public function tryTmpDir()
{
// Set up a collection to add tasks to
$collection = $this->collection();

// Get a temporary directory to work in. Note that we get a
// name back, but the directory is not created until the task
// runs. This technically is not thread-safe, but we create
// a random name, so it is unlikely to conflict.
$tmpPath = $this->taskTmpDir()
->addToCollection($collection)
->getPath();

// We can create the temporary directory early by running
// 'runWithoutCompletion()'. n.b. if we called 'run()' at
// this point, the collection's 'complete()' method would be
// called, and the temporary directory would be deleted.
$mktmpResult = $collection->runWithoutCompletion();

if (is_dir($tmpPath)) {
$this->say("Created a temporary directory at $tmpPath");
} else {
$this->say("Requested a temporary directory at $tmpPath, but it was not created");
}

// Run the task collection
$result = $collection->run();

if (is_dir($tmpPath)) {
$this->say("The temporary directory at $tmpPath was not cleaned up after the collection completed.");
} else {
$this->say("The temporary directory at $tmpPath was automatically deleted.");
}
}
}
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -15,13 +15,13 @@
},
"bin":["robo"],
"require": {
"php": ">=5.4.0",
"php": ">=5.5.0",
"consolidation/log": "~0",
"symfony/finder": "~2.5|~3.0",
"symfony/console": "~2.5|~3.0",
"symfony/process": "~2.5|~3.0",
"symfony/filesystem": "~2.5|~3.0",
"symfony/dependency-injection": "~2.5|~3.0"
"league/container": "~2.2"
},
"require-dev": {
"patchwork/jsqueeze": "~1.0",
Expand Down
119 changes: 105 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 deletions src/Application.php
Expand Up @@ -7,27 +7,51 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;

class Application extends SymfonyApplication
use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;

class Application extends SymfonyApplication implements ContainerAwareInterface
{
use ContainerAwareTrait;

public function __construct($name, $version)
{
parent::__construct($name, $version);

$this->getDefinition()->addOption(
new InputOption('--simulate', null, InputOption::VALUE_NONE, 'Run in simulated mode (show what would have happened).')
);
}

public function addCommandsFromClass($className, $passThrough = null)
{
$container = $this->getContainer();
$roboTasks = new $className;
if ($roboTasks instanceof ContainerAwareInterface) {
$roboTasks->setContainer($container);
}

$commandNames = array_filter(get_class_methods($className), function($m) {
return !in_array($m, ['__construct']);
// Ignore special functions, such as __construct() and __call(), and
// accessor methods such as getFoo() and setFoo(), while allowing
// set or setup.
$commandNames = array_filter(get_class_methods($className), function ($m) {
return !preg_match('#^(_|get[A-Z]|set[A-Z])#', $m);
});

foreach ($commandNames as $commandName) {
$command = $this->createCommand(new TaskInfo($className, $commandName));
$command->setCode(function(InputInterface $input) use ($roboTasks, $commandName, $passThrough) {
$command->setCode(function (InputInterface $input) use ($roboTasks, $commandName, $passThrough, $container) {
// get passthru args
$args = $input->getArguments();
array_shift($args);
if ($passThrough) {
$args[key(array_slice($args, -1, 1, TRUE))] = $passThrough;
}
$args[] = $input->getOptions();
// Need a better way to handle global options
// Also, this is not necessarily the best place to do this
Config::setGlobalOptions($input);
$container->setSimulated(Config::isSimulated());

$res = call_user_func_array([$roboTasks, $commandName], $args);
if (is_int($res)) exit($res);
Expand Down Expand Up @@ -97,4 +121,4 @@ public function addInitRoboFileCommand($roboFile, $roboClass)
});
$this->add($createRoboFile);
}
}
}
24 changes: 22 additions & 2 deletions src/Collection/Collection.php
Expand Up @@ -3,6 +3,10 @@

use Robo\Result;
use Robo\Contract\TaskInterface;
use Robo\Container\SimpleServiceProvider;

use League\Container\ContainerAwareInterface;
use League\Container\ContainerAwareTrait;

/**
* Group tasks into a collection that run together. Supports
Expand Down Expand Up @@ -30,8 +34,10 @@
* ?>
* ```
*/
class Collection implements TaskInterface
class Collection implements TaskInterface, ContainerAwareInterface
{
use ContainerAwareTrait;

// Unnamed tasks are assigned an arbitrary numeric index
// in the task list. Any numeric value may be used, but the
// UNNAMEDTASK constant is recommended for clarity.
Expand All @@ -42,6 +48,19 @@ class Collection implements TaskInterface
protected $completionStack = [];
protected $previousResult;

/**
* Return services.
*/
public static function getCollectionServices()
{
return new SimpleServiceProvider(
[
'collection' => Collection::class,
'completionWrapper' => CompletionWrapper::class,
]
);
}

/**
* Constructor.
*/
Expand Down Expand Up @@ -274,7 +293,8 @@ protected function addTask($name, $task)
{
// Wrap the task as necessary.
$task = $this->wrapTask($task);
$this->addToTaskStack($name, new TaskWrapper($this, $task));
$task = $this->getContainer()->get('completionWrapper', [$this, $task]);
$this->addToTaskStack($name, $task);
return $this;
}

Expand Down