1
0
Fork 0

Remove persistence of alias data, make abstract branch aliasing and keep it in composer only

pull/359/head
Jordi Boggiano 2012-02-25 02:52:19 +01:00
parent 1bdab5c4c8
commit 0b7ee194c6
11 changed files with 115 additions and 44 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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();
}

View File

@ -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) {

View File

@ -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();
}

View File

@ -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}
*/

View File

@ -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)

View File

@ -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);

View File

@ -0,0 +1,27 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <j.boggiano@seld.be>
*/
class InstalledFilesystemRepository extends FilesystemRepository implements InstalledRepositoryInterface
{
}

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* 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 <j.boggiano@seld.be>
*/
interface InstalledRepositoryInterface
{
}

View File

@ -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 {