public function testWhatProvidesWithCamelcasePackageName()
    {
        $assetName = 'CamelCasePackage';
        $name = $this->getType().'-asset/' . strtolower($assetName);
        $rfs = $this->replaceRegistryRfsByMock();
        $rfs->expects($this->at(0))
            ->method('getContents')
            ->will($this->throwException(new TransportException('Package not found', 404)));
        $rfs->expects($this->at(1))
            ->method('getContents')
            ->will($this->throwException(new TransportException('Package not found', 404)));
        $rfs->expects($this->at(2))
            ->method('getContents')
            ->will($this->throwException(new TransportException('Package not found', 404)));
        $rfs->expects($this->at(3))
            ->method('getContents')
            ->will($this->returnValue(json_encode($this->getMockSearchResult($assetName))));
        $rfs->expects($this->at(4))
            ->method('getContents')
            ->will($this->returnValue(json_encode($this->getMockPackageForVcsConfig())));

        $this->assertCount(0, $this->rm->getRepositories());
        $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
        $this->assertCount(0, $this->registry->whatProvides($this->pool, $name));
        $this->assertCount(1, $this->rm->getRepositories());
    }
 /**
  * Checks if the package vcs repository is already include in repository manager.
  *
  * @param string $name The package name of the vcs repository
  *
  * @return bool
  */
 protected function hasVcsRepository($name)
 {
     foreach ($this->repositoryManager->getRepositories() as $mRepo) {
         if ($mRepo instanceof AssetVcsRepository && $name === $mRepo->getComposerPackageName()) {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 public function testPrepend()
 {
     $rm = new RepositoryManager($this->getMock('Composer\\IO\\IOInterface'), $this->getMock('Composer\\Config'), $this->getMockBuilder('Composer\\EventDispatcher\\EventDispatcher')->disableOriginalConstructor()->getMock());
     $repository1 = $this->getMock('Composer\\Repository\\RepositoryInterface');
     $repository2 = $this->getMock('Composer\\Repository\\RepositoryInterface');
     $rm->addRepository($repository1);
     $rm->prependRepository($repository2);
     $this->assertEquals(array($repository2, $repository1), $rm->getRepositories());
 }
Esempio n. 4
0
 protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false)
 {
     $minimumStability = $this->package->getMinimumStability();
     $stabilityFlags = $this->package->getStabilityFlags();
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locker to create aliased packages
     $installFromLock = false;
     if (!$this->update && $this->locker->isLocked($devMode)) {
         $installFromLock = true;
         $lockedRepository = $this->locker->getLockedRepository($devMode);
         $minimumStability = $this->locker->getMinimumStability();
         $stabilityFlags = $this->locker->getStabilityFlags();
     }
     $this->whitelistUpdateDependencies($localRepo, $devMode, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->write('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $policy = new DefaultPolicy();
     $pool = new Pool($minimumStability, $stabilityFlags);
     $pool->addRepository($installedRepo, $aliases);
     if ($installFromLock) {
         $pool->addRepository($lockedRepository, $aliases);
     }
     if (!$installFromLock || !$this->locker->isCompleteFormat($devMode)) {
         $repositories = $this->repositoryManager->getRepositories();
         foreach ($repositories as $repository) {
             $pool->addRepository($repository, $aliases);
         }
     }
     // creating requirements request
     $request = new Request($pool);
     $constraint = new VersionConstraint('=', $this->package->getVersion());
     $constraint->setPrettyString($this->package->getPrettyVersion());
     $request->install($this->package->getName(), $constraint);
     if ($this->update) {
         $this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $request->updateAll();
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } elseif ($installFromLock) {
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>');
         if (!$this->locker->isCompleteFormat($devMode)) {
             $this->io->write('<warning>Warning: Your lock file is in a deprecated format. It will most likely take a *long* time for composer to install dependencies, and may cause dependency solving issues.</warning>');
         }
         if (!$this->locker->isFresh() && !$devMode) {
             $this->io->write('<warning>Warning: The lock file is not up to date with the latest changes in composer.json, you may be getting outdated dependencies, run update to update them.</warning>');
         }
         foreach ($lockedRepository->getPackages() as $package) {
             $version = $package->getVersion();
             if (isset($aliases[$package->getName()][$version])) {
                 $version = $aliases[$package->getName()][$version]['alias_normalized'];
             }
             $constraint = new VersionConstraint('=', $version);
             $constraint->setPrettyString($package->getPrettyVersion());
             $request->install($package->getName(), $constraint);
         }
     } else {
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // fix the version of all installed packages (+ platform) that are not
     // in the current local repo to prevent rogue updates (e.g. non-dev
     // updating when in dev)
     foreach ($installedRepo->getPackages() as $package) {
         if ($package->getRepository() === $localRepo) {
             continue;
         }
         $constraint = new VersionConstraint('=', $package->getVersion());
         $constraint->setPrettyString($package->getPrettyVersion());
         $request->install($package->getName(), $constraint);
     }
     // if the updateWhitelist is enabled, packages not in it are also fixed
     // to the version specified in the lock, or their currently installed version
     if ($this->update && $this->updateWhitelist) {
         if ($this->locker->isLocked($devMode)) {
             $currentPackages = $this->locker->getLockedRepository($devMode)->getPackages();
         } else {
             $currentPackages = $installedRepo->getPackages();
         }
         // collect links from composer as well as installed packages
         $candidates = array();
         foreach ($links as $link) {
             $candidates[$link->getTarget()] = true;
         }
         foreach ($localRepo->getPackages() as $package) {
             $candidates[$package->getName()] = true;
         }
         // fix them to the version in lock (or currently installed) if they are not updateable
         foreach ($candidates as $candidate => $dummy) {
             foreach ($currentPackages as $curPackage) {
                 if ($curPackage->getName() === $candidate) {
                     if ($this->isUpdateable($curPackage)) {
                         break;
                     }
                     $constraint = new VersionConstraint('=', $curPackage->getVersion());
                     $request->install($curPackage->getName(), $constraint);
                 }
             }
         }
     }
     // force dev packages to have the latest links if we update or install from a (potentially new) lock
     $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-links');
     // solve dependencies
     $solver = new Solver($policy, $pool, $installedRepo);
     try {
         $operations = $solver->solve($request);
     } catch (SolverProblemsException $e) {
         $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
         $this->io->write($e->getMessage());
         return false;
     }
     if ($devMode) {
         // remove bogus operations that the solver creates for stuff that was force-updated in the non-dev pass
         // TODO this should not be necessary ideally, but it seems to work around the problem quite well
         foreach ($operations as $index => $op) {
             if ('update' === $op->getJobType() && $op->getInitialPackage()->getUniqueName() === $op->getTargetPackage()->getUniqueName() && $op->getInitialPackage()->getSourceReference() === $op->getTargetPackage()->getSourceReference() && $op->getInitialPackage()->getDistReference() === $op->getTargetPackage()->getDistReference()) {
                 unset($operations[$index]);
             }
         }
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-updates', $operations);
     // execute operations
     if (!$operations) {
         $this->io->write('Nothing to install or update');
     }
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
                 $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason);
             }
         }
         $event = 'Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
         }
         // not installing from lock, force dev packages' references if they're in root package refs
         if (!$installFromLock) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $package->setSourceReference($references[$package->getName()]);
                     $package->setDistReference($references[$package->getName()]);
                 }
             }
         }
         // output alias operations in verbose mode, or all ops in dry run
         if ($this->dryRun || $this->verbose && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->write('  - ' . $operation);
         }
         $this->installationManager->execute($localRepo, $operation);
         $event = 'Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     return true;
 }
Esempio n. 5
0
 protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
 {
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locker to create aliased packages
     $installFromLock = false;
     if (!$this->update && $this->locker->isLocked()) {
         $installFromLock = true;
         try {
             $lockedRepository = $this->locker->getLockedRepository($withDevReqs);
         } catch (\RuntimeException $e) {
             // if there are dev requires, then we really can not install
             if ($this->package->getDevRequires()) {
                 throw $e;
             }
             // no require-dev in composer.json and the lock file was created with no dev info, so skip them
             $lockedRepository = $this->locker->getLockedRepository();
         }
     }
     $this->whitelistUpdateDependencies($localRepo, $withDevReqs, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->writeError('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $policy = $this->createPolicy();
     $pool = $this->createPool($withDevReqs, $lockedRepository);
     $pool->addRepository($installedRepo, $aliases);
     if ($installFromLock) {
         $pool->addRepository($lockedRepository, $aliases);
     }
     if (!$installFromLock) {
         $repositories = $this->repositoryManager->getRepositories();
         foreach ($repositories as $repository) {
             $pool->addRepository($repository, $aliases);
         }
     }
     // creating requirements request
     $request = $this->createRequest($pool, $this->package, $platformRepo);
     if (!$installFromLock) {
         // remove unstable packages from the localRepo if they don't match the current stability settings
         $removedUnstablePackages = array();
         foreach ($localRepo->getPackages() as $package) {
             if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
                 $removedUnstablePackages[$package->getName()] = true;
                 $request->remove($package->getName(), new VersionConstraint('=', $package->getVersion()));
             }
         }
     }
     if ($this->update) {
         $this->io->writeError('<info>Updating dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . '</info>');
         $request->updateAll();
         if ($withDevReqs) {
             $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         } else {
             $links = $this->package->getRequires();
         }
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
         // if the updateWhitelist is enabled, packages not in it are also fixed
         // to the version specified in the lock, or their currently installed version
         if ($this->updateWhitelist) {
             if ($this->locker->isLocked()) {
                 try {
                     $currentPackages = $this->locker->getLockedRepository($withDevReqs)->getPackages();
                 } catch (\RuntimeException $e) {
                     // fetch only non-dev packages from lock if doing a dev update fails due to a previously incomplete lock file
                     $currentPackages = $this->locker->getLockedRepository()->getPackages();
                 }
             } else {
                 $currentPackages = $installedRepo->getPackages();
             }
             // collect packages to fixate from root requirements as well as installed packages
             $candidates = array();
             foreach ($links as $link) {
                 $candidates[$link->getTarget()] = true;
             }
             foreach ($localRepo->getPackages() as $package) {
                 $candidates[$package->getName()] = true;
             }
             // fix them to the version in lock (or currently installed) if they are not updateable
             foreach ($candidates as $candidate => $dummy) {
                 foreach ($currentPackages as $curPackage) {
                     if ($curPackage->getName() === $candidate) {
                         if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) {
                             $constraint = new VersionConstraint('=', $curPackage->getVersion());
                             $request->install($curPackage->getName(), $constraint);
                         }
                         break;
                     }
                 }
             }
         }
     } elseif ($installFromLock) {
         $this->io->writeError('<info>Installing dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . ' from lock file</info>');
         if (!$this->locker->isFresh()) {
             $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>');
         }
         foreach ($lockedRepository->getPackages() as $package) {
             $version = $package->getVersion();
             if (isset($aliases[$package->getName()][$version])) {
                 $version = $aliases[$package->getName()][$version]['alias_normalized'];
             }
             $constraint = new VersionConstraint('=', $version);
             $constraint->setPrettyString($package->getPrettyVersion());
             $request->install($package->getName(), $constraint);
         }
         foreach ($this->locker->getPlatformRequirements($withDevReqs) as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } else {
         $this->io->writeError('<info>Installing dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . '</info>');
         if ($withDevReqs) {
             $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         } else {
             $links = $this->package->getRequires();
         }
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // force dev packages to have the latest links if we update or install from a (potentially new) lock
     $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-links');
     // solve dependencies
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
     $solver = new Solver($policy, $pool, $installedRepo);
     try {
         $operations = $solver->solve($request, $this->ignorePlatformReqs);
         $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
     } catch (SolverProblemsException $e) {
         $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>');
         $this->io->writeError($e->getMessage());
         return max(1, $e->getCode());
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-updates', $operations);
     // execute operations
     if (!$operations) {
         $this->io->writeError('Nothing to install or update');
     }
     $operations = $this->movePluginsToFront($operations);
     $operations = $this->moveUninstallsToFront($operations);
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
                 $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason);
             }
         }
         // not installing from lock, force dev packages' references if they're in root package refs
         if (!$installFromLock) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $package->setSourceReference($references[$package->getName()]);
                     $package->setDistReference($references[$package->getName()]);
                 }
             }
             if ('update' === $operation->getJobType() && $operation->getTargetPackage()->isDev() && $operation->getTargetPackage()->getVersion() === $operation->getInitialPackage()->getVersion() && $operation->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference()) {
                 if ($this->io->isDebug()) {
                     $this->io->writeError('  - Skipping update of ' . $operation->getTargetPackage()->getPrettyName() . ' to the same reference-locked version');
                     $this->io->writeError('');
                 }
                 continue;
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         // output non-alias ops in dry run, output alias ops in debug verbosity
         if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         }
         $this->installationManager->execute($localRepo, $operation);
         // output reasons why the operation was ran, only for install/update operations
         if ($this->verbose && $this->io->isVeryVerbose() && in_array($operation->getJobType(), array('install', 'update'))) {
             $reason = $operation->getReason();
             if ($reason instanceof Rule) {
                 switch ($reason->getReason()) {
                     case Rule::RULE_JOB_INSTALL:
                         $this->io->writeError('    REASON: Required by root: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                     case Rule::RULE_PACKAGE_REQUIRES:
                         $this->io->writeError('    REASON: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                 }
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     return 0;
 }
Esempio n. 6
0
 protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false)
 {
     $minimumStability = $this->package->getMinimumStability();
     $stabilityFlags = $this->package->getStabilityFlags();
     // initialize locker to create aliased packages
     if (!$this->update && $this->locker->isLocked($devMode)) {
         $lockedPackages = $this->locker->getLockedPackages($devMode);
         $minimumStability = $this->locker->getMinimumStability();
         $stabilityFlags = $this->locker->getStabilityFlags();
     }
     $this->whitelistUpdateDependencies($localRepo, $devMode, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->write('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $pool = new Pool($minimumStability, $stabilityFlags);
     $pool->addRepository($installedRepo);
     foreach ($this->repositoryManager->getRepositories() as $repository) {
         $pool->addRepository($repository);
     }
     // creating requirements request
     $installFromLock = false;
     $request = new Request($pool);
     $constraint = new VersionConstraint('=', $this->package->getVersion());
     $request->install($this->package->getName(), $constraint);
     if ($this->update) {
         $this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $request->updateAll();
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } elseif ($this->locker->isLocked($devMode)) {
         $installFromLock = true;
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>');
         if (!$this->locker->isFresh() && !$devMode) {
             $this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
         }
         foreach ($lockedPackages as $package) {
             $version = $package->getVersion();
             foreach ($aliases as $alias) {
                 if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
                     $version = $alias['alias_normalized'];
                     break;
                 }
             }
             $constraint = new VersionConstraint('=', $version);
             $request->install($package->getName(), $constraint);
         }
     } else {
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // fix the version of all installed packages (+ platform) that are not
     // in the current local repo to prevent rogue updates (e.g. non-dev
     // updating when in dev)
     foreach ($installedRepo->getPackages() as $package) {
         if ($package->getRepository() === $localRepo) {
             continue;
         }
         $constraint = new VersionConstraint('=', $package->getVersion());
         $request->install($package->getName(), $constraint);
     }
     // if the updateWhitelist is enabled, packages not in it are also fixed
     // to the version specified in the lock, or their currently installed version
     if ($this->update && $this->updateWhitelist) {
         if ($this->locker->isLocked($devMode)) {
             $currentPackages = $this->locker->getLockedPackages($devMode);
         } else {
             $currentPackages = $installedRepo->getPackages();
         }
         // collect links from composer as well as installed packages
         $candidates = array();
         foreach ($links as $link) {
             $candidates[$link->getTarget()] = true;
         }
         foreach ($localRepo->getPackages() as $package) {
             $candidates[$package->getName()] = true;
         }
         // fix them to the version in lock (or currently installed) if they are not updateable
         foreach ($candidates as $candidate => $dummy) {
             foreach ($currentPackages as $curPackage) {
                 if ($curPackage->getName() === $candidate) {
                     if ($this->isUpdateable($curPackage)) {
                         break;
                     }
                     $constraint = new VersionConstraint('=', $curPackage->getVersion());
                     $request->install($curPackage->getName(), $constraint);
                 }
             }
         }
     }
     // prepare solver
     $policy = new DefaultPolicy();
     $solver = new Solver($policy, $pool, $installedRepo);
     // solve dependencies
     try {
         $operations = $solver->solve($request);
     } catch (SolverProblemsException $e) {
         $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>');
         $this->io->write($e->getMessage());
         return false;
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     foreach ($localRepo->getPackages() as $package) {
         // skip non-dev packages
         if (!$package->isDev()) {
             continue;
         }
         // skip packages that will be updated/uninstalled
         foreach ($operations as $operation) {
             if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) {
                 continue 2;
             }
         }
         // force update to locked version if it does not match the installed version
         if ($installFromLock) {
             $lockData = $this->locker->getLockData();
             unset($lockedReference);
             foreach ($lockData['packages'] as $lockedPackage) {
                 if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
                     $lockedReference = $lockedPackage['source-reference'];
                     break;
                 }
             }
             if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) {
                 // changing the source ref to update to will be handled in the operations loop below
                 $operations[] = new UpdateOperation($package, clone $package);
             }
         } else {
             // force update to latest on update
             if ($this->update) {
                 // skip package if the whitelist is enabled and it is not in it
                 if ($this->updateWhitelist && !$this->isUpdateable($package)) {
                     continue;
                 }
                 $newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
                 if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
                     $operations[] = new UpdateOperation($package, $newPackage);
                 }
             }
             // force installed package to update to referenced version if it does not match the installed version
             $references = $this->package->getReferences();
             if (isset($references[$package->getName()]) && $references[$package->getName()] !== $package->getSourceReference()) {
                 // changing the source ref to update to will be handled in the operations loop below
                 $operations[] = new UpdateOperation($package, clone $package);
             }
         }
     }
     // execute operations
     if (!$operations) {
         $this->io->write('Nothing to install or update');
     }
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
                 $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason);
             }
         }
         $event = 'Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $operation);
         }
         // if installing from lock, restore dev packages' references to their locked state
         if ($installFromLock) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $lockData = $this->locker->getLockData();
                 foreach ($lockData['packages'] as $lockedPackage) {
                     if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
                         // update commit date to allow recovery in case the commit disappeared
                         if (!empty($lockedPackage['commit-date'])) {
                             $package->setReleaseDate(new \DateTime('@' . $lockedPackage['commit-date']));
                         }
                         $package->setSourceReference($lockedPackage['source-reference']);
                         break;
                     }
                 }
             }
         } else {
             // not installing from lock, force dev packages' references if they're in root package refs
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $package->setSourceReference($references[$package->getName()]);
                 }
             }
         }
         // output alias operations in verbose mode, or all ops in dry run
         if ($this->dryRun || $this->verbose && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->write('  - ' . $operation);
         }
         $this->installationManager->execute($localRepo, $operation);
         $event = 'Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     return true;
 }
Esempio n. 7
0
 /**
  * @param  RepositoryInterface $localRepo
  * @param  RepositoryInterface $installedRepo
  * @param  PlatformRepository  $platformRepo
  * @param  array               $aliases
  * @return array [int, PackageInterfaces[]|null] with the exit code and an array of dev packages on update, or null on install
  */
 protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases)
 {
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locked repo if we are installing from lock or in a partial update
     // and a lock file is present as we need to force install non-whitelisted lock file
     // packages in that case
     if (!$this->update || !empty($this->updateWhitelist) && $this->locker->isLocked()) {
         try {
             $lockedRepository = $this->locker->getLockedRepository($this->devMode);
         } catch (\RuntimeException $e) {
             // if there are dev requires, then we really can not install
             if ($this->package->getDevRequires()) {
                 throw $e;
             }
             // no require-dev in composer.json and the lock file was created with no dev info, so skip them
             $lockedRepository = $this->locker->getLockedRepository();
         }
     }
     $this->whitelistUpdateDependencies($localRepo, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->writeError('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $policy = $this->createPolicy();
     $pool = $this->createPool($this->update ? null : $lockedRepository);
     $pool->addRepository($installedRepo, $aliases);
     if ($this->update) {
         $repositories = $this->repositoryManager->getRepositories();
         foreach ($repositories as $repository) {
             $pool->addRepository($repository, $aliases);
         }
     }
     // Add the locked repository after the others in case we are doing a
     // partial update so missing packages can be found there still.
     // For installs from lock it's the only one added so it is first
     if ($lockedRepository) {
         $pool->addRepository($lockedRepository, $aliases);
     }
     // creating requirements request
     $request = $this->createRequest($this->package, $platformRepo);
     if ($this->update) {
         // remove unstable packages from the localRepo if they don't match the current stability settings
         $removedUnstablePackages = array();
         foreach ($localRepo->getPackages() as $package) {
             if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
                 $removedUnstablePackages[$package->getName()] = true;
                 $request->remove($package->getName(), new Constraint('=', $package->getVersion()));
             }
         }
         $this->io->writeError('<info>Updating dependencies' . ($this->devMode ? ' (including require-dev)' : '') . '</info>');
         $request->updateAll();
         $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
         // if the updateWhitelist is enabled, packages not in it are also fixed
         // to the version specified in the lock, or their currently installed version
         if ($this->updateWhitelist) {
             $currentPackages = $this->getCurrentPackages($installedRepo);
             // collect packages to fixate from root requirements as well as installed packages
             $candidates = array();
             foreach ($links as $link) {
                 $candidates[$link->getTarget()] = true;
                 $rootRequires[$link->getTarget()] = $link;
             }
             foreach ($currentPackages as $package) {
                 $candidates[$package->getName()] = true;
             }
             // fix them to the version in lock (or currently installed) if they are not updateable
             foreach ($candidates as $candidate => $dummy) {
                 foreach ($currentPackages as $curPackage) {
                     if ($curPackage->getName() === $candidate) {
                         if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) {
                             $constraint = new Constraint('=', $curPackage->getVersion());
                             $description = $this->locker->isLocked() ? '(locked at' : '(installed at';
                             $requiredAt = isset($rootRequires[$candidate]) ? ', required as ' . $rootRequires[$candidate]->getPrettyConstraint() : '';
                             $constraint->setPrettyString($description . ' ' . $curPackage->getPrettyVersion() . $requiredAt . ')');
                             $request->install($curPackage->getName(), $constraint);
                         }
                         break;
                     }
                 }
             }
         }
     } else {
         $this->io->writeError('<info>Installing dependencies' . ($this->devMode ? ' (including require-dev)' : '') . ' from lock file</info>');
         if (!$this->locker->isFresh()) {
             $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>', true, IOInterface::QUIET);
         }
         foreach ($lockedRepository->getPackages() as $package) {
             $version = $package->getVersion();
             if (isset($aliases[$package->getName()][$version])) {
                 $version = $aliases[$package->getName()][$version]['alias_normalized'];
             }
             $constraint = new Constraint('=', $version);
             $constraint->setPrettyString($package->getPrettyVersion());
             $request->install($package->getName(), $constraint);
         }
         foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // force dev packages to have the latest links if we update or install from a (potentially new) lock
     $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-links');
     // solve dependencies
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
     $solver = new Solver($policy, $pool, $installedRepo, $this->io);
     try {
         $operations = $solver->solve($request, $this->ignorePlatformReqs);
     } catch (SolverProblemsException $e) {
         $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>', true, IOInterface::QUIET);
         $this->io->writeError($e->getMessage());
         return array(max(1, $e->getCode()), array());
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-updates', $operations);
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
     $this->io->writeError("Analyzed " . count($pool) . " packages to resolve dependencies", true, IOInterface::VERBOSE);
     $this->io->writeError("Analyzed " . $solver->getRuleSetSize() . " rules to resolve dependencies", true, IOInterface::VERBOSE);
     // execute operations
     if (!$operations) {
         $this->io->writeError('Nothing to install or update');
     }
     $operations = $this->movePluginsToFront($operations);
     $operations = $this->moveUninstallsToFront($operations);
     // extract dev packages and mark them to be skipped if it's a --no-dev install or update
     // we also force them to be uninstalled if they are present in the local repo
     if ($this->update) {
         $devPackages = $this->extractDevPackages($operations, $localRepo, $platformRepo, $aliases);
         if (!$this->devMode) {
             $operations = $this->filterDevPackageOperations($devPackages, $operations, $localRepo);
         }
     } else {
         $devPackages = null;
     }
     if ($operations) {
         $installs = $updates = $uninstalls = array();
         foreach ($operations as $operation) {
             if ($operation instanceof InstallOperation) {
                 $installs[] = $operation->getPackage()->getPrettyName() . ':' . $operation->getPackage()->getFullPrettyVersion();
             } elseif ($operation instanceof UpdateOperation) {
                 $updates[] = $operation->getTargetPackage()->getPrettyName() . ':' . $operation->getTargetPackage()->getFullPrettyVersion();
             } elseif ($operation instanceof UninstallOperation) {
                 $uninstalls[] = $operation->getPackage()->getPrettyName();
             }
         }
         $this->io->writeError(sprintf("<info>Package operations: %d install%s, %d update%s, %d removal%s</info>", count($installs), 1 === count($installs) ? '' : 's', count($updates), 1 === count($updates) ? '' : 's', count($uninstalls), 1 === count($uninstalls) ? '' : 's'));
         if ($installs) {
             $this->io->writeError("Installs: " . implode(', ', $installs), true, IOInterface::VERBOSE);
         }
         if ($updates) {
             $this->io->writeError("Updates: " . implode(', ', $updates), true, IOInterface::VERBOSE);
         }
         if ($uninstalls) {
             $this->io->writeError("Removals: " . implode(', ', $uninstalls), true, IOInterface::VERBOSE);
         }
     }
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             $this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage());
         }
         // updating, force dev packages' references if they're in root package refs
         if ($this->update) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $this->updateInstallReferences($package, $references[$package->getName()]);
                 }
             }
             if ('update' === $operation->getJobType() && $operation->getTargetPackage()->isDev() && $operation->getTargetPackage()->getVersion() === $operation->getInitialPackage()->getVersion() && (!$operation->getTargetPackage()->getSourceReference() || $operation->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference()) && (!$operation->getTargetPackage()->getDistReference() || $operation->getTargetPackage()->getDistReference() === $operation->getInitialPackage()->getDistReference())) {
                 $this->io->writeError('  - Skipping update of ' . $operation->getTargetPackage()->getPrettyName() . ' to the same reference-locked version', true, IOInterface::DEBUG);
                 $this->io->writeError('', true, IOInterface::DEBUG);
                 continue;
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         // output non-alias ops in dry run, output alias ops in debug verbosity
         if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         }
         $this->installationManager->execute($localRepo, $operation);
         // output reasons why the operation was ran, only for install/update operations
         if ($this->verbose && $this->io->isVeryVerbose() && in_array($operation->getJobType(), array('install', 'update'))) {
             $reason = $operation->getReason();
             if ($reason instanceof Rule) {
                 switch ($reason->getReason()) {
                     case Rule::RULE_JOB_INSTALL:
                         $this->io->writeError('    REASON: Required by the root package: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                     case Rule::RULE_PACKAGE_REQUIRES:
                         $this->io->writeError('    REASON: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                 }
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     if (!$this->dryRun) {
         // force source/dist urls to be updated for all packages
         $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
         $localRepo->write();
     }
     return array(0, $devPackages);
 }
Esempio n. 8
0
 protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false)
 {
     // creating repository pool
     $pool = new Pool();
     $pool->addRepository($installedRepo);
     foreach ($this->repositoryManager->getRepositories() as $repository) {
         $pool->addRepository($repository);
     }
     // creating requirements request
     $installFromLock = false;
     $request = new Request($pool);
     if ($this->update) {
         $this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $request->updateAll();
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } elseif ($this->locker->isLocked($devMode)) {
         $installFromLock = true;
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>');
         if (!$this->locker->isFresh() && !$devMode) {
             $this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
         }
         foreach ($this->locker->getLockedPackages($devMode) as $package) {
             $version = $package->getVersion();
             foreach ($aliases as $alias) {
                 if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
                     $version = $alias['alias'];
                     break;
                 }
             }
             $constraint = new VersionConstraint('=', $version);
             $request->install($package->getName(), $constraint);
         }
     } else {
         $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>');
         $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires();
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // fix the version all installed packages that are not in the current local repo to prevent rogue updates
     foreach ($installedRepo->getPackages() as $package) {
         if ($package->getRepository() === $localRepo || $package->getRepository() instanceof PlatformRepository) {
             continue;
         }
         $constraint = new VersionConstraint('=', $package->getVersion());
         $request->install($package->getName(), $constraint);
     }
     // prepare solver
     $policy = new DefaultPolicy();
     $solver = new Solver($policy, $pool, $installedRepo);
     // solve dependencies
     try {
         $operations = $solver->solve($request);
     } catch (SolverProblemsException $e) {
         $this->io->write('<error>Your requirements could not be solved to an installable set of packages.</error>');
         $this->io->write($e->getMessage());
         return false;
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     if ($this->update || $installFromLock) {
         foreach ($localRepo->getPackages() as $package) {
             // skip non-dev packages
             if (!$package->isDev()) {
                 continue;
             }
             // skip packages that will be updated/uninstalled
             foreach ($operations as $operation) {
                 if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) {
                     continue 2;
                 }
             }
             // force update to latest on update
             if ($this->update) {
                 $newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
                 if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
                     $operations[] = new UpdateOperation($package, $newPackage);
                 }
             } elseif ($installFromLock) {
                 // force update to locked version if it does not match the installed version
                 $lockData = $this->locker->getLockData();
                 unset($lockedReference);
                 foreach ($lockData['packages'] as $lockedPackage) {
                     if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
                         $lockedReference = $lockedPackage['source-reference'];
                         break;
                     }
                 }
                 if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) {
                     // changing the source ref to update to will be handled in the operations loop below
                     $operations[] = new UpdateOperation($package, $package);
                 }
             }
         }
     }
     // anti-alias local repository to allow updates to work fine
     foreach ($localRepo->getPackages() as $package) {
         if ($package instanceof AliasPackage) {
             $package->getRepository()->addPackage(clone $package->getAliasOf());
             $package->getRepository()->removePackage($package);
         }
     }
     // execute operations
     if (!$operations) {
         $this->io->write('Nothing to install or update');
     }
     foreach ($operations as $operation) {
         if ($this->verbose) {
             $this->io->write((string) $operation);
         }
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
                 $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason);
             }
         }
         if (!$this->dryRun) {
             $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
             // if installing from lock, restore dev packages' references to their locked state
             if ($installFromLock) {
                 $package = null;
                 if ('update' === $operation->getJobType()) {
                     $package = $operation->getTargetPackage();
                 } elseif ('install' === $operation->getJobType()) {
                     $package = $operation->getPackage();
                 }
                 if ($package && $package->isDev()) {
                     $lockData = $this->locker->getLockData();
                     foreach ($lockData['packages'] as $lockedPackage) {
                         if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
                             $package->setSourceReference($lockedPackage['source-reference']);
                             break;
                         }
                     }
                 }
             }
             $this->installationManager->execute($localRepo, $operation);
             $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
             $localRepo->write();
         }
     }
     // reload local repository for the dev pass to work ok with aliases since it was anti-aliased above
     if (!$devMode) {
         $localRepo->reload();
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Run installation (or update)
  *
  * @param Boolean $preferSource
  * @param Boolean $dryRun
  * @param Boolean $verbose
  * @param Boolean $noInstallRecommends
  * @param Boolean $installSuggests
  * @param Boolean $update
  * @param RepositoryInterface $additionalInstalledRepository
  */
 public function run($preferSource = false, $dryRun = false, $verbose = false, $noInstallRecommends = false, $installSuggests = false, $update = false, RepositoryInterface $additionalInstalledRepository = null)
 {
     if ($dryRun) {
         $verbose = true;
     }
     if ($preferSource) {
         $this->downloadManager->setPreferSource(true);
     }
     $this->repositoryManager = $this->repositoryManager;
     // create local repo, this contains all packages that are installed in the local project
     $localRepo = $this->repositoryManager->getLocalRepository();
     // create installed repo, this contains all local packages + platform packages (php & extensions)
     $installedRepo = new CompositeRepository(array($localRepo, new PlatformRepository()));
     if ($additionalInstalledRepository) {
         $installedRepo->addRepository($additionalInstalledRepository);
     }
     // prepare aliased packages
     if (!$update && $this->locker->isLocked()) {
         $aliases = $this->locker->getAliases();
     } else {
         $aliases = $this->package->getAliases();
     }
     foreach ($aliases as $alias) {
         foreach ($this->repositoryManager->findPackages($alias['package'], $alias['version']) as $package) {
             $package->getRepository()->addPackage(new AliasPackage($package, $alias['alias_normalized'], $alias['alias']));
         }
         foreach ($this->repositoryManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) {
             $this->repositoryManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias_normalized'], $alias['alias']));
             $this->repositoryManager->getLocalRepository()->removePackage($package);
         }
     }
     // creating repository pool
     $pool = new Pool();
     $pool->addRepository($installedRepo);
     foreach ($this->repositoryManager->getRepositories() as $repository) {
         $pool->addRepository($repository);
     }
     // dispatch pre event
     if (!$dryRun) {
         $eventName = $update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
         $this->eventDispatcher->dispatchCommandEvent($eventName);
     }
     // creating requirements request
     $installFromLock = false;
     $request = new Request($pool);
     if ($update) {
         $this->io->write('<info>Updating dependencies</info>');
         $request->updateAll();
         $links = $this->collectLinks($noInstallRecommends, $installSuggests);
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } elseif ($this->locker->isLocked()) {
         $installFromLock = true;
         $this->io->write('<info>Installing from lock file</info>');
         if (!$this->locker->isFresh()) {
             $this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>');
         }
         foreach ($this->locker->getLockedPackages() as $package) {
             $version = $package->getVersion();
             foreach ($aliases as $alias) {
                 if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) {
                     $version = $alias['alias'];
                     break;
                 }
             }
             $constraint = new VersionConstraint('=', $version);
             $request->install($package->getName(), $constraint);
         }
     } else {
         $this->io->write('<info>Installing dependencies</info>');
         $links = $this->collectLinks($noInstallRecommends, $installSuggests);
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // prepare solver
     $policy = new DefaultPolicy();
     $solver = new Solver($policy, $pool, $installedRepo);
     // solve dependencies
     $operations = $solver->solve($request);
     // force dev packages to be updated to latest reference on update
     if ($update) {
         foreach ($localRepo->getPackages() as $package) {
             if ($package instanceof AliasPackage) {
                 $package = $package->getAliasOf();
             }
             // skip non-dev packages
             if (!$package->isDev()) {
                 continue;
             }
             // skip packages that will be updated/uninstalled
             foreach ($operations as $operation) {
                 if ('update' === $operation->getJobType() && $package === $operation->getInitialPackage() || 'uninstall' === $operation->getJobType() && $package === $operation->getPackage()) {
                     continue 2;
                 }
             }
             // force update
             $newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
             if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
                 $operations[] = new UpdateOperation($package, $newPackage);
             }
         }
     }
     // anti-alias local repository to allow updates to work fine
     foreach ($this->repositoryManager->getLocalRepository()->getPackages() as $package) {
         if ($package instanceof AliasPackage) {
             $this->repositoryManager->getLocalRepository()->addPackage(clone $package->getAliasOf());
             $this->repositoryManager->getLocalRepository()->removePackage($package);
         }
     }
     // execute operations
     if (!$operations) {
         $this->io->write('<info>Nothing to install/update</info>');
     }
     foreach ($operations as $operation) {
         if ($verbose) {
             $this->io->write((string) $operation);
         }
         if (!$dryRun) {
             $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
             // if installing from lock, restore dev packages' references to their locked state
             if ($installFromLock) {
                 $package = null;
                 if ('update' === $operation->getJobType()) {
                     $package = $operation->getTargetPackage();
                 } elseif ('install' === $operation->getJobType()) {
                     $package = $operation->getPackage();
                 }
                 if ($package && $package->isDev()) {
                     $lockData = $this->locker->getLockData();
                     foreach ($lockData['packages'] as $lockedPackage) {
                         if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) {
                             $package->setSourceReference($lockedPackage['source-reference']);
                             break;
                         }
                     }
                 }
             }
             $this->installationManager->execute($operation);
             $this->eventDispatcher->dispatchPackageEvent(constant('Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType())), $operation);
         }
     }
     if (!$dryRun) {
         if ($update || !$this->locker->isLocked()) {
             $this->locker->setLockData($localRepo->getPackages(), $aliases);
             $this->io->write('<info>Writing lock file</info>');
         }
         $localRepo->write();
         $this->io->write('<info>Generating autoload files</info>');
         $generator = new AutoloadGenerator();
         $generator->dump($localRepo, $this->package, $this->installationManager, $this->installationManager->getVendorPath() . '/.composer');
         // dispatch post event
         $eventName = $update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
         $this->eventDispatcher->dispatchCommandEvent($eventName);
     }
 }