Add a composer-plugin-api platform package and plugins must require it
parent
6c2e998e40
commit
92b1ee2f7a
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue