1
0
Fork 0

Make sure repos are always initialized with a repo manager if possible, and make sure async is always enabled on the process executor, fixes #10783 (#10799)

pull/10809/head
Jordi Boggiano 2022-05-24 21:32:36 +02:00 committed by GitHub
parent 865886e5c5
commit 88e1f0f9b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 15 deletions

View File

@ -159,7 +159,7 @@ EOT
$localRepo = $composer->getRepositoryManager()->getLocalRepository(); $localRepo = $composer->getRepositoryManager()->getLocalRepository();
$repo = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories())); $repo = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
} else { } else {
$defaultRepos = RepositoryFactory::defaultRepos($this->getIO()); $defaultRepos = RepositoryFactory::defaultReposWithDefaultManager($io);
$io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos))); $io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
$repo = new CompositeRepository($defaultRepos); $repo = new CompositeRepository($defaultRepos);
} }

View File

@ -18,6 +18,7 @@ use Composer\Package\CompletePackageInterface;
use Composer\Package\RootPackage; use Composer\Package\RootPackage;
use Composer\Repository\InstalledArrayRepository; use Composer\Repository\InstalledArrayRepository;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RootPackageRepository; use Composer\Repository\RootPackageRepository;
use Composer\Repository\InstalledRepository; use Composer\Repository\InstalledRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
@ -80,7 +81,7 @@ abstract class BaseDependencyCommand extends BaseCommand
// If the version we ask for is not installed then we need to locate it in remote repos and add it. // If the version we ask for is not installed then we need to locate it in remote repos and add it.
// This is needed for why-not to resolve conflicts from an uninstalled version against installed packages. // This is needed for why-not to resolve conflicts from an uninstalled version against installed packages.
if (!$installedRepo->findPackage($needle, $textConstraint)) { if (!$installedRepo->findPackage($needle, $textConstraint)) {
$defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos($this->getIO())); $defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos($this->getIO(), $composer->getConfig(), $composer->getRepositoryManager()));
if ($match = $defaultRepos->findPackage($needle, $textConstraint)) { if ($match = $defaultRepos->findPackage($needle, $textConstraint)) {
$installedRepo->addRepository(new InstalledArrayRepository(array(clone $match))); $installedRepo->addRepository(new InstalledArrayRepository(array(clone $match)));
} }

View File

@ -170,6 +170,6 @@ EOT
); );
} }
return RepositoryFactory::defaultRepos($this->getIO()); return RepositoryFactory::defaultReposWithDefaultManager($this->getIO());
} }
} }

View File

@ -225,6 +225,9 @@ EOT
$repositories = $input->getOption('repository'); $repositories = $input->getOption('repository');
if (count($repositories) > 0) { if (count($repositories) > 0) {
$config = Factory::createConfig($io); $config = Factory::createConfig($io);
$io->loadConfiguration($config);
$repoManager = RepositoryFactory::manager($io, $config);
$repos = array(new PlatformRepository); $repos = array(new PlatformRepository);
$createDefaultPackagistRepo = true; $createDefaultPackagistRepo = true;
foreach ($repositories as $repo) { foreach ($repositories as $repo) {
@ -236,14 +239,14 @@ EOT
$createDefaultPackagistRepo = false; $createDefaultPackagistRepo = false;
continue; continue;
} }
$repos[] = RepositoryFactory::createRepo($io, $config, $repoConfig); $repos[] = RepositoryFactory::createRepo($io, $config, $repoConfig, $repoManager);
} }
if ($createDefaultPackagistRepo) { if ($createDefaultPackagistRepo) {
$repos[] = RepositoryFactory::createRepo($io, $config, array( $repos[] = RepositoryFactory::createRepo($io, $config, array(
'type' => 'composer', 'type' => 'composer',
'url' => 'https://repo.packagist.org', 'url' => 'https://repo.packagist.org',
)); ), $repoManager);
} }
$this->repos = new CompositeRepository($repos); $this->repos = new CompositeRepository($repos);

View File

@ -47,7 +47,7 @@ trait PackageDiscoveryTrait
if (null === $this->repos) { if (null === $this->repos) {
$this->repos = new CompositeRepository(array_merge( $this->repos = new CompositeRepository(array_merge(
array(new PlatformRepository), array(new PlatformRepository),
RepositoryFactory::defaultRepos($this->getIO()) RepositoryFactory::defaultReposWithDefaultManager($this->getIO())
)); ));
} }

View File

@ -194,7 +194,7 @@ EOT
$repos = new CompositeRepository($composer->getRepositoryManager()->getRepositories()); $repos = new CompositeRepository($composer->getRepositoryManager()->getRepositories());
$installedRepo->addRepository($composer->getRepositoryManager()->getLocalRepository()); $installedRepo->addRepository($composer->getRepositoryManager()->getLocalRepository());
} else { } else {
$defaultRepos = RepositoryFactory::defaultRepos($io); $defaultRepos = RepositoryFactory::defaultReposWithDefaultManager($io);
$repos = new CompositeRepository($defaultRepos); $repos = new CompositeRepository($defaultRepos);
$io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos))); $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
} }
@ -209,7 +209,7 @@ EOT
} }
$repos = new CompositeRepository(array_merge(array(new FilterRepository($installedRepo, array('canonical' => false))), $composer->getRepositoryManager()->getRepositories())); $repos = new CompositeRepository(array_merge(array(new FilterRepository($installedRepo, array('canonical' => false))), $composer->getRepositoryManager()->getRepositories()));
} elseif ($input->getOption('all')) { } elseif ($input->getOption('all')) {
$defaultRepos = RepositoryFactory::defaultRepos($io); $defaultRepos = RepositoryFactory::defaultReposWithDefaultManager($io);
$io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos))); $io->writeError('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = new InstalledRepository(array($platformRepo)); $installedRepo = new InstalledRepository(array($platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos)); $repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));

View File

@ -80,7 +80,8 @@ class RepositoryFactory
public static function createRepo(IOInterface $io, Config $config, array $repoConfig, RepositoryManager $rm = null): RepositoryInterface public static function createRepo(IOInterface $io, Config $config, array $repoConfig, RepositoryManager $rm = null): RepositoryInterface
{ {
if (!$rm) { if (!$rm) {
$rm = static::manager($io, $config, Factory::createHttpDownloader($io, $config)); @trigger_error('Not passing a repository manager when calling createRepo is deprecated since Composer 2.3.6', E_USER_DEPRECATED);
$rm = static::manager($io, $config);
} }
$repos = self::createRepos($rm, array($repoConfig)); $repos = self::createRepos($rm, array($repoConfig));
@ -95,14 +96,18 @@ class RepositoryFactory
*/ */
public static function defaultRepos(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null): array public static function defaultRepos(IOInterface $io = null, Config $config = null, RepositoryManager $rm = null): array
{ {
if (!$config) { if (null === $rm) {
@trigger_error('Not passing a repository manager when calling defaultRepos is deprecated since Composer 2.3.6, use defaultReposWithDefaultManager() instead if you cannot get a manager.', E_USER_DEPRECATED);
}
if (null === $config) {
$config = Factory::createConfig($io); $config = Factory::createConfig($io);
} }
if ($io) { if (null !== $io) {
$io->loadConfiguration($config); $io->loadConfiguration($config);
} }
if (!$rm) { if (null === $rm) {
if (!$io) { if (null === $io) {
throw new \InvalidArgumentException('This function requires either an IOInterface or a RepositoryManager'); throw new \InvalidArgumentException('This function requires either an IOInterface or a RepositoryManager');
} }
$rm = static::manager($io, $config, Factory::createHttpDownloader($io, $config)); $rm = static::manager($io, $config, Factory::createHttpDownloader($io, $config));
@ -118,8 +123,16 @@ class RepositoryFactory
* @param HttpDownloader $httpDownloader * @param HttpDownloader $httpDownloader
* @return RepositoryManager * @return RepositoryManager
*/ */
public static function manager(IOInterface $io, Config $config, HttpDownloader $httpDownloader, EventDispatcher $eventDispatcher = null, ProcessExecutor $process = null): RepositoryManager public static function manager(IOInterface $io, Config $config, HttpDownloader $httpDownloader = null, EventDispatcher $eventDispatcher = null, ProcessExecutor $process = null): RepositoryManager
{ {
if ($httpDownloader === null) {
$httpDownloader = Factory::createHttpDownloader($io, $config);
}
if ($process === null) {
$process = new ProcessExecutor($io);
$process->enableAsync();
}
$rm = new RepositoryManager($io, $config, $httpDownloader, $eventDispatcher, $process); $rm = new RepositoryManager($io, $config, $httpDownloader, $eventDispatcher, $process);
$rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository'); $rm->setRepositoryClass('composer', 'Composer\Repository\ComposerRepository');
$rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository'); $rm->setRepositoryClass('vcs', 'Composer\Repository\VcsRepository');
@ -140,6 +153,18 @@ class RepositoryFactory
return $rm; return $rm;
} }
/**
* @return RepositoryInterface[]
*/
public static function defaultReposWithDefaultManager(IOInterface $io): array
{
$manager = RepositoryFactory::manager($io, $config = Factory::createConfig($io));
$io->loadConfiguration($config);
return RepositoryFactory::defaultRepos($io, $config, $manager);
}
/** /**
* @param array<int|string, mixed> $repoConfigs * @param array<int|string, mixed> $repoConfigs
* *

View File

@ -87,9 +87,11 @@ class PoolBuilderTest extends TestCase
chdir(__DIR__.'/Fixtures/poolbuilder/'); chdir(__DIR__.'/Fixtures/poolbuilder/');
$repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $rootAliases, $rootReferences); $repositorySet = new RepositorySet($minimumStability, $stabilityFlags, $rootAliases, $rootReferences);
$config = new Config(false);
$rm = RepositoryFactory::manager($io = new NullIO(), $config);
foreach ($packageRepos as $packages) { foreach ($packageRepos as $packages) {
if (isset($packages['type'])) { if (isset($packages['type'])) {
$repo = RepositoryFactory::createRepo(new NullIO, new Config(false), $packages); $repo = RepositoryFactory::createRepo($io, $config, $packages, $rm);
$repositorySet->addRepository($repo); $repositorySet->addRepository($repo);
continue; continue;
} }