1
0
Fork 0

Add lock file alias support and a bunch of fixes

pull/350/head
Jordi Boggiano 2012-02-21 16:44:49 +01:00
parent f9fc9695e9
commit 59d2b1145c
9 changed files with 70 additions and 21 deletions

View File

@ -107,13 +107,17 @@ EOT
// prepare aliased packages
$aliasRepo = new ArrayRepository;
foreach ($composer->getPackage()->getAliases() as $alias) {
if (!$update && $composer->getLocker()->isLocked()) {
$aliases = $composer->getLocker()->getAliases();
} else {
$aliases = $composer->getPackage()->getAliases();
}
foreach ($aliases as $alias) {
foreach ($repoManager->findPackages($alias['package'], $alias['version']) as $package) {
$aliasRepo->addPackage(new AliasPackage($package, $alias['replaces']));
$aliasRepo->addPackage(new AliasPackage($package, $alias['alias']));
}
foreach ($repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) {
$repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['replaces']));
$repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias']));
$repoManager->getLocalRepository()->removePackage($package);
}
}
@ -137,11 +141,11 @@ EOT
$request = new Request($pool);
if ($update) {
$io->write('<info>Updating dependencies</info>');
$installedPackages = $installedRepo->getPackages();
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
$request->updateAll();
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
foreach ($links as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
@ -154,7 +158,14 @@ EOT
}
foreach ($composer->getLocker()->getLockedPackages() as $package) {
$constraint = new VersionConstraint('=', $package->getVersion());
$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 {
@ -175,14 +186,13 @@ EOT
// solve dependencies
$operations = $solver->solve($request);
// execute operations
if (!$operations) {
$io->write('<info>Nothing to install/update</info>');
}
// 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;
@ -205,6 +215,19 @@ EOT
}
}
// anti-alias local repository to allow updates to work fine
foreach ($repoManager->getLocalRepository()->getPackages() as $package) {
if ($package instanceof AliasPackage) {
$repoManager->getLocalRepository()->addPackage(clone $package->getAliasOf());
$repoManager->getLocalRepository()->removePackage($package);
}
}
// execute operations
if (!$operations) {
$io->write('<info>Nothing to install/update</info>');
}
foreach ($operations as $operation) {
if ($verbose) {
$io->write((string) $operation);
@ -238,7 +261,7 @@ EOT
if (!$dryRun) {
if ($update || !$composer->getLocker()->isLocked()) {
$composer->getLocker()->lockPackages($localRepo->getPackages());
$composer->getLocker()->setLockData($localRepo->getPackages(), $aliases);
$io->write('<info>Writing lock file</info>');
}

View File

@ -13,6 +13,7 @@
namespace Composer\Installer;
use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;

View File

@ -60,6 +60,11 @@ class AliasPackage extends BasePackage
}
}
public function getAliasOf()
{
return $this->aliasOf;
}
/**
* {@inheritDoc}
*/
@ -204,6 +209,10 @@ class AliasPackage extends BasePackage
{
return $this->aliasOf->getReleaseDate();
}
public function getBinaries()
{
return $this->aliasOf->getBinaries();
}
public function getKeywords()
{
return $this->aliasOf->getKeywords();

View File

@ -50,7 +50,7 @@ class RootPackageLoader extends ArrayLoader
$aliases[] = array(
'package' => strtolower($reqName),
'version' => $this->versionParser->normalize($match[1]),
'replaces' => $this->versionParser->normalize($match[2]),
'alias' => $this->versionParser->normalize($match[2]),
);
}
}

View File

@ -91,6 +91,12 @@ class Locker
return $packages;
}
public function getAliases()
{
$lockList = $this->getLockData();
return isset($lockList['aliases']) ? $lockList['aliases'] : array();
}
public function getLockData()
{
if (!$this->isLocked()) {
@ -101,15 +107,17 @@ class Locker
}
/**
* Locks provided packages into lockfile.
* Locks provided data into lockfile.
*
* @param array $packages array of packages
* @param array $aliases array of aliases
*/
public function lockPackages(array $packages)
public function setLockData(array $packages, array $aliases)
{
$lock = array(
'hash' => $this->hash,
'packages' => array(),
'aliases' => $aliases,
);
foreach ($packages as $package) {
$name = $package->getPrettyName();

View File

@ -293,6 +293,13 @@ interface PackageInterface
*/
function getDescription();
/**
* Returns the package binaries
*
* @return string
*/
function getBinaries();
/**
* Returns the package homepage
*

View File

@ -36,7 +36,7 @@ class VersionParser
// ignore aliases and just assume the alias is required instead of the source
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
$version = $match[1];
$version = $match[2];
}
// match master-like branches

View File

@ -114,7 +114,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$locker->getLockedPackages();
}
public function testLockPackages()
public function testSetLockData()
{
$json = $this->createJsonFileMock();
$repo = $this->createRepositoryManagerMock();
@ -151,9 +151,10 @@ class LockerTest extends \PHPUnit_Framework_TestCase
array('package' => 'pkg1', 'version' => '1.0.0-beta'),
array('package' => 'pkg2', 'version' => '0.1.10')
),
'aliases' => array(),
));
$locker->lockPackages(array($package1, $package2));
$locker->setLockData(array($package1, $package2), array());
}
public function testLockBadPackages()
@ -171,7 +172,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('LogicException');
$locker->lockPackages(array($package1));
$locker->setLockData(array($package1), array());
}
public function testIsFresh()

View File

@ -53,7 +53,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
'parses trunk' => array('dev-trunk', '9999999-dev'),
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-foobar'),
'ignores aliases' => array('dev-master as 1.0.0', '9999999-dev'),
'ignores aliases' => array('dev-master as 1.0.0', '1.0.0.0'),
);
}