private function getMediaWikiVersionConstraint() { $mvVersion = $this->versionFetcher->fetchVersion(); $mvVersion = $this->versionNormalizer->normalizeSuffix($mvVersion); $version = new VersionConstraint('==', $this->versionNormalizer->normalizeLevelCount($mvVersion)); $version->setPrettyString($mvVersion); return $version; }
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator) { if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) { return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB]; } $constraint = new VersionConstraint($operator, $b->getVersion()); $version = new VersionConstraint('==', $a->getVersion()); return $constraint->matchSpecific($version, true); }
public function testComparableBranches() { $versionRequire = new VersionConstraint('>', '0.12'); $versionProvide = new VersionConstraint('==', 'dev-foo'); $this->assertFalse($versionRequire->matches($versionProvide)); $this->assertFalse($versionRequire->matchSpecific($versionProvide, true)); $versionRequire = new VersionConstraint('<', '0.12'); $versionProvide = new VersionConstraint('==', 'dev-foo'); $this->assertFalse($versionRequire->matches($versionProvide)); $this->assertTrue($versionRequire->matchSpecific($versionProvide, true)); }
protected function getVersionConstraint($operator, $version) { $constraint = new VersionConstraint( $operator, self::getVersionParser()->normalize($version) ); $constraint->setPrettyString($operator.' '.$version); return $constraint; }
/** * Compares two versions and returns 0 if $a == $b, -1 if $a < $b and +1 if $b > $a. * * @param AddonVersion * @param AddonVersion * @return int */ public function compare(AddonVersion $a, AddonVersion $b) { $parser = $this->getParser(); $a = $parser->normalize($a->version); $b = $parser->normalize($b->version); $constraint = new VersionConstraint(NULL, NULL); if ($constraint->versionCompare($a, $b, '==')) { return 0; } elseif ($constraint->versionCompare($a, $b, '<')) { return -1; } else { return 1; } }
/** * @dataProvider failingVersionMatches */ public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion) { $versionRequire = new VersionConstraint($requireOperator, $requireVersion); $versionProvide = new VersionConstraint($provideOperator, $provideVersion); $this->assertFalse($versionRequire->matches($versionProvide)); }
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; }
private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo) { $request = new Request($pool); $constraint = new VersionConstraint('=', $rootPackage->getVersion()); $constraint->setPrettyString($rootPackage->getPrettyVersion()); $request->install($rootPackage->getName(), $constraint); $fixedPackages = $platformRepo->getPackages(); if ($this->additionalInstalledRepository) { $additionalFixedPackages = $this->additionalInstalledRepository->getPackages(); $fixedPackages = array_merge($fixedPackages, $additionalFixedPackages); } // fix the version of all platform packages + additionally installed packages // to prevent the solver trying to remove or update those $provided = $rootPackage->getProvides(); foreach ($fixedPackages as $package) { $constraint = new VersionConstraint('=', $package->getVersion()); $constraint->setPrettyString($package->getPrettyVersion()); // skip platform packages that are provided by the root package if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) { $request->fix($package->getName(), $constraint); } } return $request; }
private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo) { $request = new Request($pool); $constraint = new VersionConstraint('=', $rootPackage->getVersion()); $constraint->setPrettyString($rootPackage->getPrettyVersion()); $request->install($rootPackage->getName(), $constraint); // fix the version of all platform packages to prevent the solver trying to remove those foreach ($platformRepo->getPackages() as $package) { $constraint = new VersionConstraint('=', $package->getVersion()); $constraint->setPrettyString($package->getPrettyVersion()); if (!($provided = $rootPackage->getProvides()) || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) { $request->install($package->getName(), $constraint); } } return $request; }
/** * Search for packages. * * @param array $tokens * @param int $searchIn * * @return CompletePackageInterface[] */ protected function searchPackages(array $tokens, $searchIn) { $repositoryManager = $this->getRepositoryManager(); $platformRepo = new PlatformRepository(); $localRepository = $repositoryManager->getLocalRepository(); $installedRepository = new CompositeRepository(array($localRepository, $platformRepo)); $repositories = new CompositeRepository(array_merge(array($installedRepository), $repositoryManager->getRepositories())); /* $localRepository = $this->composer ->getRepositoryManager() ->getLocalRepository(); $platformRepository = new PlatformRepository(); $installedRepositories = new CompositeRepository( array( $localRepository, $platformRepository ) ); $repositories = array_merge( array($installedRepositories), $this->composer ->getRepositoryManager() ->getRepositories() ); $repositories = new CompositeRepository($repositories); */ $results = $repositories->search(implode(' ', $tokens), $searchIn); $contaoVersion = VERSION . (is_numeric(BUILD) ? '.' . BUILD : '-' . BUILD); $constraint = new VersionConstraint('=', $contaoVersion); $constraint->setPrettyString($contaoVersion); $packages = array(); foreach ($results as $result) { if (!isset($packages[$result['name']])) { /** @var PackageInterface[] $versions */ $versions = $repositories->findPackages($result['name']); /** @var PackageInterface|CompletePackageInterface $latestVersion */ $latestVersion = false; $packages[$result['name']] = $result; if (count($versions)) { $packages[$result['name']]['type'] = $versions[0]->getType(); $packages[$result['name']]['description'] = $versions[0] instanceof CompletePackageInterface ? $versions[0]->getDescription() : ''; $packages[$result['name']]['contao-compatible'] = null; foreach ($versions as $version) { $requires = $version->getRequires(); if (isset($requires['contao/core']) && $requires['contao/core'] instanceof Link) { /** @var Link $link */ $link = $requires['contao/core']; if ($link->getConstraint()->matches($constraint)) { $packages[$result['name']]['contao-compatible'] = true; if (!$latestVersion || $version->getReleaseDate() > $latestVersion->getReleaseDate()) { $latestVersion = $version; } } } } } if ($packages[$result['name']]['contao-compatible'] === null) { $packages[$result['name']]['contao-compatible'] = true; } if ($latestVersion) { $packages[$result['name']]['type'] = $latestVersion->getType(); if ($latestVersion instanceof CompletePackageInterface) { $packages[$result['name']]['description'] = $latestVersion->getDescription(); } } } } return $packages; }
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator) { $constraint = new VersionConstraint($operator, $b->getVersion()); $version = new VersionConstraint('==', $a->getVersion()); return $constraint->matchSpecific($version); }
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.LongVariable) */ public function handle(\Input $input) { $packageName = $input->get('solve'); $version = base64_decode(rawurldecode($input->get('version'))); if ($input->post('mark') || $input->post('install')) { // make a backup copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~'); // update requires $json = new JsonFile(TL_ROOT . '/' . $this->configPathname); $config = $json->read(); if (!array_key_exists('require', $config)) { $config['require'] = array(); } $config['require'][$packageName] = $version; $json->write($config); $_SESSION['TL_INFO'][] = sprintf($GLOBALS['TL_LANG']['composer_client']['added_candidate'], $packageName, $version); $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput(); if ($input->post('install')) { $this->redirect('contao/main.php?do=composer&update=packages'); } $this->redirect('contao/main.php?do=composer'); } /** @var RootPackage $rootPackage */ $rootPackage = $this->composer->getPackage(); $installedRootPackage = clone $rootPackage; $installedRootPackage->setRequires(array()); $installedRootPackage->setDevRequires(array()); $repositoryManager = $this->getRepositoryManager(); $localRepository = $repositoryManager->getLocalRepository(); $platformRepo = new PlatformRepository(); $installedRepository = new CompositeRepository(array($localRepository, new InstalledArrayRepository(array($installedRootPackage)), $platformRepo)); $versionParser = new VersionParser(); $constraint = $versionParser->parseConstraints($version); $stability = $versionParser->parseStability($version); $aliases = $this->getRootAliases($rootPackage); $this->aliasPlatformPackages($platformRepo, $aliases); $stabilityFlags = $rootPackage->getStabilityFlags(); $stabilityFlags[$packageName] = BasePackage::$stabilities[$stability]; $pool = $this->getPool($rootPackage->getMinimumStability(), $stabilityFlags); $pool->addRepository($installedRepository, $aliases); $policy = new DefaultPolicy($rootPackage->getPreferStable()); $request = new Request($pool); // add root package $rootPackageConstraint = new VersionConstraint('=', $rootPackage->getVersion()); $rootPackageConstraint->setPrettyString($rootPackage->getPrettyVersion()); $request->install($rootPackage->getName(), $rootPackageConstraint); // add requirements $links = $rootPackage->getRequires(); /** @var Link $link */ foreach ($links as $link) { if ($link->getTarget() != $packageName) { $request->install($link->getTarget(), $link->getConstraint()); } } /** @var PackageInterface $package */ foreach ($installedRepository->getPackages() as $package) { $request->install($package->getName(), new VersionConstraint('=', $package->getVersion())); } $operations = array(); try { $solver = new Solver($policy, $pool, $installedRepository); $beforeOperations = $solver->solve($request); $request->install($packageName, $constraint); $operations = $solver->solve($request); /** @var \Composer\DependencyResolver\Operation\SolverOperation $beforeOperation */ foreach ($beforeOperations as $beforeOperation) { /** @var \Composer\DependencyResolver\Operation\InstallOperation $operation */ foreach ($operations as $index => $operation) { if ($operation->getPackage()->getName() != $packageName && $beforeOperation->__toString() == $operation->__toString()) { unset($operations[$index]); } } } } catch (SolverProblemsException $e) { $_SESSION['TL_ERROR'][] = sprintf('<span style="white-space: pre-line">%s</span>', trim($e->getMessage())); } $template = new \BackendTemplate('be_composer_client_solve'); $template->composer = $this->composer; $template->packageName = $packageName; $template->packageVersion = $version; $template->operations = $operations; return $template->parse(); }
private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo) { $request = new Request($pool); $constraint = new VersionConstraint('=', $rootPackage->getVersion()); $constraint->setPrettyString($rootPackage->getPrettyVersion()); $request->install($rootPackage->getName(), $constraint); $fixedPackages = $platformRepo->getPackages(); if ($this->additionalInstalledRepository) { $additionalFixedPackages = $this->additionalInstalledRepository->getPackages(); $fixedPackages = array_merge($fixedPackages, $additionalFixedPackages); } $provided = $rootPackage->getProvides(); foreach ($fixedPackages as $package) { $constraint = new VersionConstraint('=', $package->getVersion()); $constraint->setPrettyString($package->getPrettyVersion()); if ($package->getRepository() !== $platformRepo || !isset($provided[$package->getName()]) || !$provided[$package->getName()]->getConstraint()->matches($constraint)) { $request->install($package->getName(), $constraint); } } return $request; }
private function createConstraint($operator, $version) { $constraint = new VersionConstraint($operator, $version); $constraint->setPrettyString($operator . ' ' . $version); return $constraint; }
/** * Check version requirements from the "extra" block of a package * against the local Roundcube version */ private function rcubeVersionCheck($package) { $parser = new VersionParser(); // read rcube version from iniset $rootdir = getcwd(); $iniset = @file_get_contents($rootdir . '/program/include/iniset.php'); if (preg_match('/define\\(.RCMAIL_VERSION.,\\s*.([0-9.]+[a-z-]*)?/', $iniset, $m)) { $rcubeVersion = $parser->normalize(str_replace('-git', '.999', $m[1])); } else { throw new \Exception("Unable to find a Roundcube installation in {$rootdir}"); } $extra = $package->getExtra(); if (!empty($extra['roundcube'])) { foreach (array('min-version' => '>=', 'max-version' => '<=') as $key => $operator) { if (!empty($extra['roundcube'][$key])) { $version = $parser->normalize(str_replace('-git', '.999', $extra['roundcube'][$key])); $constraint = new VersionConstraint($operator, $version); if (!$constraint->versionCompare($rcubeVersion, $version, $operator)) { throw new \Exception("Version check failed! " . $package->getName() . " requires Roundcube version {$operator} {$version}, {$rcubeVersion} was detected."); } } } } }
public function compareVersion($a, $b) { $constraint = new VersionConstraint('>', ''); return $constraint->versionCompare($this->parser->normalize($a['version']), $this->parser->normalize($b['version']), '<', true); }