From cb865644fea7ac3268a7acec7fd177a8dbcdefe2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 09:57:48 -0400 Subject: [PATCH 01/10] Fixes #341 #284: Automating alias installation and template updates. --- composer.json | 10 ++- composer.lock | 8 +- phing/tasks/blt.xml | 2 +- src/Composer/BltPlugin.php | 174 +++++++++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 src/Composer/BltPlugin.php diff --git a/composer.json b/composer.json index d95c9f13a..189fc64a8 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "acquia/blt", "description": "BLT", + "type": "composer-plugin", "license": "GPL-2.0", "require": { "drupal/console": "~1", @@ -11,7 +12,9 @@ "symfony/yaml": "~2.7", "drupal/coder": "~8.2", "symfony/console": "~2", - "symfony/twig-bridge": "~2" + "symfony/twig-bridge": "~2", + "php": ">=5.6", + "composer-plugin-api": "^1.0.0" }, "autoload": { "psr-4": { @@ -19,6 +22,9 @@ "Acquia\\Blt\\Tests\\": "tests/phpunit/src/" } }, + "extra": { + "class": "Acquia\\Blt\\Composer\\BltPlugin" + }, "bin": [ "bin/blt", "bin/blt-console" @@ -29,6 +35,6 @@ "minimum-stability": "beta", "prefer-stable": true, "scripts": { - "install-blt-alias": "./blt.sh install-alias" + "install-blt-alias": "yes | ./blt.sh install-alias" } } diff --git a/composer.lock b/composer.lock index b34bc01b3..c89f63f24 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2423149def7560fd1866a80e77d9eee7", - "content-hash": "dc83ee695cd8276b601fb2ff5867f4fb", + "hash": "3a94d7da4921e599a2ee5da0682b114a", + "content-hash": "775b7572a266f8ee2789b56d25fa35b4", "packages": [ { "name": "alchemy/zippy", @@ -3627,6 +3627,8 @@ }, "prefer-stable": true, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=5.6" + }, "platform-dev": [] } diff --git a/phing/tasks/blt.xml b/phing/tasks/blt.xml index 515a210b1..6c3b62219 100644 --- a/phing/tasks/blt.xml +++ b/phing/tasks/blt.xml @@ -28,7 +28,7 @@ - + Some of your customized files may have been modified. diff --git a/src/Composer/BltPlugin.php b/src/Composer/BltPlugin.php new file mode 100644 index 000000000..4e6ffd5e4 --- /dev/null +++ b/src/Composer/BltPlugin.php @@ -0,0 +1,174 @@ +composer = $composer; + $this->io = $io; + $this->eventDispatcher = $composer->getEventDispatcher(); + $this->executor = new ProcessExecutor($this->io); + } + + /** + * Returns an array of event names this subscriber wants to listen to. + */ + public static function getSubscribedEvents() { + return array( + PackageEvents::POST_PACKAGE_INSTALL => "onPostPackageEvent", + PackageEvents::POST_PACKAGE_UPDATE => "onPostPackageEvent", + ScriptEvents::POST_UPDATE_CMD => 'onPostCmdEvent', + ScriptEvents::POST_INSTALL_CMD => 'onPostCmdEvent', + ); + } + + /** + * Marks blt to be processed after an install or update command. + * + * @param \Composer\Installer\PackageEvent $event + */ + public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){ + $package = $this->getBltPackage($event->getOperation()); + if ($package) { + // By explicitly setting the blt package, the onPostCmdEvent() will + // process the update automatically. + $this->bltPackage = $package; + } + } + + /** + * Post install command event to execute the blt update. + * + * @param \Composer\Script\Event $event + */ + public function onPostCmdEvent(\Composer\Script\Event $event) { + // Only install the scaffolding if acquia/blt was installed, + if (isset($this->bltPackage)) { + $this->executeBltUpdate(); + } + } + + /** + * @param $operation + * @return mixed + */ + protected function getBltPackage($operation) { + if ($operation instanceof InstallOperation) { + $package = $operation->getPackage(); + } + elseif ($operation instanceof UpdateOperation) { + $package = $operation->getTargetPackage(); + } + if (isset($package) && $package instanceof PackageInterface && $package->getName() == 'acquia/blt') { + return $package; + } + return NULL; + } + + protected function executeBltUpdate() { + // @todo cd into project root from getVendorPath? + $this->io->write('Updating BLT templated files'); + $this->executeCommand('blt update'); + $this->io->write('BLT template files were updated'); + $this->io->write('This may have modified your composer.json and require a subsequent `composer update`'); + } + + /** + * Get the path to the 'vendor' directory. + * + * @return string + */ + public function getVendorPath() { + $config = $this->composer->getConfig(); + $filesystem = new Filesystem(); + $filesystem->ensureDirectoryExists($config->get('vendor-dir')); + $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); + return $vendorPath; + } + + /** + * Executes a shell command with escaping. + * + * @param string $cmd + * @return bool + */ + protected function executeCommand($cmd) { + // Shell-escape all arguments except the command. + $args = func_get_args(); + foreach ($args as $index => $arg) { + if ($index !== 0) { + $args[$index] = escapeshellarg($arg); + } + } + // And replace the arguments. + $command = call_user_func_array('sprintf', $args); + $output = ''; + if ($this->io->isVerbose()) { + $this->io->write(' > ' . $command . ''); + $io = $this->io; + $output = function ($type, $buffer) use ($io) { + if ($type == Process::ERR) { + $io->write('' . $buffer . ''); + } + else { + // @todo Figure out how to preserve color! + $io->write($buffer); + } + }; + } + return ($this->executor->execute($command, $output) == 0); + } + +} From 8b347d4b01b3ae30da9fd2f92d50dcc07edb6782 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 11:22:15 -0400 Subject: [PATCH 02/10] Removing blt configure command. Updating docs. --- INSTALL.md | 8 +------- phing/tasks/blt.xml | 45 ++----------------------------------------- phing/tasks/setup.xml | 4 ++-- template/README.md | 4 ++-- 4 files changed, 7 insertions(+), 54 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index d933dbe33..dedd9d968 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -35,10 +35,6 @@ You should be able to use the following tools on the command line of your native * `project.yml` * `docroot/sites/default/settings/local.settings.php` * Add your local DB credentials to `$databases` -1. Replace tokens in new BLT-generated files with your custom values in project.yml: - - blt configure - 1. Follow instructions for [Setting up your \*AMP stack](#set-up-your-amp-stack) 1. Follow instructions for installing Drupal locally. Don't install Drupal locally using your web browser. 1. (optional) Modify project files. Important files that you may want to modify include: @@ -53,10 +49,9 @@ To add BLT to a pre-existing Drupal project, do the following: 1. Ensure that your project directory structure is Acquia-cloud compatible by asserting that the Drupal root is in a top-level folder called `docroot`. 1. If you currently manage your dependencies via Composer, ensure that they are all up to date via `composer update`. Assert that these updates do not break your project. 1. `cd` into your existing project directory. -1. Add BLT via composer and initialize it: +1. Add BLT via composer: composer require acquia/blt:~8 --dev - ./vendor/bin/blt init 1. Follow instructions for [Setting up your \*AMP stack](#set-up-your-42amp-stack) 1. Follow instructions for installing Drupal locally. Don't install Drupal locally using your web browser. @@ -72,7 +67,6 @@ To add BLT to a pre-existing Drupal project, do the following: If you are already using BLT via Composer, you can update to the latest version of BLT by running the following commands from your project's root directory: composer update acquia/blt - blt update Review and commit changes to your project files. For customized files like `.travis.yml` or `docroot/sites/default/settings.php` it is recommended that you use `git add -p` to select which specific line changes you'd like to stage and commit. diff --git a/phing/tasks/blt.xml b/phing/tasks/blt.xml index 6c3b62219..33c5aebcc 100644 --- a/phing/tasks/blt.xml +++ b/phing/tasks/blt.xml @@ -12,10 +12,7 @@ BLT files have been copied to your project directory. Some of your existing files may have been modified. - Please customize ${repo.root}/project.yml and then run: - blt configure - - This will replace placeholders with your custom values in the new files created by BLT. + Please customize ${repo.root}/project.yml. @@ -28,7 +25,7 @@ - + Some of your customized files may have been modified. @@ -59,28 +56,6 @@ project.yml has been modified. - - - Making ${docroot}/sites/default/settings.php writable. - - - Expanding Phing properties in BLT files. - - - - - - - - - - - - - - - - @@ -90,20 +65,4 @@ - - - - - - - - - - - - - diff --git a/phing/tasks/setup.xml b/phing/tasks/setup.xml index bcd8c25a4..09e6f2760 100644 --- a/phing/tasks/setup.xml +++ b/phing/tasks/setup.xml @@ -61,7 +61,7 @@ Making ${docroot}/sites/default/settings.php writable. Ensuring that blt.settings.php is required by settings.php - + Generating local settings files. @@ -121,7 +121,7 @@ + depends="setup:drupal:settings, setup:hash-salt"> Printing drush status. diff --git a/template/README.md b/template/README.md index 8f6959dc2..5cad387a5 100644 --- a/template/README.md +++ b/template/README.md @@ -1,6 +1,6 @@ -# ${project.human_name} +# My Project -Replace this with a brief description of the ${project.human_name} project. +A brief description of My Project. ## BLT From b4c4e7867c572f0abff4b5e5e24b95c55de1ae39 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 11:51:09 -0400 Subject: [PATCH 03/10] Adding blt-alias composer command to template composer.json. --- INSTALL.md | 2 +- scripts/blt/install-alias.sh | 4 ++-- src/Composer/{BltPlugin.php => Plugin.php} | 2 +- template/composer.json | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) rename src/Composer/{BltPlugin.php => Plugin.php} (98%) diff --git a/INSTALL.md b/INSTALL.md index dedd9d968..37362c71d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -29,7 +29,7 @@ You should be able to use the following tools on the command line of your native 1. Install the `blt` alias and follow on-screen instructions: - ./vendor/bin/blt install-alias + composer blt-alias 1. Customize BLT configuration files: * `project.yml` diff --git a/scripts/blt/install-alias.sh b/scripts/blt/install-alias.sh index ddb230570..235b1634c 100755 --- a/scripts/blt/install-alias.sh +++ b/scripts/blt/install-alias.sh @@ -2,10 +2,10 @@ if [ "`basename "/$SHELL"`" = "zsh" ]; then DETECTED_PROFILE="$HOME/.zshrc" -elif [ -f "$HOME/.bashrc" ]; then - DETECTED_PROFILE="$HOME/.bashrc" elif [ -f "$HOME/.bash_profile" ]; then DETECTED_PROFILE="$HOME/.bash_profile" +elif [ -f "$HOME/.bashrc" ]; then + DETECTED_PROFILE="$HOME/.bashrc" elif [ -f "$HOME/.profile" ]; then DETECTED_PROFILE="$HOME/.profile" fi diff --git a/src/Composer/BltPlugin.php b/src/Composer/Plugin.php similarity index 98% rename from src/Composer/BltPlugin.php rename to src/Composer/Plugin.php index 4e6ffd5e4..df7468081 100644 --- a/src/Composer/BltPlugin.php +++ b/src/Composer/Plugin.php @@ -25,7 +25,7 @@ use Composer\Util\RemoteFilesystem; use Symfony\Component\Process\Process; -class BltPlugin implements PluginInterface, EventSubscriberInterface { +class Plugin implements PluginInterface, EventSubscriberInterface { /** * @var Composer $composer diff --git a/template/composer.json b/template/composer.json index f6dd7f33e..594a6900f 100644 --- a/template/composer.json +++ b/template/composer.json @@ -59,6 +59,7 @@ }, "scripts": { "install-phantomjs": "PhantomInstaller\\Installer::installPhantomJS", + "blt-alias": "blt install-alias", "post-install-cmd": [ "PhantomInstaller\\Installer::installPhantomJS" ], From 930c793086ffa498bd1bd4df8884c5ea27623eb8 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 11:51:42 -0400 Subject: [PATCH 04/10] Renaming BltPlugin to Plugin. --- composer.json | 2 +- src/Composer/Plugin.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 189fc64a8..f636b7490 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } }, "extra": { - "class": "Acquia\\Blt\\Composer\\BltPlugin" + "class": "Acquia\\Blt\\Composer\\Plugin" }, "bin": [ "bin/blt", diff --git a/src/Composer/Plugin.php b/src/Composer/Plugin.php index df7468081..438662fef 100644 --- a/src/Composer/Plugin.php +++ b/src/Composer/Plugin.php @@ -94,7 +94,7 @@ public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){ * @param \Composer\Script\Event $event */ public function onPostCmdEvent(\Composer\Script\Event $event) { - // Only install the scaffolding if acquia/blt was installed, + // Only install the template files if acquia/blt was installed. if (isset($this->bltPackage)) { $this->executeBltUpdate(); } From 1c88f0a9738c9e21ffb022f4e947780aec66cc11 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 11:52:03 -0400 Subject: [PATCH 05/10] Making vm:init more verbose. --- phing/tasks/vm.xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/phing/tasks/vm.xml b/phing/tasks/vm.xml index 5ab76676e..cae290a44 100644 --- a/phing/tasks/vm.xml +++ b/phing/tasks/vm.xml @@ -13,16 +13,23 @@ + + Creating a config.yml file for Drupal VM. - Adding geerlingguy/drupal-vm to composer dev dependencies. - + + Creating a Vagrantfile. + + Adding geerlingguy/drupal-vm to composer dev dependencies. + + + Updating project.yml. From 402664bda329ac5b4084cd51f53797313ecc4cd0 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 12:30:00 -0400 Subject: [PATCH 06/10] Adding -y argument to install-alias.sh --- CONTRIBUTING.md | 4 ---- phing/tasks/blt.xml | 11 +++++++++-- scripts/blt/install-alias.sh | 19 +++++++++++++++++-- template/composer.json | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dfba57d28..2c5f842c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,10 +36,6 @@ git commit -m 'Initial commit.' The new `blt-project` directory will have a composer dependency on your local clone of BLT via a `../blt` symlink. You can therefore make changes to files in `blt` and see them immediately reflected in `blt-project/vendor/acquia/blt`. -### Updating BLT - -Given that `vendor/acquia/blt` is symlinked to `../blt`, you won't need to actually rebuild the blt dependency often. However, you may need to trigger a blt event or rebuild autoloader files, in which case you should run the following command: `rm -rf vendor/acquia/blt && composer update acquia/blt`. - ## Development conventions ### Phing targets vs. Symfony commands? diff --git a/phing/tasks/blt.xml b/phing/tasks/blt.xml index 33c5aebcc..e28d380d4 100644 --- a/phing/tasks/blt.xml +++ b/phing/tasks/blt.xml @@ -60,8 +60,15 @@ - - + + + + + + + + + diff --git a/scripts/blt/install-alias.sh b/scripts/blt/install-alias.sh index 235b1634c..2bf95c961 100755 --- a/scripts/blt/install-alias.sh +++ b/scripts/blt/install-alias.sh @@ -23,11 +23,23 @@ if [ ! -z "$DETECTED_PROFILE" ]; then exit fi + while getopts ":y" arg; do + case $arg in + y) + REPLY=y + ;; + esac + done + + echo "" echo "BLT can automatically create a Bash alias to make it easier to run BLT tasks." echo "This alias may be created in .bash_profile or .bashrc depending on your system architecture." echo "" - read -p "Install alias? (y/n)" -n 1 -r - echo "" + + if [ -z $REPLY ]; then + read -p "Install alias? (y/n)" -n 1 -r + echo "" + fi if [[ $REPLY =~ ^[Yy]$ ]]; then DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) @@ -37,12 +49,15 @@ if [ ! -z "$DETECTED_PROFILE" ]; then echo "You may now use the 'blt' command from anywhere within a BLT-generated repository." echo "" echo "Restart your terminal session or run 'source $DETECTED_PROFILE' to use the new command." + exit else echo "Error: Could not modify $DETECTED_PROFILE." + exit 1 fi fi else echo "Could not install blt alias. No profile found. Tried ~/.zshrc, ~/.bashrc, ~/.bash_profile and ~/.profile." + exit 1 fi diff --git a/template/composer.json b/template/composer.json index 594a6900f..8fc984a41 100644 --- a/template/composer.json +++ b/template/composer.json @@ -59,7 +59,7 @@ }, "scripts": { "install-phantomjs": "PhantomInstaller\\Installer::installPhantomJS", - "blt-alias": "blt install-alias", + "blt-alias": "blt install-alias -Dcreate_alias=true", "post-install-cmd": [ "PhantomInstaller\\Installer::installPhantomJS" ], From 09c60f2ef1438a843c876563fe8032c671c2e050 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 12:33:44 -0400 Subject: [PATCH 07/10] Updating composer.lock. --- composer.json | 2 +- composer.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f636b7490..3c496dce3 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,6 @@ "minimum-stability": "beta", "prefer-stable": true, "scripts": { - "install-blt-alias": "yes | ./blt.sh install-alias" + "install-blt-alias": "blt install-alias -Dcreate_alias=true" } } diff --git a/composer.lock b/composer.lock index c89f63f24..de3455e0c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3a94d7da4921e599a2ee5da0682b114a", - "content-hash": "775b7572a266f8ee2789b56d25fa35b4", + "hash": "693d125627cafdc5cf7204dcb98ed5a3", + "content-hash": "d6a08564eea3d27404b9ce2c13bf7d63", "packages": [ { "name": "alchemy/zippy", From ac61fa42a2999a5fb56c65cd6e366e9cea93cf37 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 12:50:56 -0400 Subject: [PATCH 08/10] Fixing Drupal VM issue. --- phing/phingcludes/RandomStringTask.php | 0 phing/tasks/vm.xml | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 phing/phingcludes/RandomStringTask.php diff --git a/phing/phingcludes/RandomStringTask.php b/phing/phingcludes/RandomStringTask.php new file mode 100644 index 000000000..e69de29bb diff --git a/phing/tasks/vm.xml b/phing/tasks/vm.xml index cae290a44..951e6b5dd 100644 --- a/phing/tasks/vm.xml +++ b/phing/tasks/vm.xml @@ -4,7 +4,7 @@ BLT support for Drupal VM is EXPERIMENTAL. Not all BLT features currently work with Drupal VM. Creating a drush alias for the new VM. - + @@ -43,12 +43,21 @@ To run drush commands against the VM, use the @${drush.aliases.local} alias. You may pin yourself to this alias using "drush use @${drush.aliases.local}" - + - + - The vagrant-hostsupdater plugin is not installed! + The vagrant is not installed! + + + + + + The vagrant-hostsupdater plugin is not installed! + + + From 7756c09b540bda0c976c3efa0d6306bf3b2de8a5 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Fri, 9 Sep 2016 13:48:42 -0400 Subject: [PATCH 09/10] Preventing drush alias files from being overwritten on update. --- phing/tasks/blt.xml | 5 ++--- scripts/blt/rsync-include-if-does-not-exist.txt | 5 ++++- scripts/drupal-vm/drupal-vm.aliases.drushrc.php | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phing/tasks/blt.xml b/phing/tasks/blt.xml index e28d380d4..a0a67c0a9 100644 --- a/phing/tasks/blt.xml +++ b/phing/tasks/blt.xml @@ -18,11 +18,10 @@ Copying files from BLT's template into your project. - + - - + diff --git a/scripts/blt/rsync-include-if-does-not-exist.txt b/scripts/blt/rsync-include-if-does-not-exist.txt index 75d221a1a..08dad5955 100644 --- a/scripts/blt/rsync-include-if-does-not-exist.txt +++ b/scripts/blt/rsync-include-if-does-not-exist.txt @@ -1,3 +1,6 @@ -# These files will be included if they do not yet exist. They will not overwrite +# These files from template dir will be included if they do not yet exist. They will not overwrite # existing files. project.yml +composer.json +README.md +drush/site-aliases/aliases.drushrc.php diff --git a/scripts/drupal-vm/drupal-vm.aliases.drushrc.php b/scripts/drupal-vm/drupal-vm.aliases.drushrc.php index 1babc3e3d..22e148c83 100644 --- a/scripts/drupal-vm/drupal-vm.aliases.drushrc.php +++ b/scripts/drupal-vm/drupal-vm.aliases.drushrc.php @@ -1,5 +1,3 @@ - Date: Fri, 9 Sep 2016 14:05:18 -0400 Subject: [PATCH 10/10] Removing invalid call to blt configure. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bbabe5a9b..e1dbe4484 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,7 +77,6 @@ script: - yes | blt init # The local.hostname must be set to 127.0.0.1:8888 because we are using drush runserver to run the site on Travis CI. - drupal yaml:update:value project.yml project.local.hostname '127.0.0.1:8888' - - blt configure # Running `blt init` modified composer.json, so we must update. - composer update # Call targets in the new 'blt-project' project.