1
0
Fork 0

Merge remote-tracking branch 'bboer/feature/svn-alternative-structures'

Conflicts:
	src/Composer/Repository/Vcs/GitHubDriver.php
pull/1191/merge
Jordi Boggiano 2012-10-19 12:19:19 +02:00
commit 0a3097c569
6 changed files with 62 additions and 21 deletions

View File

@ -331,7 +331,7 @@ class GitHubDriver extends VcsDriver
// cannot ask for authentication credentials (because we // cannot ask for authentication credentials (because we
// are not interactive) then we fallback to GitDriver. // are not interactive) then we fallback to GitDriver.
$this->gitDriver = new GitDriver( $this->gitDriver = new GitDriver(
$this->generateSshUrl(), array('url' => $this->generateSshUrl()),
$this->io, $this->io,
$this->config, $this->config,
$this->process, $this->process,

View File

@ -32,6 +32,10 @@ class SvnDriver extends VcsDriver
protected $branches; protected $branches;
protected $infoCache = array(); protected $infoCache = array();
protected $trunkPath = 'trunk';
protected $branchesPath = 'branches';
protected $tagsPath = 'tags';
/** /**
* @var \Composer\Util\Svn * @var \Composer\Util\Svn
*/ */
@ -44,7 +48,17 @@ class SvnDriver extends VcsDriver
{ {
$this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
if (false !== ($pos = strrpos($this->url, '/trunk'))) { if (isset($this->repoConfig['trunk-path'])) {
$this->trunkPath = $this->repoConfig['trunk-path'];
}
if (isset($this->repoConfig['branches-path'])) {
$this->branchesPath = $this->repoConfig['branches-path'];
}
if (isset($this->repoConfig['tags-path'])) {
$this->tagsPath = $this->repoConfig['tags-path'];
}
if (false !== ($pos = strrpos($this->url, '/' . $this->trunkPath))) {
$this->baseUrl = substr($this->url, 0, $pos); $this->baseUrl = substr($this->url, 0, $pos);
} }
@ -59,7 +73,7 @@ class SvnDriver extends VcsDriver
*/ */
public function getRootIdentifier() public function getRootIdentifier()
{ {
return 'trunk'; return $this->trunkPath;
} }
/** /**
@ -145,13 +159,14 @@ class SvnDriver extends VcsDriver
if (null === $this->tags) { if (null === $this->tags) {
$this->tags = array(); $this->tags = array();
$output = $this->execute('svn ls --verbose', $this->baseUrl . '/tags'); $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath);
if ($output) { if ($output) {
foreach ($this->process->splitLines($output) as $line) { foreach ($this->process->splitLines($output) as $line) {
$line = trim($line); $line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
$this->tags[rtrim($match[2], '/')] = '/tags/'.$match[2].'@'.$match[1]; $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsPath .
'/' . $match[2] . '@' . $match[1];
} }
} }
} }
@ -174,8 +189,9 @@ class SvnDriver extends VcsDriver
foreach ($this->process->splitLines($output) as $line) { foreach ($this->process->splitLines($output) as $line) {
$line = trim($line); $line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
if (isset($match[1]) && isset($match[2]) && $match[2] === 'trunk/') { if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkPath . '/') {
$this->branches['trunk'] = '/trunk/@'.$match[1]; $this->branches[$this->trunkPath] = '/' . $this->trunkPath .
'/@'.$match[1];
break; break;
} }
} }
@ -183,13 +199,14 @@ class SvnDriver extends VcsDriver
} }
unset($output); unset($output);
$output = $this->execute('svn ls --verbose', $this->baseUrl . '/branches'); $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesPath);
if ($output) { if ($output) {
foreach ($this->process->splitLines(trim($output)) as $line) { foreach ($this->process->splitLines(trim($output)) as $line) {
$line = trim($line); $line = trim($line);
if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) {
if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { if (isset($match[1]) && isset($match[2]) && $match[2] !== './') {
$this->branches[rtrim($match[2], '/')] = '/branches/'.$match[2].'@'.$match[1]; $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesPath .
'/' . $match[2] . '@' . $match[1];
} }
} }
} }

View File

@ -27,6 +27,7 @@ abstract class VcsDriver implements VcsDriverInterface
{ {
protected $url; protected $url;
protected $originUrl; protected $originUrl;
protected $repoConfig;
protected $io; protected $io;
protected $config; protected $config;
protected $process; protected $process;
@ -35,16 +36,17 @@ abstract class VcsDriver implements VcsDriverInterface
/** /**
* Constructor. * Constructor.
* *
* @param string $url The URL * @param array $repoConfig The repository configuration
* @param IOInterface $io The IO instance * @param IOInterface $io The IO instance
* @param Config $config The composer configuration * @param Config $config The composer configuration
* @param ProcessExecutor $process Process instance, injectable for mocking * @param ProcessExecutor $process Process instance, injectable for mocking
* @param callable $remoteFilesystem Remote Filesystem, injectable for mocking * @param callable $remoteFilesystem Remote Filesystem, injectable for mocking
*/ */
final public function __construct($url, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null) final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, $remoteFilesystem = null)
{ {
$this->url = $url; $this->url = $repoConfig['url'];
$this->originUrl = $url; $this->originUrl = $repoConfig['url'];
$this->repoConfig = $repoConfig;
$this->io = $io; $this->io = $io;
$this->config = $config; $this->config = $config;
$this->process = $process ?: new ProcessExecutor; $this->process = $process ?: new ProcessExecutor;

View File

@ -33,6 +33,7 @@ class VcsRepository extends ArrayRepository
protected $versionParser; protected $versionParser;
protected $type; protected $type;
protected $loader; protected $loader;
protected $repoConfig;
public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null)
{ {
@ -50,6 +51,7 @@ class VcsRepository extends ArrayRepository
$this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
$this->verbose = $io->isVerbose(); $this->verbose = $io->isVerbose();
$this->config = $config; $this->config = $config;
$this->repoConfig = $repoConfig;
} }
public function setLoader(LoaderInterface $loader) public function setLoader(LoaderInterface $loader)
@ -61,7 +63,7 @@ class VcsRepository extends ArrayRepository
{ {
if (isset($this->drivers[$this->type])) { if (isset($this->drivers[$this->type])) {
$class = $this->drivers[$this->type]; $class = $this->drivers[$this->type];
$driver = new $class($this->url, $this->io, $this->config); $driver = new $class($this->repoConfig, $this->io, $this->config);
$driver->initialize(); $driver->initialize();
return $driver; return $driver;
@ -69,7 +71,7 @@ class VcsRepository extends ArrayRepository
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->url)) { if ($driver::supports($this->io, $this->url)) {
$driver = new $driver($this->url, $this->io, $this->config); $driver = new $driver($this->repoConfig, $this->io, $this->config);
$driver->initialize(); $driver->initialize();
return $driver; return $driver;
@ -78,7 +80,7 @@ class VcsRepository extends ArrayRepository
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->url, true)) { if ($driver::supports($this->io, $this->url, true)) {
$driver = new $driver($this->url, $this->io, $this->config); $driver = new $driver($this->repoConfig, $this->io, $this->config);
$driver->initialize(); $driver->initialize();
return $driver; return $driver;

View File

@ -85,7 +85,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
$configSource = $this->getMock('Composer\Config\ConfigSourceInterface'); $configSource = $this->getMock('Composer\Config\ConfigSourceInterface');
$this->config->setConfigSource($configSource); $this->config->setConfigSource($configSource);
$gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem); $repoConfig = array(
'url' => $repoUrl,
);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -133,7 +137,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
->will($this->returnValue('{"master_branch": "test_master"}')); ->will($this->returnValue('{"master_branch": "test_master"}'));
$gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem); $repoConfig = array(
'url' => $repoUrl,
);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -191,7 +199,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo'), $this->equalTo(false)) ->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/repos/composer/packagist/commits/feature%2F3.2-foo'), $this->equalTo(false))
->will($this->returnValue('{"commit": {"committer":{ "date": "2012-09-10"}}}')); ->will($this->returnValue('{"commit": {"committer":{ "date": "2012-09-10"}}}'));
$gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem); $repoConfig = array(
'url' => $repoUrl,
);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -279,7 +291,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
->method('splitLines') ->method('splitLines')
->will($this->returnValue(array('* test_master'))); ->will($this->returnValue(array('* test_master')));
$gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem); $repoConfig = array(
'url' => $repoUrl,
);
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $process, $remoteFilesystem);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier());

View File

@ -48,7 +48,11 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase
'home' => sys_get_temp_dir() . '/composer-test', 'home' => sys_get_temp_dir() . '/composer-test',
), ),
)); ));
$svn = new SvnDriver('http://till:secret@corp.svn.local/repo', $console, $config, $process); $repoConfig = array(
'url' => 'http://till:secret@corp.svn.local/repo',
);
$svn = new SvnDriver($repoConfig, $console, $config, $process);
$svn->initialize(); $svn->initialize();
} }