예제 #1
0
 public function getCoreBundleVersion()
 {
     $installedFile = $this->kernelRootDir . '/../vendor/composer/installed.json';
     $repo = new InstalledFilesystemRepository(new JsonFile($installedFile));
     $corePackage = $repo->findPackage('claroline/core-bundle', '*');
     return $corePackage->getPrettyVersion();
 }
 /**
  * @dataProvider getDataForInstalledTests
  *
  * @param array       $extra
  * @param string      $packageName
  * @param string      $version
  * @param string      $minimumStability
  * @param string|null $rootRequireVersion
  * @param string|null $installedVersion
  * @param bool        $validSkip
  */
 public function testFilterWithInstalledPackage(array $extra, $packageName, $version, $minimumStability, $rootRequireVersion, $installedVersion, $validSkip)
 {
     $installed = null === $installedVersion ? array() : array($packageName => $installedVersion);
     $require = null === $rootRequireVersion ? array() : array($packageName => $rootRequireVersion);
     $this->installedRepository = $this->getMockBuilder('Composer\\Repository\\InstalledFilesystemRepository')->disableOriginalConstructor()->getMock();
     $this->installedRepository->expects($this->any())->method('getPackages')->will($this->returnValue($this->convertInstalled($installed)));
     $this->init($require, $minimumStability, $extra);
     $this->assertSame($validSkip, $this->filter->skip($this->assetType, $packageName, $version));
 }
 /**
  * Creates a new instance.
  */
 public function __construct()
 {
     $constantName = 'BARTFEENSTRA_COMPOSER_PACKAGE_LOCATOR_VENDOR_DIR';
     if (!defined($constantName)) {
         // @codingStandardsIgnoreStart
         throw new \RuntimeException(sprintf('%s was not defined. Maybe you installed Composer packages with `--no-plugin`. Run `composer dump-autoload` again.', $constantName));
         // @codingStandardsIgnoreEnd
     }
     parent::__construct(new JsonFile(BARTFEENSTRA_COMPOSER_PACKAGE_LOCATOR_VENDOR_DIR . '/composer/installed.json'));
 }
 /**
  * Initialize the installed package.
  */
 private function initInstalledPackages()
 {
     /* @var PackageInterface $package */
     foreach ($this->installedRepository->getPackages() as $package) {
         $operator = $this->getFilterOperator($package);
         /* @var Link $link */
         $link = current($this->arrayLoader->parseLinks($this->package->getName(), $this->package->getVersion(), 'installed', array($package->getName() => $operator . $package->getPrettyVersion())));
         $link = $this->includeRootConstraint($package, $link);
         $this->requires[$package->getName()] = $link;
     }
 }
예제 #5
0
 /**
  * Run installation (or update)
  *
  * @return int 0 on success or a positive error code on failure
  *
  * @throws \Exception
  */
 public function run()
 {
     gc_collect_cycles();
     gc_disable();
     if ($this->dryRun) {
         $this->verbose = true;
         $this->runScripts = false;
         $this->installationManager->addInstaller(new NoopInstaller());
         $this->mockLocalRepositories($this->repositoryManager);
     }
     // TODO remove this BC feature at some point
     // purge old require-dev packages to avoid conflicts with the new way of handling dev requirements
     $devRepo = new InstalledFilesystemRepository(new JsonFile($this->config->get('vendor-dir') . '/composer/installed_dev.json'));
     if ($devRepo->getPackages()) {
         $this->io->writeError('<warning>BC Notice: Removing old dev packages to migrate to the new require-dev handling.</warning>');
         foreach ($devRepo->getPackages() as $package) {
             if ($this->installationManager->isPackageInstalled($devRepo, $package)) {
                 $this->installationManager->uninstall($devRepo, new UninstallOperation($package));
             }
         }
         unlink($this->config->get('vendor-dir') . '/composer/installed_dev.json');
     }
     unset($devRepo, $package);
     // end BC
     if ($this->runScripts) {
         // dispatch pre event
         $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
         $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
     }
     $this->downloadManager->setPreferSource($this->preferSource);
     $this->downloadManager->setPreferDist($this->preferDist);
     // clone root package to have one in the installed repo that does not require anything
     // we don't want it to be uninstallable, but its requirements should not conflict
     // with the lock file for example
     $installedRootPackage = clone $this->package;
     $installedRootPackage->setRequires(array());
     $installedRootPackage->setDevRequires(array());
     // create installed repo, this contains all local packages + platform packages (php & extensions)
     $localRepo = $this->repositoryManager->getLocalRepository();
     $platformRepo = new PlatformRepository();
     $repos = array($localRepo, new InstalledArrayRepository(array($installedRootPackage)), $platformRepo);
     $installedRepo = new CompositeRepository($repos);
     if ($this->additionalInstalledRepository) {
         $installedRepo->addRepository($this->additionalInstalledRepository);
     }
     $aliases = $this->getRootAliases();
     $this->aliasPlatformPackages($platformRepo, $aliases);
     try {
         $this->suggestedPackages = array();
         $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
         if ($res !== 0) {
             return $res;
         }
     } catch (\Exception $e) {
         $this->installationManager->notifyInstalls();
         throw $e;
     }
     $this->installationManager->notifyInstalls();
     // output suggestions if we're in dev mode
     if ($this->devMode) {
         foreach ($this->suggestedPackages as $suggestion) {
             $target = $suggestion['target'];
             foreach ($installedRepo->getPackages() as $package) {
                 if (in_array($target, $package->getNames())) {
                     continue 2;
                 }
             }
             $this->io->writeError($suggestion['source'] . ' suggests installing ' . $suggestion['target'] . ' (' . $suggestion['reason'] . ')');
         }
     }
     # Find abandoned packages and warn user
     foreach ($localRepo->getPackages() as $package) {
         if (!$package instanceof CompletePackage || !$package->isAbandoned()) {
             continue;
         }
         $replacement = is_string($package->getReplacementPackage()) ? 'Use ' . $package->getReplacementPackage() . ' instead' : 'No replacement was suggested';
         $this->io->writeError(sprintf("<error>Package %s is abandoned, you should avoid using it. %s.</error>", $package->getPrettyName(), $replacement));
     }
     if (!$this->dryRun) {
         // write lock
         if ($this->update || !$this->locker->isLocked()) {
             $localRepo->reload();
             // if this is not run in dev mode and the root has dev requires, the lock must
             // contain null to prevent dev installs from a non-dev lock
             $devPackages = $this->devMode || !$this->package->getDevRequires() ? array() : null;
             // split dev and non-dev requirements by checking what would be removed if we update without the dev requirements
             if ($this->devMode && $this->package->getDevRequires()) {
                 $policy = $this->createPolicy();
                 $pool = $this->createPool(true);
                 $pool->addRepository($installedRepo, $aliases);
                 // creating requirements request
                 $request = $this->createRequest($pool, $this->package, $platformRepo);
                 $request->updateAll();
                 foreach ($this->package->getRequires() as $link) {
                     $request->install($link->getTarget(), $link->getConstraint());
                 }
                 $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
                 $solver = new Solver($policy, $pool, $installedRepo);
                 $ops = $solver->solve($request, $this->ignorePlatformReqs);
                 $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
                 foreach ($ops as $op) {
                     if ($op->getJobType() === 'uninstall') {
                         $devPackages[] = $op->getPackage();
                     }
                 }
             }
             $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
             $platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();
             $updatedLock = $this->locker->setLockData(array_diff($localRepo->getCanonicalPackages(), (array) $devPackages), $devPackages, $platformReqs, $platformDevReqs, $aliases, $this->package->getMinimumStability(), $this->package->getStabilityFlags(), $this->preferStable || $this->package->getPreferStable(), $this->preferLowest);
             if ($updatedLock) {
                 $this->io->writeError('<info>Writing lock file</info>');
             }
         }
         if ($this->dumpAutoloader) {
             // write autoloader
             if ($this->optimizeAutoloader) {
                 $this->io->writeError('<info>Generating optimized autoload files</info>');
             } else {
                 $this->io->writeError('<info>Generating autoload files</info>');
             }
             $this->autoloadGenerator->setDevMode($this->devMode);
             $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
         }
         if ($this->runScripts) {
             // dispatch post event
             $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
             $this->eventDispatcher->dispatchScript($eventName, $this->devMode);
         }
         $vendorDir = $this->config->get('vendor-dir');
         if (is_dir($vendorDir)) {
             touch($vendorDir);
         }
     }
     return 0;
 }
예제 #6
0
 /**
  * Run installation (or update)
  */
 public function run()
 {
     if ($this->dryRun) {
         $this->verbose = true;
         $this->runScripts = false;
         $this->installationManager->addInstaller(new NoopInstaller());
         $this->mockLocalRepositories($this->repositoryManager);
     }
     // TODO remove this BC feature at some point
     // purge old require-dev packages to avoid conflicts with the new way of handling dev requirements
     $devRepo = new InstalledFilesystemRepository(new JsonFile($this->config->get('vendor-dir') . '/composer/installed_dev.json'));
     if ($devRepo->getPackages()) {
         $this->io->write('<warning>BC Notice: Removing old dev packages to migrate to the new require-dev handling.</warning>');
         foreach ($devRepo->getPackages() as $package) {
             if ($this->installationManager->isPackageInstalled($devRepo, $package)) {
                 $this->installationManager->uninstall($devRepo, new UninstallOperation($package));
             }
         }
         unlink($this->config->get('vendor-dir') . '/composer/installed_dev.json');
     }
     unset($devRepo, $package);
     // end BC
     if ($this->preferSource) {
         $this->downloadManager->setPreferSource(true);
     }
     if ($this->preferDist) {
         $this->downloadManager->setPreferDist(true);
     }
     // create installed repo, this contains all local packages + platform packages (php & extensions)
     $installedRootPackage = clone $this->package;
     $installedRootPackage->setRequires(array());
     $installedRootPackage->setDevRequires(array());
     $localRepo = $this->repositoryManager->getLocalRepository();
     $platformRepo = new PlatformRepository();
     $repos = array($localRepo, new InstalledArrayRepository(array($installedRootPackage)), $platformRepo);
     $installedRepo = new CompositeRepository($repos);
     if ($this->additionalInstalledRepository) {
         $installedRepo->addRepository($this->additionalInstalledRepository);
     }
     $aliases = $this->getRootAliases();
     $this->aliasPlatformPackages($platformRepo, $aliases);
     if ($this->runScripts) {
         // dispatch pre event
         $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
         $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
     }
     try {
         $this->suggestedPackages = array();
         if (!$this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode)) {
             return false;
         }
     } catch (\Exception $e) {
         $this->installationManager->notifyInstalls();
         throw $e;
     }
     $this->installationManager->notifyInstalls();
     // output suggestions
     foreach ($this->suggestedPackages as $suggestion) {
         $target = $suggestion['target'];
         foreach ($installedRepo->getPackages() as $package) {
             if (in_array($target, $package->getNames())) {
                 continue 2;
             }
         }
         $this->io->write($suggestion['source'] . ' suggests installing ' . $suggestion['target'] . ' (' . $suggestion['reason'] . ')');
     }
     if (!$this->dryRun) {
         // write lock
         if ($this->update || !$this->locker->isLocked()) {
             $localRepo->reload();
             // if this is not run in dev mode and the root has dev requires, the lock must
             // contain null to prevent dev installs from a non-dev lock
             $devPackages = $this->devMode || !$this->package->getDevRequires() ? array() : null;
             // split dev and non-dev requirements by checking what would be removed if we update without the dev requirements
             if ($this->devMode && $this->package->getDevRequires()) {
                 $policy = $this->createPolicy();
                 $pool = $this->createPool();
                 $pool->addRepository($installedRepo, $aliases);
                 // creating requirements request
                 $request = $this->createRequest($pool, $this->package, $platformRepo);
                 $request->updateAll();
                 foreach ($this->package->getRequires() as $link) {
                     $request->install($link->getTarget(), $link->getConstraint());
                 }
                 $solver = new Solver($policy, $pool, $installedRepo);
                 $ops = $solver->solve($request);
                 foreach ($ops as $op) {
                     if ($op->getJobType() === 'uninstall') {
                         $devPackages[] = $op->getPackage();
                     }
                 }
             }
             $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
             $platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();
             $updatedLock = $this->locker->setLockData(array_diff($localRepo->getPackages(), (array) $devPackages), $devPackages, $platformReqs, $platformDevReqs, $aliases, $this->package->getMinimumStability(), $this->package->getStabilityFlags());
             if ($updatedLock) {
                 $this->io->write('<info>Writing lock file</info>');
             }
         }
         // write autoloader
         $this->io->write('<info>Generating autoload files</info>');
         $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
         if ($this->runScripts) {
             // dispatch post event
             $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
             $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
         }
     }
     return true;
 }
예제 #7
0
 public function getCurrentDistributionCommit()
 {
     $repo = new InstalledFilesystemRepository(new JsonFile($this->installedRepoFile));
     $distrib = $repo->findPackage('claroline/distribution', '*');
     return $distrib->getSourceReference();
 }
예제 #8
0
 /**
  * @param string $repoFile
  * @param bool   $filter
  *
  * @return InstalledFilesystemRepository
  */
 private function openRepository($repoFile, $filter = true)
 {
     $json = new JsonFile($repoFile);
     if (!$json->exists()) {
         throw new \RuntimeException("Repository file '{$repoFile}' doesn't exist", 123);
     }
     $repo = new InstalledFilesystemRepository($json);
     if ($filter) {
         foreach ($repo->getPackages() as $package) {
             if ($package->getType() !== 'claroline-core' && $package->getType() !== 'claroline-plugin') {
                 $repo->removePackage($package);
             }
         }
     }
     return $repo;
 }
예제 #9
0
 public function run()
 {
     if ($this->dryRun) {
         $this->verbose = true;
         $this->runScripts = false;
         $this->installationManager->addInstaller(new NoopInstaller());
         $this->mockLocalRepositories($this->repositoryManager);
     }
     $devRepo = new InstalledFilesystemRepository(new JsonFile($this->config->get('vendor-dir') . '/composer/installed_dev.json'));
     if ($devRepo->getPackages()) {
         $this->io->write('<warning>BC Notice: Removing old dev packages to migrate to the new require-dev handling.</warning>');
         foreach ($devRepo->getPackages() as $package) {
             if ($this->installationManager->isPackageInstalled($devRepo, $package)) {
                 $this->installationManager->uninstall($devRepo, new UninstallOperation($package));
             }
         }
         unlink($this->config->get('vendor-dir') . '/composer/installed_dev.json');
     }
     unset($devRepo, $package);
     if ($this->runScripts) {
         $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
         $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
     }
     $this->downloadManager->setPreferSource($this->preferSource);
     $this->downloadManager->setPreferDist($this->preferDist);
     $installedRootPackage = clone $this->package;
     $installedRootPackage->setRequires(array());
     $installedRootPackage->setDevRequires(array());
     $localRepo = $this->repositoryManager->getLocalRepository();
     $platformRepo = new PlatformRepository();
     $repos = array($localRepo, new InstalledArrayRepository(array($installedRootPackage)), $platformRepo);
     $installedRepo = new CompositeRepository($repos);
     if ($this->additionalInstalledRepository) {
         $installedRepo->addRepository($this->additionalInstalledRepository);
     }
     $aliases = $this->getRootAliases();
     $this->aliasPlatformPackages($platformRepo, $aliases);
     try {
         $this->suggestedPackages = array();
         $res = $this->doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $this->devMode);
         if ($res !== 0) {
             return $res;
         }
     } catch (\Exception $e) {
         $this->installationManager->notifyInstalls();
         throw $e;
     }
     $this->installationManager->notifyInstalls();
     foreach ($this->suggestedPackages as $suggestion) {
         $target = $suggestion['target'];
         foreach ($installedRepo->getPackages() as $package) {
             if (in_array($target, $package->getNames())) {
                 continue 2;
             }
         }
         $this->io->write($suggestion['source'] . ' suggests installing ' . $suggestion['target'] . ' (' . $suggestion['reason'] . ')');
     }
     if (!$this->dryRun) {
         if ($this->update || !$this->locker->isLocked()) {
             $localRepo->reload();
             $devPackages = $this->devMode || !$this->package->getDevRequires() ? array() : null;
             if ($this->devMode && $this->package->getDevRequires()) {
                 $policy = $this->createPolicy();
                 $pool = $this->createPool(true);
                 $pool->addRepository($installedRepo, $aliases);
                 $request = $this->createRequest($pool, $this->package, $platformRepo);
                 $request->updateAll();
                 foreach ($this->package->getRequires() as $link) {
                     $request->install($link->getTarget(), $link->getConstraint());
                 }
                 $solver = new Solver($policy, $pool, $installedRepo);
                 $ops = $solver->solve($request);
                 foreach ($ops as $op) {
                     if ($op->getJobType() === 'uninstall') {
                         $devPackages[] = $op->getPackage();
                     }
                 }
             }
             $platformReqs = $this->extractPlatformRequirements($this->package->getRequires());
             $platformDevReqs = $this->devMode ? $this->extractPlatformRequirements($this->package->getDevRequires()) : array();
             $updatedLock = $this->locker->setLockData(array_diff($localRepo->getCanonicalPackages(), (array) $devPackages), $devPackages, $platformReqs, $platformDevReqs, $aliases, $this->package->getMinimumStability(), $this->package->getStabilityFlags());
             if ($updatedLock) {
                 $this->io->write('<info>Writing lock file</info>');
             }
         }
         if ($this->optimizeAutoloader) {
             $this->io->write('<info>Generating optimized autoload files</info>');
         } else {
             $this->io->write('<info>Generating autoload files</info>');
         }
         $this->autoloadGenerator->dump($this->config, $localRepo, $this->package, $this->installationManager, 'composer', $this->optimizeAutoloader);
         if ($this->runScripts) {
             $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
             $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
         }
     }
     return 0;
 }
예제 #10
0
 public function testExecuteCallsInstallersAndUpdatePreviousRepo()
 {
     vfsStream::setup('root');
     $previous = vfsStream::url('root/previous-installed.json');
     file_put_contents($previous, file_get_contents($this->repo('repo-1')));
     $this->executor->setRepositoryFiles($previous, '/does/not/exist');
     $this->kernel->expects($this->once())->method('getBundles')->willReturn([$this->mockBundle('Foo'), $this->mockBundle('Quz', true), $this->mockBundle('Bar', true)]);
     $this->baseInstaller->expects($this->once())->method('install')->will($this->throwException(new \Exception('from test')));
     $installOp1 = new Operation(Operation::INSTALL, $this->package('quz', '3.4.1.2', 'claroline-plugin'), 'Quz');
     $updateOp = new Operation(Operation::UPDATE, $this->package('bar', '2.0.0.0', 'claroline-plugin'), 'Bar');
     $updateOp->setFromVersion('2.0.0.0');
     $updateOp->setToVersion('3.0.0.0');
     $installOp2 = new Operation(Operation::INSTALL, $this->package('foo', '5.2.3.1', 'claroline-core'), 'Foo');
     try {
         $this->executor->execute([$installOp1, $updateOp, $installOp2]);
         $this->fail('An exception should have been thrown');
     } catch (\Exception $ex) {
         $this->assertTrue(file_exists($previous));
         $repo = new InstalledFilesystemRepository(new JsonFile($previous));
         $this->assertNotNull($repo->findPackage('quz', '3.4.1.2'));
         $this->assertNotNull($repo->findPackage('bar', '2.0.0.0'));
     }
 }
예제 #11
0
 /**
  * Get module packs
  *
  * @param   bool $clear (optional)
  *
  * @return  CompletePackage[]
  */
 public function getPackages(bool $clear = false) : array
 {
     if (!$clear && $this->packages !== null) {
         return $this->packages;
     }
     $packages = array();
     $repository = new InstalledFilesystemRepository(new JsonFile($this->info->vendorDir() . '/composer/installed.json'));
     foreach ($repository->getCanonicalPackages() as $package) {
         if (!$package instanceof CompletePackage || $package->getType() !== static::COMPOSER_TYPE) {
             continue;
         }
         $packages[$package->getName()] = $package;
     }
     return $this->packages = $packages;
 }