From 41d8fdfda881cf24af6d9cceff76f4b8b4dc7d2f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 18 Jan 2016 15:08:38 +0000 Subject: [PATCH] Restore "Avoid loading plugins that do not match the current plugin api even during installation" but fixed This reverts commit 0118d69603b02bf1d4bdb4d992350725aa7ca72f. --- src/Composer/Plugin/PluginManager.php | 43 ++++++++++++++------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 230087175..27680907d 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -106,6 +106,28 @@ class PluginManager return; } + if ($package->getType() === 'composer-plugin') { + $requiresComposer = null; + foreach ($package->getRequires() as $link) { /** @var Link $link */ + if ('composer-plugin-api' === $link->getTarget()) { + $requiresComposer = $link->getConstraint(); + break; + } + } + + if (!$requiresComposer) { + throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package."); + } + + $currentPluginApiVersion = $this->getPluginApiVersion(); + $currentPluginApiConstraint = new Constraint('==', $this->versionParser->normalize($currentPluginApiVersion)); + + if (!$requiresComposer->matches($currentPluginApiConstraint)) { + $this->io->writeError('The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.'); + return; + } + } + $oldInstallerPlugin = ($package->getType() === 'composer-installer'); if (in_array($package->getName(), $this->registeredPlugins)) { @@ -209,28 +231,7 @@ class PluginManager continue; } if ('composer-plugin' === $package->getType()) { - $requiresComposer = null; - foreach ($package->getRequires() as $link) { /** @var Link $link */ - if ('composer-plugin-api' === $link->getTarget()) { - $requiresComposer = $link->getConstraint(); - break; - } - } - - if (!$requiresComposer) { - throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package."); - } - - $currentPluginApiVersion = $this->getPluginApiVersion(); - $currentPluginApiConstraint = new Constraint('==', $this->versionParser->normalize($currentPluginApiVersion)); - - if (!$requiresComposer->matches($currentPluginApiConstraint)) { - $this->io->writeError('The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currentPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.'); - continue; - } - $this->registerPackage($package); - // Backward compatibility } elseif ('composer-installer' === $package->getType()) { $this->registerPackage($package);