1
0
Fork 0

Made repoConfig available for the VcsDriver to be able to provide additional configuration options easily.

pull/1037/head
bboer 2012-08-30 16:52:37 +02:00
parent 93628c42d8
commit d1a452b00b
3 changed files with 29 additions and 28 deletions

View File

@ -32,9 +32,9 @@ class SvnDriver extends VcsDriver
protected $branches; protected $branches;
protected $infoCache = array(); protected $infoCache = array();
protected $trunkLocation = 'trunk'; protected $trunkPath = 'trunk';
protected $branchesLocation = 'branches'; protected $branchesPath = 'branches';
protected $tagsLocation = 'tags'; protected $tagsPath = 'tags';
/** /**
* @var \Composer\Util\Svn * @var \Composer\Util\Svn
@ -47,18 +47,18 @@ class SvnDriver extends VcsDriver
public function initialize() public function initialize()
{ {
$this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/'); $this->url = $this->baseUrl = rtrim(self::normalizeUrl($this->url), '/');
if ($this->config->has('trunkLocation')) { if (isset($this->repoConfig['trunk-path'])) {
$this->trunkLocation = $this->config->get('trunkLocation'); $this->trunkPath = $this->repoConfig['trunk-path'];
} }
if ($this->config->has('branchesLocation')) { if (isset($this->repoConfig['branches-path'])) {
$this->branchesLocation = $this->config->get('branchesLocation'); $this->branchesPath = $this->repoConfig['branches-path'];
} }
if ($this->config->has('tagsLocation')) { if (isset($this->repoConfig['tags-path'])) {
$this->tagsLocation = $this->config->get('tagsLocation'); $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); $this->baseUrl = substr($this->url, 0, $pos);
} }
@ -73,7 +73,7 @@ class SvnDriver extends VcsDriver
*/ */
public function getRootIdentifier() public function getRootIdentifier()
{ {
return $this->trunkLocation; return $this->trunkPath;
} }
/** /**
@ -159,13 +159,13 @@ 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 . '/' . $this->tagsLocation); $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], '/')] = '/' . $this->tagsLocation . $this->tags[rtrim($match[2], '/')] = '/' . $this->tagsPath .
'/' . $match[2] . '@' . $match[1]; '/' . $match[2] . '@' . $match[1];
} }
} }
@ -189,8 +189,8 @@ 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] === $this->trunkLocation . '/') { if (isset($match[1]) && isset($match[2]) && $match[2] === $this->trunkPath . '/') {
$this->branches[$this->trunkLocation] = '/' . $this->trunkLocation . $this->branches[$this->trunkPath] = '/' . $this->trunkPath .
'/@'.$match[1]; '/@'.$match[1];
break; break;
} }
@ -199,13 +199,13 @@ class SvnDriver extends VcsDriver
} }
unset($output); unset($output);
$output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->branchesLocation); $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], '/')] = '/' . $this->branchesLocation . $this->branches[rtrim($match[2], '/')] = '/' . $this->branchesPath .
'/' . $match[2] . '@' . $match[1]; '/' . $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,9 +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;
if (isset($repoConfig['config']) && is_array($repoConfig['config'])) { $this->repoConfig = $repoConfig;
$this->config->merge(array('config' => $repoConfig['config']));
}
} }
public function setLoader(LoaderInterface $loader) public function setLoader(LoaderInterface $loader)
@ -64,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;
@ -72,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;
@ -81,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;