Skip to content

Commit

Permalink
Fix VCS Repositories that are not added in Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Oct 1, 2014
1 parent 876b038 commit 18a1dc4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
28 changes: 25 additions & 3 deletions FxpAssetPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
namespace Fxp\Composer\AssetPlugin;

use Composer\Composer;
use Composer\DependencyResolver\Pool;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Installer\InstallerEvent;
use Composer\Installer\InstallerEvents;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use Composer\Repository\RepositoryInterface;
Expand All @@ -39,6 +42,11 @@ class FxpAssetPlugin implements PluginInterface, EventSubscriberInterface
*/
protected $repos = array();

/**
* @var Pool
*/
protected $pool;

/**
* {@inheritdoc}
*/
Expand All @@ -48,6 +56,9 @@ public static function getSubscribedEvents()
AssetEvents::ADD_VCS_REPOSITORIES => array(
array('onAddVcsRepositories', 0),
),
InstallerEvents::PRE_DEPENDENCIES_SOLVING => array(
array('onPreDependenciesSolving', 0),
),
);
}

Expand Down Expand Up @@ -79,10 +90,20 @@ public function onAddVcsRepositories(VcsRepositoryEvent $event)
{
if (null !== $this->composer) {
$rm = $this->composer->getRepositoryManager();
$this->addRepositories($rm, $event->getRepositories());
$this->addRepositories($rm, $event->getRepositories(), $this->pool);
}
}

/**
* Add pool in plugin.
*
* @param InstallerEvent $event
*/
public function onPreDependenciesSolving(InstallerEvent $event)
{
$this->pool = $event->getPool();
}

/**
* Adds asset registry repositories.
*
Expand Down Expand Up @@ -125,19 +146,20 @@ protected function setVcsTypeRepositories(RepositoryManager $rm)
*
* @param RepositoryManager $rm
* @param array $repositories
* @param Pool|null $pool
*
* @throws \UnexpectedValueException When config of repository is not an array
* @throws \UnexpectedValueException When the config of repository has not a type defined
* @throws \UnexpectedValueException When the config of repository has an invalid type
*/
protected function addRepositories(RepositoryManager $rm, array $repositories)
protected function addRepositories(RepositoryManager $rm, array $repositories, Pool $pool = null)
{
foreach ($repositories as $index => $repo) {
$this->validateRepositories($index, $repo);
$name = is_int($index) ? preg_replace('{^https?://}i', '', $repo['url']) : $index;
$name = isset($repo['name']) ? $repo['name'] : $name;

Util::addRepository($rm, $this->repos, $name, $repo);
Util::addRepository($rm, $this->repos, $name, $repo, $pool);
}
}

Expand Down
8 changes: 7 additions & 1 deletion Tests/FxpAssetPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Composer\Composer;
use Composer\Config;
use Composer\Installer\InstallationManager;
use Composer\Installer\InstallerEvent;
use Composer\IO\IOInterface;
use Composer\Repository\RepositoryManager;
use Composer\Util\Filesystem;
Expand Down Expand Up @@ -246,16 +247,21 @@ public function testSubscribeEvents()
->method('getExtra')
->will($this->returnValue(array()));

$this->assertCount(1, $this->plugin->getSubscribedEvents());
$this->assertCount(2, $this->plugin->getSubscribedEvents());
$this->assertCount(0, $this->composer->getRepositoryManager()->getRepositories());

$event = new VcsRepositoryEvent(AssetEvents::ADD_VCS_REPOSITORIES, array(
array('type' => 'npm-vcs', 'url' => 'http://foo.tld'),
));
/* @var InstallerEvent $eventInstaller */
$eventInstaller = $this->getMockBuilder('Composer\Installer\InstallerEvent')
->disableOriginalConstructor()
->getMock();

$this->plugin->activate($this->composer, $this->io);
$this->assertCount(2, $this->composer->getRepositoryManager()->getRepositories());
$this->plugin->onAddVcsRepositories($event);
$this->plugin->onPreDependenciesSolving($eventInstaller);
$this->assertCount(3, $this->composer->getRepositoryManager()->getRepositories());
}

Expand Down

0 comments on commit 18a1dc4

Please sign in to comment.