From 93628c42d84bf967a7dc5b341d2e7be85eb12f5a Mon Sep 17 00:00:00 2001 From: bboer Date: Wed, 29 Aug 2012 13:26:53 +0200 Subject: [PATCH 1/3] Add support for alternative structures --- src/Composer/Repository/Vcs/SvnDriver.php | 33 +++++++++++++++++------ src/Composer/Repository/VcsRepository.php | 3 +++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index a933d7df5..a2a4e468c 100755 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -32,6 +32,10 @@ class SvnDriver extends VcsDriver protected $branches; protected $infoCache = array(); + protected $trunkLocation = 'trunk'; + protected $branchesLocation = 'branches'; + protected $tagsLocation = 'tags'; + /** * @var \Composer\Util\Svn */ @@ -43,8 +47,18 @@ class SvnDriver extends VcsDriver public function initialize() { $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); + + if ($this->config->has('trunkLocation')) { + $this->trunkLocation = $this->config->get('trunkLocation'); + } + if ($this->config->has('branchesLocation')) { + $this->branchesLocation = $this->config->get('branchesLocation'); + } + if ($this->config->has('tagsLocation')) { + $this->tagsLocation = $this->config->get('tagsLocation'); + } - if (false !== ($pos = strrpos($this->url, '/trunk'))) { + if (false !== ($pos = strrpos($this->url, '/' . $this->trunkLocation))) { $this->baseUrl = substr($this->url, 0, $pos); } @@ -59,7 +73,7 @@ class SvnDriver extends VcsDriver */ public function getRootIdentifier() { - return 'trunk'; + return $this->trunkLocation; } /** @@ -145,13 +159,14 @@ class SvnDriver extends VcsDriver if (null === $this->tags) { $this->tags = array(); - $output = $this->execute('svn ls --verbose', $this->baseUrl . '/tags'); + $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsLocation); if ($output) { foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { 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->tagsLocation . + '/' . $match[2] . '@' . $match[1]; } } } @@ -174,8 +189,9 @@ class SvnDriver extends VcsDriver foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { - if (isset($match[1]) && isset($match[2]) && $match[2] === 'trunk/') { - $this->branches['trunk'] = '/trunk/@'.$match[1]; + if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkLocation . '/') { + $this->branches[$this->trunkLocation] = '/' . $this->trunkLocation . + '/@'.$match[1]; break; } } @@ -183,13 +199,14 @@ class SvnDriver extends VcsDriver } unset($output); - $output = $this->execute('svn ls --verbose', $this->baseUrl . '/branches'); + $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesLocation); if ($output) { foreach ($this->process->splitLines(trim($output)) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { 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->branchesLocation . + '/' . $match[2] . '@' . $match[1]; } } } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index c6f644388..2dd0407e9 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -50,6 +50,9 @@ class VcsRepository extends ArrayRepository $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->verbose = $io->isVerbose(); $this->config = $config; + if (isset($repoConfig['config']) && is_array($repoConfig['config'])) { + $this->config->merge(array('config' => $repoConfig['config'])); + } } public function setLoader(LoaderInterface $loader) From d1a452b00b184655be2132aeb9e426c4a9b02836 Mon Sep 17 00:00:00 2001 From: bboer Date: Thu, 30 Aug 2012 16:52:37 +0200 Subject: [PATCH 2/3] Made repoConfig available for the VcsDriver to be able to provide additional configuration options easily. --- src/Composer/Repository/Vcs/SvnDriver.php | 36 +++++++++++------------ src/Composer/Repository/Vcs/VcsDriver.php | 10 ++++--- src/Composer/Repository/VcsRepository.php | 11 ++++--- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index a2a4e468c..4fd6eb21e 100755 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -32,9 +32,9 @@ class SvnDriver extends VcsDriver protected $branches; protected $infoCache = array(); - protected $trunkLocation = 'trunk'; - protected $branchesLocation = 'branches'; - protected $tagsLocation = 'tags'; + protected $trunkPath = 'trunk'; + protected $branchesPath = 'branches'; + protected $tagsPath = 'tags'; /** * @var \Composer\Util\Svn @@ -47,18 +47,18 @@ class SvnDriver extends VcsDriver public function initialize() { $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); - - if ($this->config->has('trunkLocation')) { - $this->trunkLocation = $this->config->get('trunkLocation'); + + if (isset($this->repoConfig['trunk-path'])) { + $this->trunkPath = $this->repoConfig['trunk-path']; } - if ($this->config->has('branchesLocation')) { - $this->branchesLocation = $this->config->get('branchesLocation'); + if (isset($this->repoConfig['branches-path'])) { + $this->branchesPath = $this->repoConfig['branches-path']; } - if ($this->config->has('tagsLocation')) { - $this->tagsLocation = $this->config->get('tagsLocation'); + if (isset($this->repoConfig['tags-path'])) { + $this->tagsPath = $this->repoConfig['tags-path']; } - if (false !== ($pos = strrpos($this->url, '/' . $this->trunkLocation))) { + if (false !== ($pos = strrpos($this->url, '/' . $this->trunkPath))) { $this->baseUrl = substr($this->url, 0, $pos); } @@ -73,7 +73,7 @@ class SvnDriver extends VcsDriver */ public function getRootIdentifier() { - return $this->trunkLocation; + return $this->trunkPath; } /** @@ -159,13 +159,13 @@ class SvnDriver extends VcsDriver if (null === $this->tags) { $this->tags = array(); - $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsLocation); + $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath); if ($output) { foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { - $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsLocation . + $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsPath . '/' . $match[2] . '@' . $match[1]; } } @@ -189,8 +189,8 @@ class SvnDriver extends VcsDriver foreach ($this->process->splitLines($output) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { - if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkLocation . '/') { - $this->branches[$this->trunkLocation] = '/' . $this->trunkLocation . + if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkPath . '/') { + $this->branches[$this->trunkPath] = '/' . $this->trunkPath . '/@'.$match[1]; break; } @@ -199,13 +199,13 @@ class SvnDriver extends VcsDriver } unset($output); - $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesLocation); + $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesPath); if ($output) { foreach ($this->process->splitLines(trim($output)) as $line) { $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if (isset($match[1]) && isset($match[2]) && $match[2] !== './') { - $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesLocation . + $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesPath . '/' . $match[2] . '@' . $match[1]; } } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index ead688b69..c7a3be24d 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -27,6 +27,7 @@ abstract class VcsDriver implements VcsDriverInterface { protected $url; protected $originUrl; + protected $repoConfig; protected $io; protected $config; protected $process; @@ -35,16 +36,17 @@ abstract class VcsDriver implements VcsDriverInterface /** * Constructor. * - * @param string $url The URL + * @param array $repoConfig The repository configuration * @param IOInterface $io The IO instance * @param Config $config The composer configuration * @param ProcessExecutor $process Process instance, 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->originUrl = $url; + $this->url = $repoConfig['url']; + $this->originUrl = $repoConfig['url']; + $this->repoConfig = $repoConfig; $this->io = $io; $this->config = $config; $this->process = $process ?: new ProcessExecutor; diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 2dd0407e9..048a085f7 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -33,6 +33,7 @@ class VcsRepository extends ArrayRepository protected $versionParser; protected $type; protected $loader; + protected $repoConfig; public function __construct(array $repoConfig, IOInterface $io, Config $config, array $drivers = null) { @@ -50,9 +51,7 @@ class VcsRepository extends ArrayRepository $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->verbose = $io->isVerbose(); $this->config = $config; - if (isset($repoConfig['config']) && is_array($repoConfig['config'])) { - $this->config->merge(array('config' => $repoConfig['config'])); - } + $this->repoConfig = $repoConfig; } public function setLoader(LoaderInterface $loader) @@ -64,7 +63,7 @@ class VcsRepository extends ArrayRepository { if (isset($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(); return $driver; @@ -72,7 +71,7 @@ class VcsRepository extends ArrayRepository foreach ($this->drivers as $driver) { 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(); return $driver; @@ -81,7 +80,7 @@ class VcsRepository extends ArrayRepository foreach ($this->drivers as $driver) { 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(); return $driver; From 00361e00875e12e4ab38a4b5d37c44c1c3034e7c Mon Sep 17 00:00:00 2001 From: bboer Date: Fri, 31 Aug 2012 08:12:20 +0200 Subject: [PATCH 3/3] Fixed tests --- src/Composer/Repository/Vcs/GitHubDriver.php | 2 +- .../Test/Repository/Vcs/GitHubDriverTest.php | 24 +++++++++++++++---- .../Test/Repository/Vcs/SvnDriverTest.php | 6 ++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 58cfd82d9..c9004f4ac 100755 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -270,7 +270,7 @@ class GitHubDriver extends VcsDriver // cannot ask for authentication credentials (because we // are not interactive) then we fallback to GitDriver. $this->gitDriver = new GitDriver( - $this->generateSshUrl(), + array('url' => $this->generateSshUrl()), $this->io, $this->config, $this->process, diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index d8fdebd07..fe0ed6141 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -77,7 +77,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->will($this->returnValue('{"master_branch": "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(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -125,7 +129,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false)) ->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(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -183,7 +191,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)) ->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(); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); @@ -271,7 +283,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase ->method('splitLines') ->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(); $this->assertEquals('test_master', $gitHubDriver->getRootIdentifier()); diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index bf96e0f3a..d40d3f07a 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -45,7 +45,11 @@ class SvnDriverTest extends \PHPUnit_Framework_TestCase '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(); }