diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index e27976a4b..a9ed4722a 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -130,7 +130,7 @@ class Factory protected function addLocalRepository(RepositoryManager $rm, $vendorDir) { - $rm->setLocalRepository(new Repository\FilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json'))); + $rm->setLocalRepository(new Repository\InstalledFilesystemRepository(new JsonFile($vendorDir.'/.composer/installed.json'))); } protected function addPackagistRepository(RepositoryManager $rm) diff --git a/src/Composer/Installer/InstallationManager.php b/src/Composer/Installer/InstallationManager.php index 6500e6b00..68355f72c 100644 --- a/src/Composer/Installer/InstallationManager.php +++ b/src/Composer/Installer/InstallationManager.php @@ -127,6 +127,7 @@ class InstallationManager $package = $operation->getPackage(); if ($package instanceof AliasPackage) { $package = $package->getAliasOf(); + $package->setInstalledAsAlias(true); } $installer = $this->getInstaller($package->getType()); $installer->install($package); @@ -146,6 +147,7 @@ class InstallationManager $target = $operation->getTargetPackage(); if ($target instanceof AliasPackage) { $target = $target->getAliasOf(); + $target->setInstalledAsAlias(true); } $initialType = $initial->getType(); diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 4062d7f8d..188d55c5c 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -43,11 +43,6 @@ class ArrayDumper $data['version'] = $package->getPrettyVersion(); $data['version_normalized'] = $package->getVersion(); - if ($package->getAlias()) { - $data['alias'] = $package->getPrettyAlias(); - $data['alias_normalized'] = $package->getAlias(); - } - if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 7c8778af2..001fa2e25 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -134,10 +134,28 @@ class ArrayLoader $package->setDistSha1Checksum(isset($config['dist']['shasum']) ? $config['dist']['shasum'] : null); } - // load alias for named dev packages - if (!empty($config['alias']) && 'dev-' === substr($package->getPrettyVersion(), 0, 4)) { - $package->setAlias($config['alias_normalized']); - $package->setPrettyAlias($config['alias']); + // check for a branch alias (dev-master => 1.0.x-dev for example) if this is a named branch + if ('dev-' === substr($package->getPrettyVersion(), 0, 4) && isset($config['extra']['branch-alias']) && is_array($config['extra']['branch-alias'])) { + foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) { + // ensure it is an alias to a -dev package + if ('-dev' !== substr($targetBranch, -4)) { + continue; + } + // normalize without -dev and ensure it's a numeric branch that is parseable + $validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4)); + if ('-dev' !== substr($validatedTargetBranch, -4)) { + continue; + } + + // ensure that it is the current branch aliasing itself + if (strtolower($package->getPrettyVersion()) !== strtolower($sourceBranch)) { + continue; + } + + $package->setAlias($validatedTargetBranch); + $package->setPrettyAlias($targetBranch); + break; + } } foreach (Package\BasePackage::$supportedLinkTypes as $type => $description) { diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index db47ce35e..b4df22f21 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -139,8 +139,7 @@ class Locker if ($package->isDev()) { $spec['source-reference'] = $package->getSourceReference(); } - // TODO discriminate between really installed as alias and installed as real package - if ($package->getAlias()) { + if ($package->getAlias() && $package->isInstalledAsAlias()) { $spec['alias'] = $package->getAlias(); } diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index 6a38093a3..e266f754c 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -44,6 +44,7 @@ class MemoryPackage extends BasePackage protected $aliases = array(); protected $alias; protected $prettyAlias; + protected $installedAsAlias; protected $dev; protected $requires = array(); @@ -207,6 +208,24 @@ class MemoryPackage extends BasePackage return $this->prettyAlias; } + /** + * Enabled if the package is installed from its alias package + * + * @param string $installedAsAlias + */ + public function setInstalledAsAlias($installedAsAlias) + { + $this->installedAsAlias = $installedAsAlias; + } + + /** + * @return string + */ + public function isInstalledAsAlias() + { + return $this->installedAsAlias; + } + /** * {@inheritDoc} */ diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 9dfde50fe..515f89ea9 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -95,6 +95,11 @@ class ArrayRepository implements RepositoryInterface } $package->setRepository($this); $this->packages[] = $package; + + // create alias package on the fly if needed (installed repos manage aliases themselves) + if ($package->getAlias() && !$this instanceof InstalledRepositoryInterface) { + $this->addPackage($this->createAliasPackage($package)); + } } protected function createAliasPackage(PackageInterface $package) diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index 6e74e3fe6..e17134b42 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -54,12 +54,15 @@ class FilesystemRepository extends ArrayRepository implements WritableRepository } $loader = new ArrayLoader(); - foreach ($packages as $package) { - $package = $loader->load($package); - // TODO discriminate between really installed as alias and installed as real package - if ($package->getAlias()) { + foreach ($packages as $packageData) { + $package = $loader->load($packageData); + + // package was installed as alias, so we only add the alias + if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) { + $package->setInstalledAsAlias(true); $this->addPackage($this->createAliasPackage($package)); } else { + // only add regular package - if it's not an installed repo the alias will be created on the fly $this->addPackage($package); } } @@ -73,7 +76,11 @@ class FilesystemRepository extends ArrayRepository implements WritableRepository $packages = array(); $dumper = new ArrayDumper(); foreach ($this->getPackages() as $package) { - $packages[] = $dumper->dump($package); + $data = $dumper->dump($package); + if ($this instanceof InstalledRepositoryInterface && $package->isInstalledAsAlias()) { + $data['installed-as-alias'] = true; + } + $packages[] = $data; } $this->file->write($packages); diff --git a/src/Composer/Repository/InstalledFilesystemRepository.php b/src/Composer/Repository/InstalledFilesystemRepository.php new file mode 100644 index 000000000..7bb70d666 --- /dev/null +++ b/src/Composer/Repository/InstalledFilesystemRepository.php @@ -0,0 +1,27 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Repository; + +use Composer\Json\JsonFile; +use Composer\Package\PackageInterface; +use Composer\Package\Loader\ArrayLoader; +use Composer\Package\Dumper\ArrayDumper; + +/** + * Installed filesystem repository. + * + * @author Jordi Boggiano + */ +class InstalledFilesystemRepository extends FilesystemRepository implements InstalledRepositoryInterface +{ +} diff --git a/src/Composer/Repository/InstalledRepositoryInterface.php b/src/Composer/Repository/InstalledRepositoryInterface.php new file mode 100644 index 000000000..de71d23c6 --- /dev/null +++ b/src/Composer/Repository/InstalledRepositoryInterface.php @@ -0,0 +1,26 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Repository; + +use Composer\Package\PackageInterface; + +/** + * Installable repository interface. + * + * Just used to tag installed repositories so the base classes can act differently on Alias packages + * + * @author Jordi Boggiano + */ +interface InstalledRepositoryInterface +{ +} diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 03a78d798..afdc12bcb 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -185,36 +185,9 @@ class VcsRepository extends ArrayRepository $data['source'] = $driver->getSource($identifier); } - // check for a branch alias (dev-master => 1.0.x-dev for example) if this is a named branch - if ('dev-' === substr($data['version'], 0, 4) && isset($data['extra']['branch-alias']) && is_array($data['extra']['branch-alias'])) { - foreach ($data['extra']['branch-alias'] as $sourceBranch => $targetBranch) { - // ensure it is an alias to a numeric branch that is parseable - if (!($validatedTargetBranch = $this->validateBranch($targetBranch)) || '-dev' !== substr($validatedTargetBranch, -4)) { - continue; - } - // ensure that it is the current branch aliasing itself - if ($data['version'] !== $sourceBranch && substr($data['version'], 4) !== $sourceBranch) { - continue; - } - - $data['alias'] = $targetBranch.'-dev'; - $data['alias_normalized'] = $validatedTargetBranch; - break; - } - } - return $data; } - public function addPackage(PackageInterface $package) - { - parent::addPackage($package); - - if ($package->getAlias()) { - $this->addPackage($this->createAliasPackage($package)); - } - } - private function validateBranch($branch) { try {