From 01a08a2ff30ed8c3096ec320420bf92a040c7562 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 13 Aug 2013 13:25:21 +0200 Subject: [PATCH] As preparation for composer plugins, rename custom installers to plugins --- doc/04-schema.md | 2 +- res/composer-schema.json | 4 ++-- src/Composer/Command/CreateProjectCommand.php | 18 +++++++++--------- src/Composer/Command/InstallCommand.php | 6 +++--- src/Composer/Command/UpdateCommand.php | 6 +++--- src/Composer/Factory.php | 2 +- src/Composer/Installer.php | 14 +++++++------- src/Composer/Installer/InstallationManager.php | 8 ++++---- ...tallerInstaller.php => PluginInstaller.php} | 11 +++++++---- ...t.test => plugins-are-installed-first.test} | 4 ++-- .../Fixtures/installer-v1/composer.json | 2 +- .../Fixtures/installer-v2/composer.json | 2 +- .../Fixtures/installer-v3/composer.json | 2 +- .../Fixtures/installer-v4/composer.json | 2 +- ...stallerTest.php => PluginInstallerTest.php} | 14 +++++++------- 15 files changed, 50 insertions(+), 47 deletions(-) rename src/Composer/Installer/{InstallerInstaller.php => PluginInstaller.php} (86%) rename tests/Composer/Test/Fixtures/installer/{custom-installers-are-installed-first.test => plugins-are-installed-first.test} (90%) rename tests/Composer/Test/Installer/{InstallerInstallerTest.php => PluginInstallerTest.php} (92%) diff --git a/doc/04-schema.md b/doc/04-schema.md index 7b8ef5558..7d2775af1 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -99,7 +99,7 @@ Out of the box, composer supports three types: their installation, but contains no files and will not write anything to the filesystem. As such, it does not require a dist or source key to be installable. -- **composer-installer:** A package of type `composer-installer` provides an +- **composer-plugin:** A package of type `composer-plugin` may provide an installer for other packages that have a custom type. Read more in the [dedicated article](articles/custom-installers.md). diff --git a/res/composer-schema.json b/res/composer-schema.json index 328794ef8..eef9aa3d6 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -9,7 +9,7 @@ "required": true }, "type": { - "description": "Package type, either 'library' for common packages, 'composer-installer' for custom installers, 'metapackage' for empty packages, or a custom type ([a-z0-9-]+) defined by whatever project this package applies to.", + "description": "Package type, either 'library' for common packages, 'composer-plugin' for plugins, 'metapackage' for empty packages, or a custom type ([a-z0-9-]+) defined by whatever project this package applies to.", "type": "string" }, "target-dir": { @@ -180,7 +180,7 @@ }, "extra": { "type": ["object", "array"], - "description": "Arbitrary extra data that can be used by custom installers, for example, package of type composer-installer must have a 'class' key defining the installer class name.", + "description": "Arbitrary extra data that can be used by plugins, for example, package of type composer-plugin may have a 'class' key defining an installer class name.", "additionalProperties": true }, "autoload": { diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 222add8e5..c38f0bec4 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -62,7 +62,7 @@ class CreateProjectCommand extends Command new InputOption('repository-url', null, InputOption::VALUE_REQUIRED, 'Pick a different repository url to look for the package.'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'), - new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Whether to disable custom installers.'), + new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Whether to disable plugins.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Whether to prevent execution of all defined scripts in the root package.'), new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('keep-vcs', null, InputOption::VALUE_NONE, 'Whether to prevent deletion vcs folder.'), @@ -127,19 +127,19 @@ EOT $preferDist, !$input->getOption('no-dev'), $input->getOption('repository-url'), - $input->getOption('no-custom-installers'), + $input->getOption('no-plugins'), $input->getOption('no-scripts'), $input->getOption('keep-vcs'), $input->getOption('no-progress') ); } - public function installProject(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false, $noProgress = false) + public function installProject(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false) { $oldCwd = getcwd(); if ($packageName !== null) { - $installedFromVcs = $this->installRootPackage($io, $config, $packageName, $directory, $packageVersion, $stability, $preferSource, $preferDist, $installDevPackages, $repositoryUrl, $disableCustomInstallers, $noScripts, $keepVcs, $noProgress); + $installedFromVcs = $this->installRootPackage($io, $config, $packageName, $directory, $packageVersion, $stability, $preferSource, $preferDist, $installDevPackages, $repositoryUrl, $disablePlugins, $noScripts, $keepVcs, $noProgress); } else { $installedFromVcs = false; } @@ -158,8 +158,8 @@ EOT ->setDevMode($installDevPackages) ->setRunScripts( ! $noScripts); - if ($disableCustomInstallers) { - $installer->disableCustomInstallers(); + if ($disablePlugins) { + $installer->disablePlugins(); } if (!$installer->run()) { @@ -226,7 +226,7 @@ EOT return 0; } - protected function installRootPackage(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false, $noProgress = false) + protected function installRootPackage(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false) { $stability = strtolower($stability); if ($stability === 'rc') { @@ -285,8 +285,8 @@ EOT $io->write('Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')'); - if ($disableCustomInstallers) { - $io->write('Custom installers have been disabled.'); + if ($disablePlugins) { + $io->write('Plugins have been disabled.'); } if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) { diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 05d3f37d9..90ad2810f 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -35,7 +35,7 @@ class InstallCommand extends Command new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'), - new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'), + new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), @@ -90,8 +90,8 @@ EOT ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) ; - if ($input->getOption('no-custom-installers')) { - $install->disableCustomInstallers(); + if ($input->getOption('no-plugins')) { + $install->disablePlugins(); } return $install->run() ? 0 : 1; diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index dc103cf99..8d3133b83 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -36,7 +36,7 @@ class UpdateCommand extends Command new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of require-dev packages (enabled by default, only present for BC).'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables installation of require-dev packages.'), new InputOption('lock', null, InputOption::VALUE_NONE, 'Only updates the lock file hash to suppress warning about the lock file being out of date.'), - new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'), + new InputOption('no-plugins', null, InputOption::VALUE_NONE, 'Disables all plugins.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), @@ -96,8 +96,8 @@ EOT ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) ; - if ($input->getOption('no-custom-installers')) { - $install->disableCustomInstallers(); + if ($input->getOption('no-plugins')) { + $install->disablePlugins(); } return $install->run() ? 0 : 1; diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 82c5084c2..749e1ad88 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -370,7 +370,7 @@ class Factory { $im->addInstaller(new Installer\LibraryInstaller($io, $composer, null)); $im->addInstaller(new Installer\PearInstaller($io, $composer, 'pear-library')); - $im->addInstaller(new Installer\InstallerInstaller($io, $composer)); + $im->addInstaller(new Installer\PluginInstaller($io, $composer)); $im->addInstaller(new Installer\MetapackageInstaller($io)); } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 8f424cc39..1d3ec9255 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -461,7 +461,7 @@ class Installer $this->io->write('Nothing to install or update'); } - $operations = $this->moveCustomInstallersToFront($operations); + $operations = $this->movePluginsToFront($operations); foreach ($operations as $operation) { // collect suggestions @@ -540,7 +540,7 @@ class Installer /** - * Workaround: if your packages depend on custom installers, we must be sure + * Workaround: if your packages depend on plugins, we must be sure * that those are installed / updated first; else it would lead to packages * being installed multiple times in different folders, when running Composer * twice. @@ -552,7 +552,7 @@ class Installer * @param OperationInterface[] $operations * @return OperationInterface[] reordered operation list */ - private function moveCustomInstallersToFront(array $operations) + private function movePluginsToFront(array $operations) { $installerOps = array(); foreach ($operations as $idx => $op) { @@ -564,7 +564,7 @@ class Installer continue; } - if ($package->getRequires() === array() && $package->getType() === 'composer-installer') { + if ($package->getRequires() === array() && ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer')) { $installerOps[] = $op; unset($operations[$idx]); } @@ -1055,7 +1055,7 @@ class Installer } /** - * Disables custom installers. + * Disables plugins. * * Call this if you want to ensure that third-party code never gets * executed. The default is to automatically install, and execute @@ -1063,9 +1063,9 @@ class Installer * * @return Installer */ - public function disableCustomInstallers() + public function disablePlugins() { - $this->installationManager->disableCustomInstallers(); + $this->installationManager->disablePlugins(); return $this; } diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 406ee1166..b26273847 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -66,16 +66,16 @@ class InstallationManager } /** - * Disables custom installers. + * Disables plugins. * - * We prevent any custom installers from being instantiated by simply + * We prevent any plugins from being instantiated by simply * deactivating the installer for them. This ensure that no third-party * code is ever executed. */ - public function disableCustomInstallers() + public function disablePlugins() { foreach ($this->installers as $i => $installer) { - if (!$installer instanceof InstallerInstaller) { + if (!$installer instanceof PluginInstaller) { continue; } diff --git a/src/Composer/Installer/InstallerInstaller.php b/src/Composer/Installer/PluginInstaller.php similarity index 86% rename from src/Composer/Installer/InstallerInstaller.php rename to src/Composer/Installer/PluginInstaller.php index a833b68d2..9be0a9155 100644 --- a/src/Composer/Installer/InstallerInstaller.php +++ b/src/Composer/Installer/PluginInstaller.php @@ -23,7 +23,7 @@ use Composer\Package\PackageInterface; * * @author Jordi Boggiano */ -class InstallerInstaller extends LibraryInstaller +class PluginInstaller extends LibraryInstaller { private $installationManager; private static $classCounter = 0; @@ -37,7 +37,7 @@ class InstallerInstaller extends LibraryInstaller */ public function __construct(IOInterface $io, Composer $composer, $type = 'library') { - parent::__construct($io, $composer, 'composer-installer'); + parent::__construct($io, $composer, $type); $this->installationManager = $composer->getInstallationManager(); $repo = $composer->getRepositoryManager()->getLocalRepository(); @@ -45,6 +45,9 @@ class InstallerInstaller extends LibraryInstaller if ('composer-installer' === $package->getType()) { $this->registerInstaller($package); } + if ('composer-plugin' === $package->getType()) { + $this->registerInstaller($package); + } } } @@ -55,7 +58,7 @@ class InstallerInstaller extends LibraryInstaller { $extra = $package->getExtra(); if (empty($extra['class'])) { - throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-installer packages should have a class defined in their extra key to be usable.'); + throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); } parent::install($repo, $package); @@ -69,7 +72,7 @@ class InstallerInstaller extends LibraryInstaller { $extra = $target->getExtra(); if (empty($extra['class'])) { - throw new \UnexpectedValueException('Error while installing '.$target->getPrettyName().', composer-installer packages should have a class defined in their extra key to be usable.'); + throw new \UnexpectedValueException('Error while installing '.$target->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.'); } parent::update($repo, $initial, $target); diff --git a/tests/Composer/Test/Fixtures/installer/custom-installers-are-installed-first.test b/tests/Composer/Test/Fixtures/installer/plugins-are-installed-first.test similarity index 90% rename from tests/Composer/Test/Fixtures/installer/custom-installers-are-installed-first.test rename to tests/Composer/Test/Fixtures/installer/plugins-are-installed-first.test index dd9d26d98..c57a36d35 100644 --- a/tests/Composer/Test/Fixtures/installer/custom-installers-are-installed-first.test +++ b/tests/Composer/Test/Fixtures/installer/plugins-are-installed-first.test @@ -8,8 +8,8 @@ Composer installers are installed first if they have no requirements "package": [ { "name": "pkg", "version": "1.0.0" }, { "name": "pkg2", "version": "1.0.0" }, - { "name": "inst", "version": "1.0.0", "type": "composer-installer" }, - { "name": "inst2", "version": "1.0.0", "type": "composer-installer", "require": { "pkg2": "*" } } + { "name": "inst", "version": "1.0.0", "type": "composer-plugin" }, + { "name": "inst2", "version": "1.0.0", "type": "composer-plugin", "require": { "pkg2": "*" } } ] } ], diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v1/composer.json b/tests/Composer/Test/Installer/Fixtures/installer-v1/composer.json index 2230f4c4c..3ec38c60e 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v1/composer.json +++ b/tests/Composer/Test/Installer/Fixtures/installer-v1/composer.json @@ -1,7 +1,7 @@ { "name": "", "version": "1.0.0", - "type": "composer-installer", + "type": "composer-plugin", "autoload": { "psr-0": { "Installer": "" } }, "extra": { "class": "Installer\\Custom" diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v2/composer.json b/tests/Composer/Test/Installer/Fixtures/installer-v2/composer.json index 82daa3d43..974c82b54 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v2/composer.json +++ b/tests/Composer/Test/Installer/Fixtures/installer-v2/composer.json @@ -1,7 +1,7 @@ { "name": "", "version": "2.0.0", - "type": "composer-installer", + "type": "composer-plugin", "autoload": { "psr-0": { "Installer": "" } }, "extra": { "class": "Installer\\Custom2" diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v3/composer.json b/tests/Composer/Test/Installer/Fixtures/installer-v3/composer.json index 84c1d8c00..ef2cc278b 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v3/composer.json +++ b/tests/Composer/Test/Installer/Fixtures/installer-v3/composer.json @@ -1,7 +1,7 @@ { "name": "", "version": "3.0.0", - "type": "composer-installer", + "type": "composer-plugin", "autoload": { "psr-0": { "Installer": "" } }, "extra": { "class": "Installer\\Custom2" diff --git a/tests/Composer/Test/Installer/Fixtures/installer-v4/composer.json b/tests/Composer/Test/Installer/Fixtures/installer-v4/composer.json index f29258bc6..5ff8d7cb6 100644 --- a/tests/Composer/Test/Installer/Fixtures/installer-v4/composer.json +++ b/tests/Composer/Test/Installer/Fixtures/installer-v4/composer.json @@ -1,7 +1,7 @@ { "name": "", "version": "4.0.0", - "type": "composer-installer", + "type": "composer-plugin", "autoload": { "psr-0": { "Installer": "" } }, "extra": { "class": [ diff --git a/tests/Composer/Test/Installer/InstallerInstallerTest.php b/tests/Composer/Test/Installer/PluginInstallerTest.php similarity index 92% rename from tests/Composer/Test/Installer/InstallerInstallerTest.php rename to tests/Composer/Test/Installer/PluginInstallerTest.php index c61182389..217edb999 100644 --- a/tests/Composer/Test/Installer/InstallerInstallerTest.php +++ b/tests/Composer/Test/Installer/PluginInstallerTest.php @@ -14,13 +14,13 @@ namespace Composer\Test\Installer; use Composer\Composer; use Composer\Config; -use Composer\Installer\InstallerInstaller; +use Composer\Installer\PluginInstaller; use Composer\Package\Loader\JsonLoader; use Composer\Package\Loader\ArrayLoader; use Composer\Package\PackageInterface; use Composer\Autoload\AutoloadGenerator; -class InstallerInstallerTest extends \PHPUnit_Framework_TestCase +class PluginInstallerTest extends \PHPUnit_Framework_TestCase { protected $composer; protected $packages; @@ -81,7 +81,7 @@ class InstallerInstallerTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array())); - $installer = new InstallerInstallerMock($this->io, $this->composer); + $installer = new PluginInstallerMock($this->io, $this->composer); $test = $this; $this->im @@ -101,7 +101,7 @@ class InstallerInstallerTest extends \PHPUnit_Framework_TestCase ->method('getPackages') ->will($this->returnValue(array())); - $installer = new InstallerInstallerMock($this->io, $this->composer); + $installer = new PluginInstallerMock($this->io, $this->composer); $test = $this; @@ -134,7 +134,7 @@ class InstallerInstallerTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(2)) ->method('hasPackage') ->will($this->onConsecutiveCalls(true, false)); - $installer = new InstallerInstallerMock($this->io, $this->composer); + $installer = new PluginInstallerMock($this->io, $this->composer); $test = $this; $this->im @@ -157,7 +157,7 @@ class InstallerInstallerTest extends \PHPUnit_Framework_TestCase ->expects($this->exactly(2)) ->method('hasPackage') ->will($this->onConsecutiveCalls(true, false)); - $installer = new InstallerInstallerMock($this->io, $this->composer); + $installer = new PluginInstallerMock($this->io, $this->composer); $test = $this; $this->im @@ -171,7 +171,7 @@ class InstallerInstallerTest extends \PHPUnit_Framework_TestCase } } -class InstallerInstallerMock extends InstallerInstaller +class PluginInstallerMock extends PluginInstaller { public function getInstallPath(PackageInterface $package) {