Add lock file alias support and a bunch of fixes
parent
f9fc9695e9
commit
59d2b1145c
|
@ -107,13 +107,17 @@ EOT
|
||||||
|
|
||||||
// prepare aliased packages
|
// prepare aliased packages
|
||||||
$aliasRepo = new ArrayRepository;
|
$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) {
|
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) {
|
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);
|
$repoManager->getLocalRepository()->removePackage($package);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,11 +141,11 @@ EOT
|
||||||
$request = new Request($pool);
|
$request = new Request($pool);
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$io->write('<info>Updating dependencies</info>');
|
$io->write('<info>Updating dependencies</info>');
|
||||||
$installedPackages = $installedRepo->getPackages();
|
|
||||||
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
|
|
||||||
|
|
||||||
$request->updateAll();
|
$request->updateAll();
|
||||||
|
|
||||||
|
$links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
|
||||||
|
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
$request->install($link->getTarget(), $link->getConstraint());
|
$request->install($link->getTarget(), $link->getConstraint());
|
||||||
}
|
}
|
||||||
|
@ -154,7 +158,14 @@ EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($composer->getLocker()->getLockedPackages() as $package) {
|
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);
|
$request->install($package->getName(), $constraint);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -175,14 +186,13 @@ EOT
|
||||||
// solve dependencies
|
// solve dependencies
|
||||||
$operations = $solver->solve($request);
|
$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
|
// force dev packages to be updated to latest reference on update
|
||||||
if ($update) {
|
if ($update) {
|
||||||
foreach ($localRepo->getPackages() as $package) {
|
foreach ($localRepo->getPackages() as $package) {
|
||||||
|
if ($package instanceof AliasPackage) {
|
||||||
|
$package = $package->getAliasOf();
|
||||||
|
}
|
||||||
|
|
||||||
// skip non-dev packages
|
// skip non-dev packages
|
||||||
if (!$package->isDev()) {
|
if (!$package->isDev()) {
|
||||||
continue;
|
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) {
|
foreach ($operations as $operation) {
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
$io->write((string) $operation);
|
$io->write((string) $operation);
|
||||||
|
@ -238,7 +261,7 @@ EOT
|
||||||
|
|
||||||
if (!$dryRun) {
|
if (!$dryRun) {
|
||||||
if ($update || !$composer->getLocker()->isLocked()) {
|
if ($update || !$composer->getLocker()->isLocked()) {
|
||||||
$composer->getLocker()->lockPackages($localRepo->getPackages());
|
$composer->getLocker()->setLockData($localRepo->getPackages(), $aliases);
|
||||||
$io->write('<info>Writing lock file</info>');
|
$io->write('<info>Writing lock file</info>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
namespace Composer\Installer;
|
namespace Composer\Installer;
|
||||||
|
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
|
use Composer\Package\AliasPackage;
|
||||||
use Composer\DependencyResolver\Operation\OperationInterface;
|
use Composer\DependencyResolver\Operation\OperationInterface;
|
||||||
use Composer\DependencyResolver\Operation\InstallOperation;
|
use Composer\DependencyResolver\Operation\InstallOperation;
|
||||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||||
|
|
|
@ -60,6 +60,11 @@ class AliasPackage extends BasePackage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAliasOf()
|
||||||
|
{
|
||||||
|
return $this->aliasOf;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@ -204,6 +209,10 @@ class AliasPackage extends BasePackage
|
||||||
{
|
{
|
||||||
return $this->aliasOf->getReleaseDate();
|
return $this->aliasOf->getReleaseDate();
|
||||||
}
|
}
|
||||||
|
public function getBinaries()
|
||||||
|
{
|
||||||
|
return $this->aliasOf->getBinaries();
|
||||||
|
}
|
||||||
public function getKeywords()
|
public function getKeywords()
|
||||||
{
|
{
|
||||||
return $this->aliasOf->getKeywords();
|
return $this->aliasOf->getKeywords();
|
||||||
|
|
|
@ -50,7 +50,7 @@ class RootPackageLoader extends ArrayLoader
|
||||||
$aliases[] = array(
|
$aliases[] = array(
|
||||||
'package' => strtolower($reqName),
|
'package' => strtolower($reqName),
|
||||||
'version' => $this->versionParser->normalize($match[1]),
|
'version' => $this->versionParser->normalize($match[1]),
|
||||||
'replaces' => $this->versionParser->normalize($match[2]),
|
'alias' => $this->versionParser->normalize($match[2]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,12 @@ class Locker
|
||||||
return $packages;
|
return $packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAliases()
|
||||||
|
{
|
||||||
|
$lockList = $this->getLockData();
|
||||||
|
return isset($lockList['aliases']) ? $lockList['aliases'] : array();
|
||||||
|
}
|
||||||
|
|
||||||
public function getLockData()
|
public function getLockData()
|
||||||
{
|
{
|
||||||
if (!$this->isLocked()) {
|
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 $packages array of packages
|
||||||
|
* @param array $aliases array of aliases
|
||||||
*/
|
*/
|
||||||
public function lockPackages(array $packages)
|
public function setLockData(array $packages, array $aliases)
|
||||||
{
|
{
|
||||||
$lock = array(
|
$lock = array(
|
||||||
'hash' => $this->hash,
|
'hash' => $this->hash,
|
||||||
'packages' => array(),
|
'packages' => array(),
|
||||||
|
'aliases' => $aliases,
|
||||||
);
|
);
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
$name = $package->getPrettyName();
|
$name = $package->getPrettyName();
|
||||||
|
|
|
@ -293,6 +293,13 @@ interface PackageInterface
|
||||||
*/
|
*/
|
||||||
function getDescription();
|
function getDescription();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the package binaries
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getBinaries();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the package homepage
|
* Returns the package homepage
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,7 +36,7 @@ class VersionParser
|
||||||
|
|
||||||
// ignore aliases and just assume the alias is required instead of the source
|
// ignore aliases and just assume the alias is required instead of the source
|
||||||
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
|
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
|
||||||
$version = $match[1];
|
$version = $match[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// match master-like branches
|
// match master-like branches
|
||||||
|
|
|
@ -114,7 +114,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
|
||||||
$locker->getLockedPackages();
|
$locker->getLockedPackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLockPackages()
|
public function testSetLockData()
|
||||||
{
|
{
|
||||||
$json = $this->createJsonFileMock();
|
$json = $this->createJsonFileMock();
|
||||||
$repo = $this->createRepositoryManagerMock();
|
$repo = $this->createRepositoryManagerMock();
|
||||||
|
@ -151,9 +151,10 @@ class LockerTest extends \PHPUnit_Framework_TestCase
|
||||||
array('package' => 'pkg1', 'version' => '1.0.0-beta'),
|
array('package' => 'pkg1', 'version' => '1.0.0-beta'),
|
||||||
array('package' => 'pkg2', 'version' => '0.1.10')
|
array('package' => 'pkg2', 'version' => '0.1.10')
|
||||||
),
|
),
|
||||||
|
'aliases' => array(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$locker->lockPackages(array($package1, $package2));
|
$locker->setLockData(array($package1, $package2), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLockBadPackages()
|
public function testLockBadPackages()
|
||||||
|
@ -171,7 +172,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$this->setExpectedException('LogicException');
|
$this->setExpectedException('LogicException');
|
||||||
|
|
||||||
$locker->lockPackages(array($package1));
|
$locker->setLockData(array($package1), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsFresh()
|
public function testIsFresh()
|
||||||
|
|
|
@ -53,7 +53,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
'parses trunk' => array('dev-trunk', '9999999-dev'),
|
'parses trunk' => array('dev-trunk', '9999999-dev'),
|
||||||
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
|
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
|
||||||
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-foobar'),
|
'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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue