diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php
index d90b05b07..89dc3aa87 100644
--- a/src/Composer/Command/InstallCommand.php
+++ b/src/Composer/Command/InstallCommand.php
@@ -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('Updating dependencies');
- $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('Nothing to install/update');
- }
-
// 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('Nothing to install/update');
+ }
+
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('Writing lock file');
}
diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php
index d2f0e2a6b..6500e6b00 100644
--- a/src/Composer/Installer/InstallationManager.php
+++ b/src/Composer/Installer/InstallationManager.php
@@ -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;
diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php
index 3665fd30a..02c0a9510 100644
--- a/src/Composer/Package/AliasPackage.php
+++ b/src/Composer/Package/AliasPackage.php
@@ -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();
diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php
index 657ff482c..a6865f01e 100644
--- a/src/Composer/Package/Loader/RootPackageLoader.php
+++ b/src/Composer/Package/Loader/RootPackageLoader.php
@@ -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]),
);
}
}
diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php
index c55c0e467..205372481 100644
--- a/src/Composer/Package/Locker.php
+++ b/src/Composer/Package/Locker.php
@@ -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();
diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php
index 1f19a835f..cf68cc02d 100644
--- a/src/Composer/Package/PackageInterface.php
+++ b/src/Composer/Package/PackageInterface.php
@@ -293,6 +293,13 @@ interface PackageInterface
*/
function getDescription();
+ /**
+ * Returns the package binaries
+ *
+ * @return string
+ */
+ function getBinaries();
+
/**
* Returns the package homepage
*
diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php
index 36a16ae09..19cd240a8 100644
--- a/src/Composer/Package/Version/VersionParser.php
+++ b/src/Composer/Package/Version/VersionParser.php
@@ -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
diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php
index 8feeabeaf..9c3f3cbe0 100644
--- a/tests/Composer/Test/Package/LockerTest.php
+++ b/tests/Composer/Test/Package/LockerTest.php
@@ -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()
diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php
index d7336bd5a..63efbc2f5 100644
--- a/tests/Composer/Test/Package/Version/VersionParserTest.php
+++ b/tests/Composer/Test/Package/Version/VersionParserTest.php
@@ -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'),
);
}