diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index bdcabcd80..01148583a 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -467,11 +467,7 @@ class InstallationManager { $package = $operation->getPackage(); $installer = $this->getInstaller($package->getType()); - if ($installer instanceof PluginInstaller) { - $promise = $installer->install($repo, $package, $this); - } else { - $promise = $installer->install($repo, $package); - } + $promise = $installer->install($repo, $package); $this->markForNotification($package); return $promise; @@ -493,11 +489,7 @@ class InstallationManager if ($initialType === $targetType) { $installer = $this->getInstaller($initialType); - if ($installer instanceof PluginInstaller) { - $promise = $installer->update($repo, $initial, $target, $this); - } else { - $promise = $installer->update($repo, $initial, $target); - } + $promise = $installer->update($repo, $initial, $target); $this->markForNotification($target); } else { $promise = $this->getInstaller($initialType)->uninstall($repo, $initial); @@ -505,12 +497,8 @@ class InstallationManager $promise = \React\Promise\resolve(); } - $installManager = $this; $installer = $this->getInstaller($targetType); - $promise->then(function () use ($installer, $repo, $target, $installManager) { - if ($installer instanceof PluginInstaller) { - return $installer->install($repo, $target, $installManager); - } + $promise->then(function () use ($installer, $repo, $target) { return $installer->install($repo, $target); }); } diff --git a/src/Composer/Installer/PluginInstaller.php b/src/Composer/Installer/PluginInstaller.php index d13364cef..5c63a6d1f 100644 --- a/src/Composer/Installer/PluginInstaller.php +++ b/src/Composer/Installer/PluginInstaller.php @@ -63,7 +63,7 @@ class PluginInstaller extends LibraryInstaller /** * {@inheritDoc} */ - public function install(InstalledRepositoryInterface $repo, PackageInterface $package, InstallationManager $installationManager = null) + public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { $promise = parent::install($repo, $package); if (!$promise instanceof PromiseInterface) { @@ -73,11 +73,8 @@ class PluginInstaller extends LibraryInstaller $pluginManager = $this->composer->getPluginManager(); $self = $this; - return $promise->then(function () use ($self, $pluginManager, $package, $repo, $installationManager) { + return $promise->then(function () use ($self, $pluginManager, $package, $repo) { try { - if ($installationManager) { - $self->updateInstalledVersions($repo, $installationManager); - } $pluginManager->registerPackage($package, true); } catch (\Exception $e) { $self->rollbackInstall($e, $repo, $package); @@ -88,7 +85,7 @@ class PluginInstaller extends LibraryInstaller /** * {@inheritDoc} */ - public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target, InstallationManager $installationManager = null) + public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { $promise = parent::update($repo, $initial, $target); if (!$promise instanceof PromiseInterface) { @@ -98,12 +95,9 @@ class PluginInstaller extends LibraryInstaller $pluginManager = $this->composer->getPluginManager(); $self = $this; - return $promise->then(function () use ($self, $pluginManager, $initial, $target, $repo, $installationManager) { + return $promise->then(function () use ($self, $pluginManager, $initial, $target, $repo) { try { $pluginManager->deactivatePackage($initial, true); - if ($installationManager) { - $self->updateInstalledVersions($repo, $installationManager); - } $pluginManager->registerPackage($target, true); } catch (\Exception $e) { $self->rollbackInstall($e, $repo, $target); @@ -128,16 +122,4 @@ class PluginInstaller extends LibraryInstaller parent::uninstall($repo, $package); throw $e; } - - /** - * TODO v3 should make this private once we can drop PHP 5.3 support - * @private - */ - public function updateInstalledVersions(InstalledRepositoryInterface $repo, InstallationManager $installationManager) - { - $versions = $repo->generateInstalledVersions($installationManager); - if ($versions) { - \Composer\InstalledVersions::reload($versions); - } - } } diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index 5c5eb33da..55d3feb5d 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -141,9 +141,8 @@ class FilesystemRepository extends WritableArrayRepository /** * @return ?array - * @internal */ - public function generateInstalledVersions(InstallationManager $installationManager) + private function generateInstalledVersions(InstallationManager $installationManager) { if (!$this->dumpVersions) { return null; diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions.test b/tests/Composer/Test/Fixtures/functional/installed-versions.test index 5eb166246..003401d09 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions.test +++ b/tests/Composer/Test/Fixtures/functional/installed-versions.test @@ -1,8 +1,8 @@ --TEST-- Checks that package versions in InstalledVersions are correct on initial install. Noteworthy things: - - PluginA is already found at the moment where it is first initialized - - PluginB is already found at the moment where it is first initialized + - PluginA is not yet found at the moment where it is first initialized. This is a quirk which we are unlikely to fix + - PluginB is not yet found at the moment where it is first initialized, but it finds PluginA which was installed before - Local dependencies (symfony/*) show the local version over the Composer-bundled version once they are installed locally --RUN-- update @@ -26,12 +26,14 @@ Package operations: 6 installs, 0 updates, 0 removals - Downloading symfony/filesystem (%v?[2-8]\.\d+\.\d+%) - Installing symfony/console (99999.1.2): Symlinking from symfony-console - Installing plugin/a (1.1.1): Symlinking from plugin-a -!!PluginA:1.1.1.0["root/pkg","symfony/console","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/filesystem","symfony/finder","symfony/polyfill-ctype","symfony/polyfill-mbstring","symfony/process","plugin/a"] +!!PluginAInit["root/pkg","symfony/console","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/filesystem","symfony/finder","symfony/polyfill-ctype","symfony/polyfill-mbstring","symfony/process"] +!!PluginA:null !!PluginB:null !!Versions:console:99999.1.2.0;process:%[2-8]\.\d+\.\d+.0%;filesystem:%[2-8]\.\d+\.\d+.0% - Installing plugin/b (2.2.2): Symlinking from plugin-b -!!PluginB:2.2.2.0["plugin/a","root/pkg","symfony/console","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/filesystem","symfony/finder","symfony/polyfill-ctype","symfony/polyfill-mbstring","symfony/process","plugin/b"] +!!PluginBInit["plugin/a","root/pkg","symfony/console","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/filesystem","symfony/finder","symfony/polyfill-ctype","symfony/polyfill-mbstring","symfony/process"] !!PluginA:1.1.1.0 +!!PluginB:null !!Versions:console:99999.1.2.0;process:%[2-8]\.\d+\.\d+.0%;filesystem:%[2-8]\.\d+\.\d+.0% - Installing symfony/polyfill-ctype (%v?[1-8]\.\d+\.\d+%): Extracting archive - Installing symfony/filesystem (%v?[2-8]\.\d+\.\d+%): Extracting archive diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-a/PluginA.php b/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-a/PluginA.php index 60ec2acac..224012c6f 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-a/PluginA.php +++ b/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-a/PluginA.php @@ -10,7 +10,8 @@ class PluginA implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { - echo '!!PluginA:'.InstalledVersions::getVersion('plugin/a').JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginAInit'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginA:'.(InstalledVersions::isInstalled('plugin/a') ? InstalledVersions::getVersion('plugin/a') : 'null')."\n"; echo '!!PluginB:'.(InstalledVersions::isInstalled('plugin/b') ? InstalledVersions::getVersion('plugin/b') : 'null')."\n"; echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; } diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-b/PluginB.php b/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-b/PluginB.php index 07c2206d6..1315f52c5 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-b/PluginB.php +++ b/tests/Composer/Test/Fixtures/functional/installed-versions/plugin-b/PluginB.php @@ -10,8 +10,9 @@ class PluginB implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { - echo '!!PluginB:'.InstalledVersions::getVersion('plugin/b').JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginBInit'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; echo '!!PluginA:'.(InstalledVersions::isInstalled('plugin/a') ? InstalledVersions::getVersion('plugin/a') : 'null')."\n"; + echo '!!PluginB:'.(InstalledVersions::isInstalled('plugin/b') ? InstalledVersions::getVersion('plugin/b') : 'null')."\n"; echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; } diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions2.test b/tests/Composer/Test/Fixtures/functional/installed-versions2.test index ed143c881..d1553a36c 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions2.test +++ b/tests/Composer/Test/Fixtures/functional/installed-versions2.test @@ -2,19 +2,20 @@ Checks that package versions in InstalledVersions are correct during an upgrade. Noteworthy things: - PluginA sees the old version of PluginB until that upgrade happened - - PluginA/PluginB see an old version of themselves as the plugin is marked install InstalledVersions::reload() but that is used as fallback vs what is in vendor dir. This is a quirk which we are unlikely to fix + - PluginA/PluginB see an old version of themselves. This is a quirk which we are unlikely to fix - Local dependencies (symfony/*) always show the local version over the Composer-bundled version, and show the correct new version as soon as they are done upgrading --RUN-- -update +update plugin/* symfony/console symfony/filesystem symfony/process --EXPECT-- !!PluginA:1.1.1.0["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] !!PluginB:2.2.2.0 !!Versions:console:99999.1.2.0;process:12345.1.2.0;filesystem:2.8.2.0 !!PluginB:2.2.2.0["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] !!PluginA:1.1.1.0 -!!Versions:console:99999.1.2.0;process:12345.1.2.0;filesystem:2.8.2.0%(\n> Hooks::preUpdate)?% +!!Versions:console:99999.1.2.0;process:12345.1.2.0;filesystem:2.8.2.0 +> Hooks::preUpdate !!PreUpdate:["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] -!!Versions:console:99999.1.2.0;process:12345.1.2.0;filesystem:2.8.2.0%(\n> Hooks::preUpdate)?% +!!Versions:console:99999.1.2.0;process:12345.1.2.0;filesystem:2.8.2.0 Loading composer repositories with package information Updating dependencies Lock file operations: 0 installs, 5 updates, 0 removals @@ -26,16 +27,19 @@ Lock file operations: 0 installs, 5 updates, 0 removals Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 0 installs, 5 updates, 0 removals + - Downloading symfony/filesystem (%v?[2-8]\.\d+\.\d+%) - Upgrading symfony/console (99999.1.2 => 99999.1.3): Mirroring from symfony-console - Upgrading plugin/a (1.1.1 => 1.1.2): Mirroring from plugin-a -!!PluginA:1.1.1.0["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] +!!PluginAInit["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] +!!PluginA:1.1.1.0 !!PluginB:2.2.2.0 !!Versions:console:99999.1.3.0;process:12345.1.2.0;filesystem:%[2-8]\.\d+\.\d+.0% - Upgrading plugin/b (2.2.2 => 2.2.3): Mirroring from plugin-b -!!PluginB:2.2.2.0["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] +!!PluginBInit["plugin/a","plugin/b","root/pkg","symfony/console","symfony/filesystem","symfony/polyfill-ctype","symfony/process","composer/ca-bundle","composer/composer","composer/semver","composer/spdx-licenses","composer/xdebug-handler","justinrainbow/json-schema","psr/log","react/promise","seld/jsonlint","seld/phar-utils","symfony/debug","symfony/finder","symfony/polyfill-mbstring"] !!PluginA:1.1.2.0 +!!PluginB:2.2.2.0 !!Versions:console:99999.1.3.0;process:12345.1.2.0;filesystem:%[2-8]\.\d+\.\d+.0% - - Upgrading symfony/filesystem (v2.8.2 => %v?[2-8]\.\d+\.\d+%) + - Upgrading symfony/filesystem (v2.8.2 => %v?[2-8]\.\d+\.\d+%): Extracting archive - Upgrading symfony/process (12345.1.2 => 12345.1.3): Mirroring from symfony-process Generating autoload files 2 packages you are using are looking for funding. diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions2/Hooks.php b/tests/Composer/Test/Fixtures/functional/installed-versions2/Hooks.php index 4de347101..24264ec54 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions2/Hooks.php +++ b/tests/Composer/Test/Fixtures/functional/installed-versions2/Hooks.php @@ -8,16 +8,15 @@ class Hooks { public static function preUpdate(Event $event) { - flush(); - echo '!!PreUpdate:'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; - echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; + fwrite(STDERR, '!!PreUpdate:'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"); + fwrite(STDERR, '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"); } public static function postUpdate(Event $event) { - echo '!!PostUpdate:'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; - echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; - echo '!!PluginA:'.InstalledVersions::getVersion('plugin/a')."\n"; - echo '!!PluginB:'.InstalledVersions::getVersion('plugin/b')."\n"; + fwrite(STDERR, '!!PostUpdate:'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"); + fwrite(STDERR, '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"); + fwrite(STDERR, '!!PluginA:'.InstalledVersions::getVersion('plugin/a')."\n"); + fwrite(STDERR, '!!PluginB:'.InstalledVersions::getVersion('plugin/b')."\n"); } } diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-a/PluginA.php b/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-a/PluginA.php index 60ec2acac..224012c6f 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-a/PluginA.php +++ b/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-a/PluginA.php @@ -10,7 +10,8 @@ class PluginA implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { - echo '!!PluginA:'.InstalledVersions::getVersion('plugin/a').JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginAInit'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginA:'.(InstalledVersions::isInstalled('plugin/a') ? InstalledVersions::getVersion('plugin/a') : 'null')."\n"; echo '!!PluginB:'.(InstalledVersions::isInstalled('plugin/b') ? InstalledVersions::getVersion('plugin/b') : 'null')."\n"; echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; } diff --git a/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-b/PluginB.php b/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-b/PluginB.php index 07c2206d6..1315f52c5 100644 --- a/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-b/PluginB.php +++ b/tests/Composer/Test/Fixtures/functional/installed-versions2/plugin-b/PluginB.php @@ -10,8 +10,9 @@ class PluginB implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { - echo '!!PluginB:'.InstalledVersions::getVersion('plugin/b').JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; + echo '!!PluginBInit'.JsonFile::encode(InstalledVersions::getInstalledPackages(), 320)."\n"; echo '!!PluginA:'.(InstalledVersions::isInstalled('plugin/a') ? InstalledVersions::getVersion('plugin/a') : 'null')."\n"; + echo '!!PluginB:'.(InstalledVersions::isInstalled('plugin/b') ? InstalledVersions::getVersion('plugin/b') : 'null')."\n"; echo '!!Versions:console:'.InstalledVersions::getVersion('symfony/console').';process:'.InstalledVersions::getVersion('symfony/process').';filesystem:'.InstalledVersions::getVersion('symfony/filesystem')."\n"; }