diff --git a/src/Composer/Plugin/PluginInterface.php b/src/Composer/Plugin/PluginInterface.php index 302175a25..3a33672a6 100644 --- a/src/Composer/Plugin/PluginInterface.php +++ b/src/Composer/Plugin/PluginInterface.php @@ -22,6 +22,13 @@ use Composer\IO\IOInterface; */ interface PluginInterface { + /** + * Version number of the fake composer-plugin-api package + * + * @var string + */ + const PLUGIN_API_VERSION = '1.0.0'; + /** * Apply plugin modifications to composer * diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index c67ea9622..dacf9bd57 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -16,9 +16,11 @@ use Composer\Composer; use Composer\EventDispatcher\EventSubscriberInterface; use Composer\IO\IOInterface; use Composer\Package\Package; +use Composer\Package\Version\VersionParser; use Composer\Repository\RepositoryInterface; use Composer\Package\PackageInterface; use Composer\Package\Link; +use Composer\Package\LinkConstraint\VersionConstraint; use Composer\DependencyResolver\Pool; /** @@ -31,6 +33,7 @@ class PluginManager protected $composer; protected $io; protected $globalRepository; + protected $versionParser; protected $plugins = array(); @@ -46,6 +49,7 @@ class PluginManager $this->composer = $composer; $this->io = $io; $this->globalRepository = $globalRepository; + $this->versionParser = new VersionParser(); } /** @@ -92,6 +96,25 @@ class PluginManager { foreach ($repo->getPackages() as $package) { if ('composer-plugin' === $package->getType() || 'composer-installer' === $package->getType()) { + $requiresComposer = null; + foreach ($package->getRequires() as $link) { + if ($link->getTarget() == 'composer-plugin-api') { + $requiresComposer = $link->getConstraint(); + } + } + + if (!$requiresComposer) { + throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package."); + } + + if (!$requiresComposer->matches(new VersionConstraint('==', $this->versionParser->normalize(PluginInterface::PLUGIN_API_VERSION)))) { + $this->io->write("The plugin ".$package->getName()." requires a version of composer-plugin-api that does not match your composer installation. You may need to run composer update with the '--no-plugins' option."); + } + + $this->registerPackage($package); + } + // Backward compatability + if ('composer-installer' === $package->getType()) { $this->registerPackage($package); } } diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 3f208aae0..7c4b72673 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -14,6 +14,7 @@ namespace Composer\Repository; use Composer\Package\CompletePackage; use Composer\Package\Version\VersionParser; +use Composer\Plugin\PluginInterface; /** * @author Jordi Boggiano @@ -28,6 +29,12 @@ class PlatformRepository extends ArrayRepository $versionParser = new VersionParser(); + $prettyVersion = PluginInterface::PLUGIN_API_VERSION; + $version = $versionParser->normalize($prettyVersion); + $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion); + $composerPluginApi->setDescription('The Composer Plugin API'); + parent::addPackage($composerPluginApi); + try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); @@ -36,6 +43,7 @@ class PlatformRepository extends ArrayRepository $version = $versionParser->normalize($prettyVersion); } + $php = new CompletePackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php);