1
0
Fork 0

PoolBuilder: make io non-nullable, NullIO can be used instead

pull/8717/head
Nils Adermann 2020-04-01 15:27:51 +02:00
parent 71c3c63b54
commit c270d3cfa6
5 changed files with 29 additions and 29 deletions

View File

@ -48,7 +48,7 @@ class PoolBuilder
private $skippedLoad = array(); private $skippedLoad = array();
private $updateAllowWarned = array(); private $updateAllowWarned = array();
public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, EventDispatcher $eventDispatcher = null, IOInterface $io = null) public function __construct(array $acceptableStabilities, array $stabilityFlags, array $rootAliases, array $rootReferences, IOInterface $io = null, EventDispatcher $eventDispatcher = null)
{ {
$this->acceptableStabilities = $acceptableStabilities; $this->acceptableStabilities = $acceptableStabilities;
$this->stabilityFlags = $stabilityFlags; $this->stabilityFlags = $stabilityFlags;
@ -244,7 +244,7 @@ class PoolBuilder
if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $require)) { if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $require)) {
$this->unfixPackage($request, $require); $this->unfixPackage($request, $require);
$loadNames[$require] = null; $loadNames[$require] = null;
} elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $require) && !isset($this->updateAllowWarned[$require]) && $this->io) { } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $require) && !isset($this->updateAllowWarned[$require])) {
$this->updateAllowWarned[$require] = true; $this->updateAllowWarned[$require] = true;
$this->io->writeError('<warning>Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.</warning>'); $this->io->writeError('<warning>Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.</warning>');
} }
@ -275,7 +275,7 @@ class PoolBuilder
$loadNames[$replace] = null; $loadNames[$replace] = null;
// TODO should we try to merge constraints here? // TODO should we try to merge constraints here?
$this->nameConstraints[$replace] = null; $this->nameConstraints[$replace] = null;
} elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $replace) && !isset($this->updateAllowWarned[$require]) && $this->io) { } elseif (!$request->getUpdateAllowTransitiveRootDependencies() && $this->isRootRequire($request, $replace) && !isset($this->updateAllowWarned[$require])) {
$this->updateAllowWarned[$replace] = true; $this->updateAllowWarned[$replace] = true;
$this->io->writeError('<warning>Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.</warning>'); $this->io->writeError('<warning>Dependency "'.$require.'" is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies to include root dependencies.</warning>');
} }
@ -315,7 +315,6 @@ class PoolBuilder
private function warnAboutNonMatchingUpdateAllowList(Request $request) private function warnAboutNonMatchingUpdateAllowList(Request $request)
{ {
if ($this->io) {
foreach ($this->updateAllowList as $pattern => $void) { foreach ($this->updateAllowList as $pattern => $void) {
$patternRegexp = BasePackage::packageNameToRegexp($pattern); $patternRegexp = BasePackage::packageNameToRegexp($pattern);
// update pattern matches a locked package? => all good // update pattern matches a locked package? => all good
@ -337,7 +336,6 @@ class PoolBuilder
} }
} }
} }
}
/** /**
* Reverts the decision to use a fixed package from lock file if a partial update with transitive dependencies * Reverts the decision to use a fixed package from lock file if a partial update with transitive dependencies

View File

@ -393,7 +393,7 @@ class Installer
$request->setUpdateAllowList($this->updateAllowList, $this->updateAllowTransitiveDependencies); $request->setUpdateAllowList($this->updateAllowList, $this->updateAllowTransitiveDependencies);
} }
$pool = $repositorySet->createPool($request, $this->eventDispatcher, $this->io); $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher);
// solve dependencies // solve dependencies
$solver = new Solver($policy, $pool, $this->io, $repositorySet); $solver = new Solver($policy, $pool, $this->io, $repositorySet);
@ -612,7 +612,7 @@ class Installer
$request->requireName($link->getTarget(), $link->getConstraint()); $request->requireName($link->getTarget(), $link->getConstraint());
} }
$pool = $repositorySet->createPool($request, $this->eventDispatcher, $this->io); $pool = $repositorySet->createPool($request, $this->io, $this->eventDispatcher);
// solve dependencies // solve dependencies
$solver = new Solver($policy, $pool, $this->io, $repositorySet); $solver = new Solver($policy, $pool, $this->io, $repositorySet);

View File

@ -17,6 +17,7 @@ use Composer\DependencyResolver\PoolBuilder;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\EventDispatcher\EventDispatcher; use Composer\EventDispatcher\EventDispatcher;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
@ -186,9 +187,9 @@ class RepositorySet
* *
* @return Pool * @return Pool
*/ */
public function createPool(Request $request, EventDispatcher $eventDispatcher = null, IOInterface $io = null) public function createPool(Request $request, IOInterface $io, EventDispatcher $eventDispatcher = null)
{ {
$poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $eventDispatcher, $io); $poolBuilder = new PoolBuilder($this->acceptableStabilities, $this->stabilityFlags, $this->rootAliases, $this->rootReferences, $io, $eventDispatcher);
foreach ($this->repositories as $repo) { foreach ($this->repositories as $repo) {
if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) { if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) {
@ -237,6 +238,6 @@ class RepositorySet
$request->requireName($packageName); $request->requireName($packageName);
} }
return $this->createPool($request); return $this->createPool($request, new NullIO());
} }
} }

View File

@ -89,7 +89,7 @@ class PoolBuilderTest extends TestCase
$request->fixPackage($loadPackage($fixedPackage)); $request->fixPackage($loadPackage($fixedPackage));
} }
$pool = $repositorySet->createPool($request); $pool = $repositorySet->createPool($request, new NullIO());
for ($i = 1, $count = count($pool); $i <= $count; $i++) { for ($i = 1, $count = count($pool); $i <= $count; $i++) {
$result[] = $pool->packageById($i); $result[] = $pool->packageById($i);
} }

View File

@ -890,8 +890,9 @@ class SolverTest extends TestCase
protected function createSolver() protected function createSolver()
{ {
$this->pool = $this->repoSet->createPool($this->request); $io = new NullIO();
$this->solver = new Solver($this->policy, $this->pool, new NullIO()); $this->pool = $this->repoSet->createPool($this->request, $io);
$this->solver = new Solver($this->policy, $this->pool, $io);
} }
protected function checkSolverResult(array $expected) protected function checkSolverResult(array $expected)