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 6 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good choice )

},
"require-dev": {
"patchwork/jsqueeze": "~1.0",
Expand Down
107 changes: 99 additions & 8 deletions composer.lock

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

65 changes: 63 additions & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,70 @@

class Application extends SymfonyApplication
{
/**
* @var \Robo\TaskAssembler
*/
protected $taskAssembler;

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 setTaskAssembler($taskAssembler)
{
$this->taskAssembler = $taskAssembler;
}

public function taskAssembler()
{
return $this->taskAssembler;
}

protected static function findAccessorMethods($commandNames)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this method is really needed. See notes below

{
$accessorNames = [];
// Using get_class_vars is not reliable, because it only
// exposes public class variables.
foreach ($commandNames as $commandName) {
// We count a set of methods as accessor methods if
// there is a setter and at least one getter.
if (strpos($commandName, 'set') === 0) {
$name = lcfirst(substr($commandName, 3));
$getter = 'get' . ucfirst($name);
$hasGetter = false;
if (in_array($name, $commandNames)) {
$accessorNames[] = $name;
$hasGetter = true;
}
if (in_array($getter, $commandNames)) {
$accessorNames[] = $getter;
$hasGetter = true;
}
if ($hasGetter) {
$accessorNames[] = $commandName;
}
}
}
return $accessorNames;
}

public function addCommandsFromClass($className, $passThrough = null)
{
$roboTasks = new $className;
if ($roboTasks instanceof \Robo\Tasks) {
$roboTasks->setTaskAssembler($this->taskAssembler);
}

$commandNames = array_filter(get_class_methods($className), function($m) {
$commandNames = array_filter(get_class_methods($className), function ($m) {
return !in_array($m, ['__construct']);
});
$accessorNames = static::findAccessorMethods($commandNames);
$commandNames = array_diff($commandNames, $accessorNames);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you need findAccessorMethods method actually.
If you think it is important to ignore getters in setters in command list, just ignore commands starting from get and set prefexes (but take camelCase into account setUp - ignored, but setup added as command)


foreach ($commandNames as $commandName) {
$command = $this->createCommand(new TaskInfo($className, $commandName));
Expand All @@ -28,6 +84,11 @@ public function addCommandsFromClass($className, $passThrough = null)
$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);
// Avoid making taskAssembler depend on Config class.
Config::service('taskAssembler')->setSimulated(Config::isSimulated());

$res = call_user_func_array([$roboTasks, $commandName], $args);
if (is_int($res)) exit($res);
Expand Down Expand Up @@ -97,4 +158,4 @@ public function addInitRoboFileCommand($roboFile, $roboClass)
});
$this->add($createRoboFile);
}
}
}
25 changes: 20 additions & 5 deletions src/Common/TaskIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
*/
trait TaskIO
{
/**
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

public function setLogger($logger)
{
$this->logger = $logger;
}

public function logger()
{
return $this->logger ?: Config::logger();
}

/**
* Print information about a task in progress.
*
Expand All @@ -31,7 +46,7 @@ protected function printTaskInfo($text, $context = null)
// The 'note' style is used for both 'notice' and 'info' log levels;
// However, 'notice' is printed at VERBOSITY_NORMAL, whereas 'info'
// is only printed at VERBOSITY_VERBOSE.
Config::logger()->notice($text, $this->getTaskContext($context));
$this->logger()->notice($text, $this->getTaskContext($context));
}

/**
Expand All @@ -48,7 +63,7 @@ protected function printTaskSuccess($text, $context = null)
// override in the context so that this message will be
// logged as SUCCESS if that log level is recognized.
$context['_level'] = ConsoleLogLevel::SUCCESS;
Config::logger()->notice($text, $this->getTaskContext($context));
$this->logger()->notice($text, $this->getTaskContext($context));
}

/**
Expand All @@ -59,7 +74,7 @@ protected function printTaskSuccess($text, $context = null)
*/
protected function printTaskWarning($text, $context = null)
{
Config::logger()->warning($text, $this->getTaskContext($context));
$this->logger()->warning($text, $this->getTaskContext($context));
}

/**
Expand All @@ -70,7 +85,7 @@ protected function printTaskWarning($text, $context = null)
*/
protected function printTaskError($text, $context = null)
{
Config::logger()->error($text, $this->getTaskContext($context));
$this->logger()->error($text, $this->getTaskContext($context));
}

/**
Expand All @@ -79,7 +94,7 @@ protected function printTaskError($text, $context = null)
*/
protected function printTaskDebug($text, $context = null)
{
Config::logger()->debug($text, $this->getTaskContext($context));
$this->logger()->debug($text, $this->getTaskContext($context));
}

/**
Expand Down