From ac055e5718508ac95ce1c9bc172efcab6f266e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 21 Jul 2020 23:25:05 +0200 Subject: [PATCH 1/8] Fix: Reference --- src/Composer/Installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index c7af69427..21e211285 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -1679,7 +1679,7 @@ class Installer * restrict the update operation to a few packages, all other packages * that are already installed will be kept at their current version * - * @deprecated use setAllowList instead + * @deprecated use setUpdateAllowList instead * * @param array $packages * @return Installer From e5c7835d575e35349fc25dc2e201cee10f05ad12 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sun, 26 Jul 2020 15:22:59 -0400 Subject: [PATCH 2/8] Properly support PHP 8.0 Named Arguments See https://wiki.php.net/rfc/named_params#internal_functions (implemented but not yet merged) An ArgumentCountError will be thrown when passing variadic arguments to a function with call_user_func_array() if extra unknown named arguments are encountered. Fatal error: Uncaught ArgumentCountError: array_merge() does not accept unknown named parameters in phar:///path/to/composer.phar/src/Composer/DependencyResolver/DefaultPolicy.php:84 (e.g. for `['phpunit/phpunit' => [72]]`) --- src/Composer/DependencyResolver/DefaultPolicy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/DependencyResolver/DefaultPolicy.php b/src/Composer/DependencyResolver/DefaultPolicy.php index 542c6e625..d7d386801 100644 --- a/src/Composer/DependencyResolver/DefaultPolicy.php +++ b/src/Composer/DependencyResolver/DefaultPolicy.php @@ -81,7 +81,7 @@ class DefaultPolicy implements PolicyInterface $literals = $this->pruneRemoteAliases($pool, $literals); } - $selected = call_user_func_array('array_merge', $packages); + $selected = call_user_func_array('array_merge', array_values($packages)); // now sort the result across all packages to respect replaces across packages usort($selected, function ($a, $b) use ($policy, $pool, $installedMap, $requiredPackage) { From b25296ef744a4c9ea8db50bfcd762d18362fa51d Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 27 Jul 2020 13:26:57 +0100 Subject: [PATCH 3/8] Driver: only cache composer.json file without API data to disk --- src/Composer/Repository/Vcs/BitbucketDriver.php | 14 +++++++------- src/Composer/Repository/Vcs/GitHubDriver.php | 14 +++++++------- src/Composer/Repository/Vcs/GitLabDriver.php | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Composer/Repository/Vcs/BitbucketDriver.php b/src/Composer/Repository/Vcs/BitbucketDriver.php index c360bad10..08f119527 100644 --- a/src/Composer/Repository/Vcs/BitbucketDriver.php +++ b/src/Composer/Repository/Vcs/BitbucketDriver.php @@ -119,10 +119,14 @@ abstract class BitbucketDriver extends VcsDriver if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) { - return $this->infoCache[$identifier] = JsonFile::parseJson($res); - } + $composer = JsonFile::parseJson($res); + } else { + $composer = $this->getBaseComposerInformation($identifier); - $composer = $this->getBaseComposerInformation($identifier); + if ($this->shouldCache($identifier)) { + $this->cache->write($identifier, json_encode($composer)); + } + } if ($composer) { // specials for bitbucket @@ -173,10 +177,6 @@ abstract class BitbucketDriver extends VcsDriver } $this->infoCache[$identifier] = $composer; - - if ($this->shouldCache($identifier)) { - $this->cache->write($identifier, json_encode($composer)); - } } return $this->infoCache[$identifier]; diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 7abda8164..26904b12f 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -150,10 +150,14 @@ class GitHubDriver extends VcsDriver if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) { - return $this->infoCache[$identifier] = JsonFile::parseJson($res); - } + $composer = JsonFile::parseJson($res); + } else { + $composer = $this->getBaseComposerInformation($identifier); - $composer = $this->getBaseComposerInformation($identifier); + if ($this->shouldCache($identifier)) { + $this->cache->write($identifier, json_encode($composer)); + } + } if ($composer) { // specials for github @@ -172,10 +176,6 @@ class GitHubDriver extends VcsDriver } } - if ($this->shouldCache($identifier)) { - $this->cache->write($identifier, json_encode($composer)); - } - $this->infoCache[$identifier] = $composer; } diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 2878f3f74..bb5c2121e 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -130,10 +130,14 @@ class GitLabDriver extends VcsDriver if (!isset($this->infoCache[$identifier])) { if ($this->shouldCache($identifier) && $res = $this->cache->read($identifier)) { - return $this->infoCache[$identifier] = JsonFile::parseJson($res); - } + $composer = JsonFile::parseJson($res); + } else { + $composer = $this->getBaseComposerInformation($identifier); - $composer = $this->getBaseComposerInformation($identifier); + if ($this->shouldCache($identifier)) { + $this->cache->write($identifier, json_encode($composer)); + } + } if ($composer) { // specials for gitlab (this data is only available if authentication is provided) @@ -145,10 +149,6 @@ class GitLabDriver extends VcsDriver } } - if ($this->shouldCache($identifier)) { - $this->cache->write($identifier, json_encode($composer)); - } - $this->infoCache[$identifier] = $composer; } @@ -446,7 +446,7 @@ class GitLabDriver extends VcsDriver if (!$moreThanGuestAccess) { $this->io->writeError('GitLab token with Guest only access detected'); - return $this->attemptCloneFallback(); + return $this->attemptCloneFallback(); } } From 404dea61c2a40f27a91c203c00ed33fb286ebedc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 29 Jul 2020 19:30:57 +0200 Subject: [PATCH 4/8] Allow specifying a version requirement for the relevant CLDR --- .../Repository/PlatformRepository.php | 35 +++++++++++++------ .../Repository/PlatformRepositoryTest.php | 32 +++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index ecd4ca256..848576aa3 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -154,7 +154,12 @@ class PlatformRepository extends ArrayRepository break; case 'intl': - $name = 'ICU'; + # Add a seperate version for the CLDR library version + $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); + $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + + $name = 'icu'; + $description = 'The ICU unicode and globalization support library'; if (defined('INTL_ICU_VERSION')) { $prettyVersion = INTL_ICU_VERSION; } else { @@ -228,15 +233,7 @@ class PlatformRepository extends ArrayRepository continue 2; } - try { - $version = $this->versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - continue; - } - - $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); - $lib->setDescription($description); - $this->addPackage($lib); + $this->addLibrary($name, $description, $prettyVersion); } $hhvmVersion = defined('HHVM_VERSION') ? HHVM_VERSION : null; @@ -346,4 +343,22 @@ class PlatformRepository extends ArrayRepository { return 'ext-' . str_replace(' ', '-', $name); } + + /** + * @param string $name + * @param string $description + * @param string $prettyVersion + */ + private function addLibrary($name, $description, $prettyVersion) + { + try { + $version = $this->versionParser->normalize($prettyVersion); + } catch (\UnexpectedValueException $e) { + return; + } + + $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); + $lib->setDescription($description); + $this->addPackage($lib); + } } diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index aa51a2fc6..20dd295fc 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Repository; +use Composer\Package\Package; use Composer\Repository\PlatformRepository; use Composer\Test\TestCase; use Composer\Util\Platform; @@ -67,4 +68,35 @@ class PlatformRepositoryTest extends TestCase { $this->assertNotNull($package, 'failed to find HHVM package'); $this->assertSame('4.0.1.0-dev', $package->getVersion()); } + + public function testICULibraryVersion() + { + if (!defined('INTL_ICU_VERSION')) { + $this->markTestSkipped('Test only work with ext-intl present'); + } + + $platformRepository = new PlatformRepository(); + $packages = $platformRepository->getPackages(); + + /** @var Package $icuPackage */ + $icuPackage = null; + /** @var Package $cldrPackage */ + $cldrPackage = null; + + foreach ($packages as $package) { + if ($package->getName() === 'lib-icu') { + $icuPackage = $package; + } + + if ($package->getName() === 'lib-cldr') { + $cldrPackage = $package; + } + } + + self::assertNotNull($icuPackage, 'Expected to find lib-icu in packages'); + self::assertNotNull($cldrPackage, 'Expected to find lib-cldr in packages'); + + self::assertSame(3, substr_count($icuPackage->getVersion(), '.'), 'Expected to find real ICU version'); + self::assertSame(3, substr_count($cldrPackage->getVersion(), '.'), 'Expected to find real CLDR version'); + } } From 5a02ea6a9622476a63515f34b1b2ef26c05ac405 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Thu, 30 Jul 2020 14:29:48 +0200 Subject: [PATCH 5/8] Check that class exists --- src/Composer/Repository/PlatformRepository.php | 8 +++++--- tests/Composer/Test/Repository/PlatformRepositoryTest.php | 7 +++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 848576aa3..5d240fa9c 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -154,9 +154,11 @@ class PlatformRepository extends ArrayRepository break; case 'intl': - # Add a seperate version for the CLDR library version - $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); - $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + if (class_exists('ResourceBundle', false)) { + # Add a seperate version for the CLDR library version + $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); + $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); + } $name = 'icu'; $description = 'The ICU unicode and globalization support library'; diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 20dd295fc..e254720fb 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -69,12 +69,15 @@ class PlatformRepositoryTest extends TestCase { $this->assertSame('4.0.1.0-dev', $package->getVersion()); } - public function testICULibraryVersion() - { + public function testICULibraryVersion() { if (!defined('INTL_ICU_VERSION')) { $this->markTestSkipped('Test only work with ext-intl present'); } + if (!class_exists('ResourceBundle', false)) { + $this->markTestSkipped('Test only work with ResourceBundle class present'); + } + $platformRepository = new PlatformRepository(); $packages = $platformRepository->getPackages(); From 5bd61ac55c45e031e749f4b0234821636ba2a6c5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Jul 2020 15:43:28 +0200 Subject: [PATCH 6/8] Cache versions data to avoid redownloading it twice during self-update --- src/Composer/SelfUpdate/Versions.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index 6a0a1bdbf..c2c54e984 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -26,6 +26,7 @@ class Versions private $rfs; private $config; private $channel; + private $versionsData; public function __construct(Config $config, RemoteFilesystem $rfs) { @@ -63,13 +64,7 @@ class Versions public function getLatest($channel = null) { - if ($this->config->get('disable-tls') === true) { - $protocol = 'http'; - } else { - $protocol = 'https'; - } - - $versions = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false)); + $versions = $this->getVersionsData(); foreach ($versions[$channel ?: $this->getChannel()] as $version) { if ($version['min-php'] <= PHP_VERSION_ID) { @@ -79,4 +74,19 @@ class Versions throw new \LogicException('There is no version of Composer available for your PHP version ('.PHP_VERSION.')'); } + + private function getVersionsData() + { + if (!$this->versionsData) { + if ($this->config->get('disable-tls') === true) { + $protocol = 'http'; + } else { + $protocol = 'https'; + } + + $this->versionsData = JsonFile::parseJson($this->rfs->getContents('getcomposer.org', $protocol . '://getcomposer.org/versions', false)); + } + + return $this->versionsData; + } } From 387e8289939284f1b3b67c392cd58b260e4e365c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Jul 2020 16:10:51 +0200 Subject: [PATCH 7/8] Promote next major version when running stable self-update, and prevent self-update from automatically upgrading to the next major release --- src/Composer/Command/SelfUpdateCommand.php | 28 ++++++++++++++++++++++ src/Composer/SelfUpdate/Versions.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 5ac7fa1f1..d4d13364e 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -135,8 +135,36 @@ EOT $latest = $versionsUtil->getLatest(); $latestStable = $versionsUtil->getLatest('stable'); + try { + $latestPreview = $versionsUtil->getLatest('preview'); + } catch (\UnexpectedValueException $e) { + $latestPreview = $latestStable; + } $latestVersion = $latest['version']; $updateVersion = $input->getArgument('version') ?: $latestVersion; + $currentMajorVersion = preg_replace('{^(\d+).*}', '$1', Composer::getVersion()); + $updateMajorVersion = preg_replace('{^(\d+).*}', '$1', $updateVersion); + $previewMajorVersion = preg_replace('{^(\d+).*}', '$1', $latestPreview['version']); + + if ($versionsUtil->getChannel() === 'stable' && !$input->getArgument('version')) { + // if requesting stable channel and no specific version, avoid automatically upgrading to the next major + // simply output a warning that the next major stable is available and let users upgrade to it manually + if ($currentMajorVersion < $updateMajorVersion) { + $skippedVersion = $updateVersion; + + $versionsUtil->setChannel($currentMajorVersion); + + $latest = $versionsUtil->getLatest(); + $latestStable = $versionsUtil->getLatest('stable'); + $latestVersion = $latest['version']; + $updateVersion = $latestVersion; + + $io->writeError('A new stable major version of Composer is available ('.$skippedVersion.'), run "composer self-update --'.$updateMajorVersion.'" to update to it. See also https://github.com/composer/composer/releases for changelogs.'); + } elseif ($currentMajorVersion < $previewMajorVersion) { + // promote next major version if available in preview + $io->writeError('A preview release of the next major version of Composer is available ('.$latestPreview['version'].'), run "composer self-update --preview" to give it a try. See also https://github.com/composer/composer/releases for changelogs.'); + } + } if ($requestedChannel && is_numeric($requestedChannel) && substr($latestStable['version'], 0, 1) !== $requestedChannel) { $io->writeError('Warning: You forced the install of '.$latestVersion.' via --'.$requestedChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.'); diff --git a/src/Composer/SelfUpdate/Versions.php b/src/Composer/SelfUpdate/Versions.php index c2c54e984..7a0835ae8 100644 --- a/src/Composer/SelfUpdate/Versions.php +++ b/src/Composer/SelfUpdate/Versions.php @@ -72,7 +72,7 @@ class Versions } } - throw new \LogicException('There is no version of Composer available for your PHP version ('.PHP_VERSION.')'); + throw new \UnexpectedValueException('There is no version of Composer available for your PHP version ('.PHP_VERSION.')'); } private function getVersionsData() From 00f712a7c48aa88c837c3571dd3578855a70e9bd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 30 Jul 2020 21:00:43 +0200 Subject: [PATCH 8/8] Revert "Allow specifying a version requirement for CLDR" --- .../Repository/PlatformRepository.php | 37 +++++-------------- .../Repository/PlatformRepositoryTest.php | 35 ------------------ 2 files changed, 10 insertions(+), 62 deletions(-) diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index 5d240fa9c..ecd4ca256 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -154,14 +154,7 @@ class PlatformRepository extends ArrayRepository break; case 'intl': - if (class_exists('ResourceBundle', false)) { - # Add a seperate version for the CLDR library version - $cldrVersion = \ResourceBundle::create('root', 'ICUDATA-curr', false)->get('Version'); - $this->addLibrary('cldr', 'The unicode CLDR project', $cldrVersion); - } - - $name = 'icu'; - $description = 'The ICU unicode and globalization support library'; + $name = 'ICU'; if (defined('INTL_ICU_VERSION')) { $prettyVersion = INTL_ICU_VERSION; } else { @@ -235,7 +228,15 @@ class PlatformRepository extends ArrayRepository continue 2; } - $this->addLibrary($name, $description, $prettyVersion); + try { + $version = $this->versionParser->normalize($prettyVersion); + } catch (\UnexpectedValueException $e) { + continue; + } + + $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); + $lib->setDescription($description); + $this->addPackage($lib); } $hhvmVersion = defined('HHVM_VERSION') ? HHVM_VERSION : null; @@ -345,22 +346,4 @@ class PlatformRepository extends ArrayRepository { return 'ext-' . str_replace(' ', '-', $name); } - - /** - * @param string $name - * @param string $description - * @param string $prettyVersion - */ - private function addLibrary($name, $description, $prettyVersion) - { - try { - $version = $this->versionParser->normalize($prettyVersion); - } catch (\UnexpectedValueException $e) { - return; - } - - $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); - $lib->setDescription($description); - $this->addPackage($lib); - } } diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index e254720fb..aa51a2fc6 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -12,7 +12,6 @@ namespace Composer\Test\Repository; -use Composer\Package\Package; use Composer\Repository\PlatformRepository; use Composer\Test\TestCase; use Composer\Util\Platform; @@ -68,38 +67,4 @@ class PlatformRepositoryTest extends TestCase { $this->assertNotNull($package, 'failed to find HHVM package'); $this->assertSame('4.0.1.0-dev', $package->getVersion()); } - - public function testICULibraryVersion() { - if (!defined('INTL_ICU_VERSION')) { - $this->markTestSkipped('Test only work with ext-intl present'); - } - - if (!class_exists('ResourceBundle', false)) { - $this->markTestSkipped('Test only work with ResourceBundle class present'); - } - - $platformRepository = new PlatformRepository(); - $packages = $platformRepository->getPackages(); - - /** @var Package $icuPackage */ - $icuPackage = null; - /** @var Package $cldrPackage */ - $cldrPackage = null; - - foreach ($packages as $package) { - if ($package->getName() === 'lib-icu') { - $icuPackage = $package; - } - - if ($package->getName() === 'lib-cldr') { - $cldrPackage = $package; - } - } - - self::assertNotNull($icuPackage, 'Expected to find lib-icu in packages'); - self::assertNotNull($cldrPackage, 'Expected to find lib-cldr in packages'); - - self::assertSame(3, substr_count($icuPackage->getVersion(), '.'), 'Expected to find real ICU version'); - self::assertSame(3, substr_count($cldrPackage->getVersion(), '.'), 'Expected to find real CLDR version'); - } }