1
0
Fork 0

Add a composer-plugin-api platform package and plugins must require it

pull/2179/head
Nils Adermann 2013-09-05 15:47:05 +02:00
parent 6c2e998e40
commit 92b1ee2f7a
3 changed files with 38 additions and 0 deletions

View File

@ -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
*

View File

@ -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("<warning>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.</warning>");
}
$this->registerPackage($package);
}
// Backward compatability
if ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
}
}

View File

@ -14,6 +14,7 @@ namespace Composer\Repository;
use Composer\Package\CompletePackage;
use Composer\Package\Version\VersionParser;
use Composer\Plugin\PluginInterface;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -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);