Skip to content

Commit

Permalink
Issue #25: Remove custom path trait in favour of Symfony Filesystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ademarco committed Jan 12, 2018
1 parent 5cf966f commit de3afce
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 53 deletions.
12 changes: 6 additions & 6 deletions src/Commands/DrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace EC\OpenEuropa\TaskRunner\Commands;

use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use EC\OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface;
use EC\OpenEuropa\TaskRunner\Traits\ComposerAwareTrait;
use EC\OpenEuropa\TaskRunner\Traits\ConfigurationTokensTrait;
use EC\OpenEuropa\TaskRunner\Traits\PathUtilitiesTrait;
use EC\OpenEuropa\TaskRunner\Traits\FilesystemAwareTrait;
use Robo\Exception\TaskException;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -17,11 +18,11 @@
*
* @package EC\OpenEuropa\TaskRunner\Commands
*/
class DrupalCommands extends BaseCommands implements ComposerAwareInterface
class DrupalCommands extends BaseCommands implements ComposerAwareInterface, FilesystemAwareInterface
{
use ComposerAwareTrait;
use ConfigurationTokensTrait;
use PathUtilitiesTrait;
use FilesystemAwareTrait;
use \NuvoleWeb\Robo\Task\Config\Php\loadTasks;

/**
Expand Down Expand Up @@ -337,9 +338,8 @@ protected function setupSiteBuild($root, $symlinks = [])

foreach ($symlinks as $symlink) {
if (is_dir($symlink['from']) || $this->isSimulating()) {
$destination = $root.'/'.$symlink['to'];
$source = $this->walkPath($destination, $symlink['from']);
$collection->addTask($this->taskFilesystemStack()->symlink($source, $destination));
$source = $this->getFilesystem()->makePathRelative($symlink['from'], $symlink['to']);
$collection->addTask($this->taskFilesystemStack()->symlink($source, $root.'/'.$symlink['to']));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ComposerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function getComposer();

/**
* @param \EC\OpenEuropa\TaskRunner\Services\Composer $composer
*
* @return $this
*/
public function setComposer(Composer $composer);
}
23 changes: 23 additions & 0 deletions src/Contract/FilesystemAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace EC\OpenEuropa\TaskRunner\Contract;

/**
* Interface FilesystemAwareTrait
*
* @package EC\OpenEuropa\TaskRunner\Contract
*/
interface FilesystemAwareInterface
{
/**
* @return \Symfony\Component\Filesystem\Filesystem
*/
public function getFilesystem();

/**
* @param \Symfony\Component\Filesystem\Filesystem $filesystem
*
* @return $this
*/
public function setFilesystem($filesystem);
}
8 changes: 6 additions & 2 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EC\OpenEuropa\TaskRunner\Commands\DynamicCommands;
use EC\OpenEuropa\TaskRunner\Contract\ComposerAwareInterface;
use EC\OpenEuropa\TaskRunner\Services\Composer;
use EC\OpenEuropa\TaskRunner\Contract\FilesystemAwareInterface;
use League\Container\ContainerAwareTrait;
use Robo\Application;
use Robo\Common\ConfigAwareTrait;
Expand All @@ -18,6 +19,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* Class Application.
Expand Down Expand Up @@ -155,12 +157,14 @@ private function createContainer(InputInterface $input, OutputInterface $output,
{
$container = Robo::createDefaultContainer($input, $output, $application, $config);
$container->get('commandFactory')->setIncludeAllPublicMethods(false);
$container->share('task_runner.composer', Composer::class)
->withArgument(getcwd());
$container->share('task_runner.composer', Composer::class)->withArgument(getcwd());
$container->share('filesystem', Filesystem::class);

// Add service inflectors.
$container->inflector(ComposerAwareInterface::class)
->invokeMethod('setComposer', ['task_runner.composer']);
$container->inflector(FilesystemAwareInterface::class)
->invokeMethod('setFilesystem', ['filesystem']);

return $container;
}
Expand Down
36 changes: 36 additions & 0 deletions src/Traits/FilesystemAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace EC\OpenEuropa\TaskRunner\Traits;

/**
* Trait FilesystemAwareTrait
*
* @package EC\OpenEuropa\TaskRunner\Traits
*/
trait FilesystemAwareTrait
{
/**
* @var \Symfony\Component\Filesystem\Filesystem
*/
protected $filesystem;

/**
* @return \Symfony\Component\Filesystem\Filesystem
*/
public function getFilesystem()
{
return $this->filesystem;
}

/**
* @param \Symfony\Component\Filesystem\Filesystem $filesystem
*
* @return FilesystemAwareTrait
*/
public function setFilesystem($filesystem)
{
$this->filesystem = $filesystem;

return $this;
}
}
29 changes: 0 additions & 29 deletions src/Traits/PathUtilitiesTrait.php

This file was deleted.

32 changes: 16 additions & 16 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"type": "drupal-module"
}
contains:
- "symlink('../../..', 'build/modules/custom/bar')"
- "symlink('../../../', 'build/modules/custom/bar')"
- "[Simulator] Running ./vendor/bin/run 'setup:behat'"
- "[Simulator] Running ./vendor/bin/run 'setup:phpunit'"
- "AppendConfiguration('build/sites/default/default.settings.php'"
Expand All @@ -141,7 +141,7 @@
"type": "drupal-theme"
}
contains:
- "symlink('../../..', 'web/themes/custom/bar')"
- "symlink('../../../', 'web/themes/custom/bar')"
- "WriteConfiguration('web/sites/default/drushrc.php'"
- "File\\Write('web/sites/default/drush.yml')"

Expand All @@ -155,7 +155,7 @@
"type": "drupal-module"
}
contains:
- "symlink('../../../../..', 'build/sites/all/modules/custom/bar')"
- "symlink('../../../../../', 'build/sites/all/modules/custom/bar')"

- command: 'drupal:component-scaffold'
configuration:
Expand All @@ -167,16 +167,16 @@
"type": "drupal-theme"
}
contains:
- "symlink('../../../../..', 'build/sites/all/themes/custom/bar')"
- "symlink('../../../../../', 'build/sites/all/themes/custom/bar')"

- command: 'drupal:site-setup'
configuration: []
composer: ''
contains:
- "symlink('../../custom/modules', 'build/modules/custom')"
- "symlink('../../custom/themes', 'build/themes/custom')"
- "symlink('../../custom/profiles', 'build/profiles/custom')"
- "symlink('../../custom/libraries', 'build/libraries/custom')"
- "symlink('../../custom/modules/', 'build/modules/custom')"
- "symlink('../../custom/themes/', 'build/themes/custom')"
- "symlink('../../custom/profiles/', 'build/profiles/custom')"
- "symlink('../../custom/libraries/', 'build/libraries/custom')"
- "AppendConfiguration('build/sites/default/default.settings.php'"
- "WriteConfiguration('build/sites/default/drushrc.php'"
- "File\\Write('build/sites/default/drush.yml')"
Expand All @@ -187,10 +187,10 @@
root: 'overridden'
composer: ''
contains:
- "symlink('../../custom/modules', 'overridden/modules/custom')"
- "symlink('../../custom/themes', 'overridden/themes/custom')"
- "symlink('../../custom/profiles', 'overridden/profiles/custom')"
- "symlink('../../custom/libraries', 'overridden/libraries/custom')"
- "symlink('../../custom/modules/', 'overridden/modules/custom')"
- "symlink('../../custom/themes/', 'overridden/themes/custom')"
- "symlink('../../custom/profiles/', 'overridden/profiles/custom')"
- "symlink('../../custom/libraries/', 'overridden/libraries/custom')"
- "AppendConfiguration('overridden/sites/default/default.settings.php'"
- "WriteConfiguration('overridden/sites/default/drushrc.php'"
- "File\\Write('overridden/sites/default/drush.yml')"
Expand All @@ -199,10 +199,10 @@
configuration: []
composer: ''
contains:
- "symlink('../../custom/modules', 'web/modules/custom')"
- "symlink('../../custom/themes', 'web/themes/custom')"
- "symlink('../../custom/profiles', 'web/profiles/custom')"
- "symlink('../../custom/libraries', 'web/libraries/custom')"
- "symlink('../../custom/modules/', 'web/modules/custom')"
- "symlink('../../custom/themes/', 'web/themes/custom')"
- "symlink('../../custom/profiles/', 'web/profiles/custom')"
- "symlink('../../custom/libraries/', 'web/libraries/custom')"
- "[Simulator] Running ./vendor/bin/run 'setup:behat'"
- "[Simulator] Running ./vendor/bin/run 'setup:phpunit'"
- "AppendConfiguration('build/sites/default/default.settings.php'"
Expand Down

0 comments on commit de3afce

Please sign in to comment.