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 $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->stabilityFlags = $stabilityFlags;
@ -244,7 +244,7 @@ class PoolBuilder
if ($request->getUpdateAllowTransitiveRootDependencies() || !$this->isRootRequire($request, $require)) {
$this->unfixPackage($request, $require);
$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->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;
// TODO should we try to merge constraints here?
$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->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,27 +315,25 @@ class PoolBuilder
private function warnAboutNonMatchingUpdateAllowList(Request $request)
{
if ($this->io) {
foreach ($this->updateAllowList as $pattern => $void) {
$patternRegexp = BasePackage::packageNameToRegexp($pattern);
// update pattern matches a locked package? => all good
foreach ($request->getLockedRepository()->getPackages() as $package) {
if (preg_match($patternRegexp, $package->getName())) {
continue 2;
}
foreach ($this->updateAllowList as $pattern => $void) {
$patternRegexp = BasePackage::packageNameToRegexp($pattern);
// update pattern matches a locked package? => all good
foreach ($request->getLockedRepository()->getPackages() as $package) {
if (preg_match($patternRegexp, $package->getName())) {
continue 2;
}
// update pattern matches a root require? => all good, probably a new package
foreach ($request->getRequires() as $packageName => $constraint) {
if (preg_match($patternRegexp, $packageName)) {
continue 2;
}
}
if (strpos($pattern, '*') !== false) {
$this->io->writeError('<warning>Pattern "' . $pattern . '" listed for update does not match any locked packages.</warning>');
} else {
$this->io->writeError('<warning>Package "' . $pattern . '" listed for update is not locked.</warning>');
}
// update pattern matches a root require? => all good, probably a new package
foreach ($request->getRequires() as $packageName => $constraint) {
if (preg_match($patternRegexp, $packageName)) {
continue 2;
}
}
if (strpos($pattern, '*') !== false) {
$this->io->writeError('<warning>Pattern "' . $pattern . '" listed for update does not match any locked packages.</warning>');
} else {
$this->io->writeError('<warning>Package "' . $pattern . '" listed for update is not locked.</warning>');
}
}
}

View File

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

View File

@ -17,6 +17,7 @@ use Composer\DependencyResolver\PoolBuilder;
use Composer\DependencyResolver\Request;
use Composer\EventDispatcher\EventDispatcher;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Package\BasePackage;
use Composer\Package\Version\VersionParser;
use Composer\Repository\CompositeRepository;
@ -186,9 +187,9 @@ class RepositorySet
*
* @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) {
if (($repo instanceof InstalledRepositoryInterface || $repo instanceof InstalledRepository) && !$this->allowInstalledRepositories) {
@ -237,6 +238,6 @@ class RepositorySet
$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));
}
$pool = $repositorySet->createPool($request);
$pool = $repositorySet->createPool($request, new NullIO());
for ($i = 1, $count = count($pool); $i <= $count; $i++) {
$result[] = $pool->packageById($i);
}

View File

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