1
0
Fork 0

Make sure global plugins are described as such in loading output, fixes composer/package-versions-deprecated#15

pull/9374/head
Jordi Boggiano 2020-10-27 09:36:59 +01:00
parent 5d4bcde454
commit d699e6b36c
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 12 additions and 11 deletions

View File

@ -82,10 +82,10 @@ class PluginManager
$repo = $this->composer->getRepositoryManager()->getLocalRepository(); $repo = $this->composer->getRepositoryManager()->getLocalRepository();
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
if ($repo) { if ($repo) {
$this->loadRepository($repo); $this->loadRepository($repo, false);
} }
if ($globalRepo) { if ($globalRepo) {
$this->loadRepository($globalRepo); $this->loadRepository($globalRepo, true);
} }
} }
@ -117,10 +117,11 @@ class PluginManager
* *
* @param PackageInterface $package * @param PackageInterface $package
* @param bool $failOnMissingClasses By default this silently skips plugins that can not be found, but if set to true it fails with an exception * @param bool $failOnMissingClasses By default this silently skips plugins that can not be found, but if set to true it fails with an exception
* @param bool $isGlobalPlugin Set to true to denote plugins which are installed in the global Composer directory
* *
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
*/ */
public function registerPackage(PackageInterface $package, $failOnMissingClasses = false) public function registerPackage(PackageInterface $package, $failOnMissingClasses = false, $isGlobalPlugin = false)
{ {
if ($this->disablePlugins) { if ($this->disablePlugins) {
return; return;
@ -145,13 +146,13 @@ class PluginManager
if ($requiresComposer->getPrettyString() === $this->getPluginApiVersion()) { if ($requiresComposer->getPrettyString() === $this->getPluginApiVersion()) {
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin requires composer-plugin-api '.$this->getPluginApiVersion().', this *WILL* break in the future and it should be fixed ASAP (require ^'.$this->getPluginApiVersion().' instead for example).</warning>'); $this->io->writeError('<warning>The "' . $package->getName() . '" plugin requires composer-plugin-api '.$this->getPluginApiVersion().', this *WILL* break in the future and it should be fixed ASAP (require ^'.$this->getPluginApiVersion().' instead for example).</warning>');
} elseif (!$requiresComposer->matches($currentPluginApiConstraint)) { } elseif (!$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>'); $this->io->writeError('<warning>The "' . $package->getName() . '" plugin '.($isGlobalPlugin ? '(installed globally) ' : '').'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; return;
} }
if ($package->getName() === 'symfony/flex' && preg_match('{^[0-9.]+$}', $package->getVersion()) && version_compare($package->getVersion(), '1.9.8', '<')) { if ($package->getName() === 'symfony/flex' && preg_match('{^[0-9.]+$}', $package->getVersion()) && version_compare($package->getVersion(), '1.9.8', '<')) {
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it is not compatible with Composer 2+. Make sure to update it to version 1.9.8 or greater.</warning>'); $this->io->writeError('<warning>The "' . $package->getName() . '" plugin '.($isGlobalPlugin ? '(installed globally) ' : '').'was skipped because it is not compatible with Composer 2+. Make sure to update it to version 1.9.8 or greater.</warning>');
return; return;
} }
@ -219,7 +220,7 @@ class PluginManager
$this->registeredPlugins[$package->getName()] = $installer; $this->registeredPlugins[$package->getName()] = $installer;
} elseif (class_exists($class)) { } elseif (class_exists($class)) {
$plugin = new $class(); $plugin = new $class();
$this->addPlugin($plugin); $this->addPlugin($plugin, $isGlobalPlugin);
$this->registeredPlugins[$package->getName()] = $plugin; $this->registeredPlugins[$package->getName()] = $plugin;
} elseif ($failOnMissingClasses) { } elseif ($failOnMissingClasses) {
throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class); throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
@ -311,9 +312,9 @@ class PluginManager
* *
* @param PluginInterface $plugin plugin instance * @param PluginInterface $plugin plugin instance
*/ */
public function addPlugin(PluginInterface $plugin) public function addPlugin(PluginInterface $plugin, $isGlobalPlugin = false)
{ {
$this->io->writeError('Loading plugin '.get_class($plugin), true, IOInterface::DEBUG); $this->io->writeError('Loading plugin '.get_class($plugin).($isGlobalPlugin ? ' (installed globally)' : ''), true, IOInterface::DEBUG);
$this->plugins[] = $plugin; $this->plugins[] = $plugin;
$plugin->activate($this->composer, $this->io); $plugin->activate($this->composer, $this->io);
@ -373,7 +374,7 @@ class PluginManager
* *
* @throws \RuntimeException * @throws \RuntimeException
*/ */
private function loadRepository(RepositoryInterface $repo) private function loadRepository(RepositoryInterface $repo, $isGlobalRepo)
{ {
$packages = $repo->getPackages(); $packages = $repo->getPackages();
$sortedPackages = PackageSorter::sortPackages($packages); $sortedPackages = PackageSorter::sortPackages($packages);
@ -382,10 +383,10 @@ class PluginManager
continue; continue;
} }
if ('composer-plugin' === $package->getType()) { if ('composer-plugin' === $package->getType()) {
$this->registerPackage($package); $this->registerPackage($package, false, $isGlobalRepo);
// Backward compatibility // Backward compatibility
} elseif ('composer-installer' === $package->getType()) { } elseif ('composer-installer' === $package->getType()) {
$this->registerPackage($package); $this->registerPackage($package, false, $isGlobalRepo);
} }
} }
} }