Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoid loading plugins that do not match the current plugin api even d…
…uring installation
  • Loading branch information
Seldaek committed Jan 17, 2016
1 parent 8375af2 commit 21f5933
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/Composer/Plugin/PluginManager.php
Expand Up @@ -106,6 +106,26 @@ public function registerPackage(PackageInterface $package, $failOnMissingClasses
return;
}

$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('<warning>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.</warning>');
return;
}

$oldInstallerPlugin = ($package->getType() === 'composer-installer');

if (in_array($package->getName(), $this->registeredPlugins)) {
Expand Down Expand Up @@ -209,28 +229,7 @@ private function loadRepository(RepositoryInterface $repo)
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('<warning>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.</warning>');
continue;
}

$this->registerPackage($package);

// Backward compatibility
} elseif ('composer-installer' === $package->getType()) {
$this->registerPackage($package);
Expand Down

0 comments on commit 21f5933

Please sign in to comment.