1
0
Fork 0

Restore PRE/POST_DEPENDENCY_SOLVING events

pull/8566/head
Jordi Boggiano 2020-01-30 22:10:39 +01:00
parent 7e142b5d6b
commit 71855e6430
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
5 changed files with 43 additions and 43 deletions

View File

@ -14,6 +14,8 @@ namespace Composer\EventDispatcher;
use Composer\DependencyResolver\PolicyInterface; use Composer\DependencyResolver\PolicyInterface;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Transaction;
use Composer\Installer\InstallerEvent; use Composer\Installer\InstallerEvent;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Composer; use Composer\Composer;
@ -128,9 +130,9 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0 * value is changed to 1, anything else to 0
*/ */
public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, RepositoryInterface $localRepo, Request $request, array $operations = array()) public function dispatchInstallerEvent($eventName, $devMode, RepositorySet $repositorySet, Pool $pool, Request $request, PolicyInterface $policy, Transaction $transaction = null)
{ {
return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $repositorySet, $localRepo, $request, $operations)); return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $repositorySet, $pool, $request, $policy, $transaction));
} }
/** /**

View File

@ -381,10 +381,8 @@ class Installer
} }
} }
// TODO reenable events
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
$pool = $repositorySet->createPool($request); $pool = $repositorySet->createPool($request);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $repositorySet, $pool, $request, $policy);
// solve dependencies // solve dependencies
$solver = new Solver($policy, $pool, $this->io, $repositorySet); $solver = new Solver($policy, $pool, $this->io, $repositorySet);
@ -403,7 +401,7 @@ class Installer
} }
// TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update? // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $lockedRepository, $request, $lockTransaction); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $repositorySet, $pool, $request, $policy, $lockTransaction);
$this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE); $this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
$this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE); $this->io->writeError("Analyzed ".$ruleSetSize." rules to resolve dependencies", true, IOInterface::VERBOSE);
@ -526,11 +524,11 @@ class Installer
$pool = $repositorySet->createPool($request); $pool = $repositorySet->createPool($request);
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $repositorySet, $pool, $request, $policy);
$solver = new Solver($policy, $pool, $this->io, $repositorySet); $solver = new Solver($policy, $pool, $this->io, $repositorySet);
try { try {
$nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs); $nonDevLockTransaction = $solver->solve($request, $this->ignorePlatformReqs);
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $repositorySet, $pool, $request, $policy, $nonDevLockTransaction);
$solver = null; $solver = null;
} catch (SolverProblemsException $e) { } catch (SolverProblemsException $e) {
$this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET); $this->io->writeError('<error>Unable to find a compatible set of packages based on your non-dev requirements alone.</error>', true, IOInterface::QUIET);
@ -580,9 +578,8 @@ class Installer
$request->requireName($link->getTarget(), $link->getConstraint()); $request->requireName($link->getTarget(), $link->getConstraint());
} }
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
$pool = $repositorySet->createPool($request); $pool = $repositorySet->createPool($request);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $repositorySet, $pool, $request, $policy);
// solve dependencies // solve dependencies
$solver = new Solver($policy, $pool, $this->io, $repositorySet); $solver = new Solver($policy, $pool, $this->io, $repositorySet);
@ -604,7 +601,7 @@ class Installer
} }
// TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update? // TODO should we warn people / error if plugins in vendor folder do not match contents of lock file before update?
//$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $lockTransaction); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $repositorySet, $pool, $request, $policy, $lockTransaction);
} }
// TODO in how far do we need to do anything here to ensure dev packages being updated to latest in lock without version change are treated correctly? // TODO in how far do we need to do anything here to ensure dev packages being updated to latest in lock without version change are treated correctly?

View File

@ -14,11 +14,11 @@ namespace Composer\Installer;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\PolicyInterface; use Composer\DependencyResolver\PolicyInterface;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Transaction;
use Composer\EventDispatcher\Event; use Composer\EventDispatcher\Event;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositorySet; use Composer\Repository\RepositorySet;
/** /**
@ -43,20 +43,15 @@ class InstallerEvent extends Event
*/ */
private $devMode; private $devMode;
/**
* @var PolicyInterface
*/
private $policy;
/** /**
* @var RepositorySet * @var RepositorySet
*/ */
private $repositorySet; private $repositorySet;
/** /**
* @var RepositoryInterface * @var Pool
*/ */
private $localRepo; private $pool;
/** /**
* @var Request * @var Request
@ -64,9 +59,14 @@ class InstallerEvent extends Event
private $request; private $request;
/** /**
* @var OperationInterface[] * @var PolicyInterface
*/ */
private $operations; private $policy;
/**
* @var Transaction|null
*/
private $transaction;
/** /**
* Constructor. * Constructor.
@ -75,24 +75,24 @@ class InstallerEvent extends Event
* @param Composer $composer * @param Composer $composer
* @param IOInterface $io * @param IOInterface $io
* @param bool $devMode * @param bool $devMode
* @param PolicyInterface $policy
* @param RepositorySet $repositorySet * @param RepositorySet $repositorySet
* @param RepositoryInterface $localRepo * @param Pool $pool
* @param Request $request * @param Request $request
* @param OperationInterface[] $operations * @param PolicyInterface $policy
* @param Transaction $transaction
*/ */
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, RepositoryInterface $localRepo, Request $request, array $operations = array()) public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, RepositorySet $repositorySet, Pool $pool, Request $request, PolicyInterface $policy, Transaction $transaction = null)
{ {
parent::__construct($eventName); parent::__construct($eventName);
$this->composer = $composer; $this->composer = $composer;
$this->io = $io; $this->io = $io;
$this->devMode = $devMode; $this->devMode = $devMode;
$this->policy = $policy;
$this->repositorySet = $repositorySet; $this->repositorySet = $repositorySet;
$this->localRepo = $localRepo; $this->pool = $pool;
$this->request = $request; $this->request = $request;
$this->operations = $operations; $this->policy = $policy;
$this->transaction = $transaction;
} }
/** /**
@ -136,11 +136,11 @@ class InstallerEvent extends Event
} }
/** /**
* @return RepositoryInterface * @return Pool
*/ */
public function getLocalRepo() public function getPool()
{ {
return $this->localRepo; return $this->pool;
} }
/** /**
@ -152,10 +152,10 @@ class InstallerEvent extends Event
} }
/** /**
* @return OperationInterface[] * @return Transaction|null
*/ */
public function getOperations() public function getTransaction()
{ {
return $this->operations; return $this->transaction;
} }
} }

View File

@ -567,11 +567,12 @@ class EventDispatcherTest extends TestCase
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock(); $policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
$repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock(); $repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
$installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock(); $pool = $this->getMockBuilder('Composer\DependencyResolver\Pool')->disableOriginalConstructor()->getMock();
$transaction = $this->getMockBuilder('Composer\DependencyResolver\LockTransaction')->disableOriginalConstructor()->getMock();
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
$dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request); $dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $repositorySet, $pool, $request, $policy);
$dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request, array()); $dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $repositorySet, $pool, $request, $policy, $transaction);
} }
public static function call() public static function call()

View File

@ -23,10 +23,10 @@ class InstallerEventTest extends TestCase
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock(); $policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
$repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock(); $repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
$localRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock(); $pool = $this->getMockBuilder('Composer\DependencyResolver\Pool')->disableOriginalConstructor()->getMock();
$transaction = $this->getMockBuilder('Composer\DependencyResolver\LockTransaction')->disableOriginalConstructor()->getMock();
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
$operations = array($this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock()); $event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $repositorySet, $pool, $request, $policy, $transaction);
$event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $policy, $repositorySet, $localRepo, $request, $operations);
$this->assertSame('EVENT_NAME', $event->getName()); $this->assertSame('EVENT_NAME', $event->getName());
$this->assertInstanceOf('Composer\Composer', $event->getComposer()); $this->assertInstanceOf('Composer\Composer', $event->getComposer());
@ -34,8 +34,8 @@ class InstallerEventTest extends TestCase
$this->assertTrue($event->isDevMode()); $this->assertTrue($event->isDevMode());
$this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy()); $this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy());
$this->assertInstanceOf('Composer\Repository\RepositorySet', $event->getRepositorySet()); $this->assertInstanceOf('Composer\Repository\RepositorySet', $event->getRepositorySet());
$this->assertInstanceOf('Composer\Repository\RepositoryInterface', $event->getLocalRepo()); $this->assertInstanceOf('Composer\DependencyResolver\Pool', $event->getPool());
$this->assertInstanceOf('Composer\DependencyResolver\Request', $event->getRequest()); $this->assertInstanceOf('Composer\DependencyResolver\Request', $event->getRequest());
$this->assertCount(1, $event->getOperations()); $this->assertInstanceOf('Composer\DependencyResolver\Transaction', $event->getTransaction());
} }
} }