1
0
Fork 0

revert style changes

pull/5862/head
Thomas Flori 2016-11-12 10:48:19 +01:00
parent 33d026bb06
commit d70dfd2df3
7 changed files with 34 additions and 129 deletions

View File

@ -37,8 +37,7 @@ class GitBitbucketDriver extends BitbucketDriver implements VcsDriverInterface
} }
if (null === $this->rootIdentifier) { if (null === $this->rootIdentifier) {
$resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository;
. $this->owner . '/' . $this->repository;
$repoData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource, true), $resource); $repoData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource, true), $resource);
$this->hasIssues = !empty($repoData['has_issues']); $this->hasIssues = !empty($repoData['has_issues']);
$this->rootIdentifier = !empty($repoData['main_branch']) ? $repoData['main_branch'] : 'master'; $this->rootIdentifier = !empty($repoData['main_branch']) ? $repoData['main_branch'] : 'master';
@ -92,8 +91,7 @@ class GitBitbucketDriver extends BitbucketDriver implements VcsDriverInterface
} }
if (null === $this->tags) { if (null === $this->tags) {
$resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
. $this->owner . '/' . $this->repository . '/tags';
$tagsData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource); $tagsData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
$this->tags = array(); $this->tags = array();
foreach ($tagsData as $tag => $data) { foreach ($tagsData as $tag => $data) {
@ -114,8 +112,7 @@ class GitBitbucketDriver extends BitbucketDriver implements VcsDriverInterface
} }
if (null === $this->branches) { if (null === $this->branches) {
$resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/' $resource = $this->getScheme() . '://api.bitbucket.org/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches';
. $this->owner . '/' . $this->repository . '/branches';
$branchData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource); $branchData = JsonFile::parseJson($this->getContentsWithOAuthCredentials($resource), $resource);
$this->branches = array(); $this->branches = array();
foreach ($branchData as $branch => $data) { foreach ($branchData as $branch => $data) {
@ -136,11 +133,7 @@ class GitBitbucketDriver extends BitbucketDriver implements VcsDriverInterface
} }
if (!extension_loaded('openssl')) { if (!extension_loaded('openssl')) {
$io->writeError( $io->writeError('Skipping Bitbucket git driver for '.$url.' because the OpenSSL PHP extension is missing.', true, IOInterface::VERBOSE);
'Skipping Bitbucket git driver for '.$url.' because the OpenSSL PHP extension is missing.',
true,
IOInterface::VERBOSE
);
return false; return false;
} }

View File

@ -42,8 +42,7 @@ class GitDriver extends VcsDriver
$this->repoDir = $this->url; $this->repoDir = $this->url;
$cacheUrl = realpath($this->url); $cacheUrl = realpath($this->url);
} else { } else {
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
. preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
GitUtil::cleanEnv(); GitUtil::cleanEnv();
@ -51,26 +50,16 @@ class GitDriver extends VcsDriver
$fs->ensureDirectoryExists(dirname($this->repoDir)); $fs->ensureDirectoryExists(dirname($this->repoDir));
if (!is_writable(dirname($this->repoDir))) { if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException( throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.dirname($this->repoDir).'" directory is not writable by the current user.');
'Can not clone ' . $this->url . ' to access package information. The "' . dirname($this->repoDir)
. '" directory is not writable by the current user.'
);
} }
if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) { if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
'The source URL ' . $this->url . ' is invalid, ssh URLs should have a port number after ":".'
. "\n" . 'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want'
. ' to provide a password or custom port.'
);
} }
$gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs); $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs);
if (!$gitUtil->syncMirror($this->url, $this->repoDir)) { if (!$gitUtil->syncMirror($this->url, $this->repoDir)) {
$this->io->writeError( $this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated</error>');
'<error>Failed to update ' . $this->url . ', package information from this repository'
. ' may be outdated</error>'
);
} }
$cacheUrl = $this->url; $cacheUrl = $this->url;
@ -79,10 +68,7 @@ class GitDriver extends VcsDriver
$this->getTags(); $this->getTags();
$this->getBranches(); $this->getBranches();
$this->cache = new Cache( $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl));
$this->io,
$this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $cacheUrl)
);
} }
/** /**

View File

@ -73,30 +73,15 @@ class GitLabDriver extends VcsDriver
public function initialize() public function initialize()
{ {
if (!preg_match(self::URL_REGEX, $this->url, $match)) { if (!preg_match(self::URL_REGEX, $this->url, $match)) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException('The URL provided is invalid. It must be the HTTP URL of a GitLab project.');
'The URL provided is invalid. It must be the HTTP URL of a GitLab project.'
);
} }
$this->scheme = !empty($match['scheme']) ? $this->scheme = !empty($match['scheme']) ? $match['scheme'] : (isset($this->repoConfig['secure-http']) && $this->repoConfig['secure-http'] === false ? 'http' : 'https');
$match['scheme'] :
(isset($this->repoConfig['secure-http']) && $this->repoConfig['secure-http'] === false ?
'http' :
'https'
);
$this->originUrl = !empty($match['domain']) ? $match['domain'] : $match['domain2']; $this->originUrl = !empty($match['domain']) ? $match['domain'] : $match['domain2'];
$this->owner = $match['owner']; $this->owner = $match['owner'];
$this->repository = preg_replace('#(\.git)$#', '', $match['repo']); $this->repository = preg_replace('#(\.git)$#', '', $match['repo']);
$this->cache = new Cache( $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.$this->originUrl.'/'.$this->owner.'/'.$this->repository);
$this->io,
implode('/', array(
$this->config->get('cache-repo-dir'),
$this->originUrl,
$this->owner,
$this->repository
))
);
$this->fetchProject(); $this->fetchProject();
} }
@ -290,8 +275,7 @@ class GitLabDriver extends VcsDriver
*/ */
public function getApiUrl() public function getApiUrl()
{ {
return $this->scheme . '://' . $this->originUrl . '/api/v3/projects/' return $this->scheme.'://'.$this->originUrl.'/api/v3/projects/'.$this->urlEncodeAll($this->owner).'%2F'.$this->urlEncodeAll($this->repository);
. $this->urlEncodeAll($this->owner) . '%2F' . $this->urlEncodeAll($this->repository);
} }
/** /**
@ -305,9 +289,7 @@ class GitLabDriver extends VcsDriver
$encoded = ''; $encoded = '';
for ($i = 0; isset($string[$i]); $i++) { for ($i = 0; isset($string[$i]); $i++) {
$character = $string[$i]; $character = $string[$i];
if (!ctype_alnum($character)) { if (!ctype_alnum($character)) $character = '%' . sprintf('%02X', ord($character));
$character = '%' . sprintf('%02X', ord($character));
}
$encoded .= $character; $encoded .= $character;
} }
return $encoded; return $encoded;
@ -356,10 +338,7 @@ class GitLabDriver extends VcsDriver
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
$this->gitDriver = null; $this->gitDriver = null;
$this->io->writeError( $this->io->writeError('<error>Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your credentials</error>');
'<error>Failed to clone the ' . $this->generateSshUrl() . ' repository, try running in interactive mode'
. ' so that you can enter your credentials</error>'
);
throw $e; throw $e;
} }
} }
@ -399,7 +378,7 @@ class GitLabDriver extends VcsDriver
switch ($e->getCode()) { switch ($e->getCode()) {
case 401: case 401:
case 404: case 404:
// try to authorize only if we are fetching the main /repos/foo/bar data, otherwise it must be a 404 // try to authorize only if we are fetching the main /repos/foo/bar data, otherwise it must be a real 404
if (!$fetchingRepoData) { if (!$fetchingRepoData) {
throw $e; throw $e;
} }
@ -411,22 +390,13 @@ class GitLabDriver extends VcsDriver
if (!$this->io->isInteractive()) { if (!$this->io->isInteractive()) {
return $this->attemptCloneFallback(); return $this->attemptCloneFallback();
} }
$this->io->writeError( $this->io->writeError('<warning>Failed to download ' . $this->owner . '/' . $this->repository . ':' . $e->getMessage() . '</warning>');
'<warning>Failed to download ' . $this->owner . '/' . $this->repository $gitLabUtil->authorizeOAuthInteractively($this->scheme, $this->originUrl, 'Your credentials are required to fetch private repository metadata (<info>'.$this->url.'</info>)');
. ':' . $e->getMessage() . '</warning>'
);
$gitLabUtil->authorizeOAuthInteractively(
$this->scheme,
$this->originUrl,
'Your credentials are required to fetch private repository metadata (<info>'
. $this->url . '</info>)'
);
return parent::getContents($url); return parent::getContents($url);
case 403: case 403:
if (!$this->io->hasAuthentication($this->originUrl) && if (!$this->io->hasAuthentication($this->originUrl) && $gitLabUtil->authorizeOAuth($this->originUrl)) {
$gitLabUtil->authorizeOAuth($this->originUrl)) {
return parent::getContents($url); return parent::getContents($url);
} }
@ -462,11 +432,7 @@ class GitLabDriver extends VcsDriver
} }
if ('https' === $scheme && !extension_loaded('openssl')) { if ('https' === $scheme && !extension_loaded('openssl')) {
$io->writeError( $io->writeError('Skipping GitLab driver for '.$url.' because the OpenSSL PHP extension is missing.', true, IOInterface::VERBOSE);
'Skipping GitLab driver for ' . $url . ' because the OpenSSL PHP extension is missing.',
true,
IOInterface::VERBOSE
);
return false; return false;
} }

View File

@ -29,14 +29,10 @@ class HgBitbucketDriver extends BitbucketDriver
public function getRootIdentifier() public function getRootIdentifier()
{ {
if (null === $this->rootIdentifier) { if (null === $this->rootIdentifier) {
$resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/' $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
. $this->owner . '/' . $this->repository . '/tags';
$repoData = JsonFile::parseJson($this->getContents($resource), $resource); $repoData = JsonFile::parseJson($this->getContents($resource), $resource);
if (array() === $repoData || !isset($repoData['tip'])) { if (array() === $repoData || !isset($repoData['tip'])) {
throw new \RuntimeException( throw new \RuntimeException($this->url.' does not appear to be a mercurial repository, use '.$this->url.'.git if this is a git bitbucket repository');
$this->url . ' does not appear to be a mercurial repository, use '
. $this->url . '.git if this is a git bitbucket repository'
);
} }
$this->hasIssues = !empty($repoData['has_issues']); $this->hasIssues = !empty($repoData['has_issues']);
$this->rootIdentifier = $repoData['tip']['raw_node']; $this->rootIdentifier = $repoData['tip']['raw_node'];
@ -77,8 +73,7 @@ class HgBitbucketDriver extends BitbucketDriver
public function getTags() public function getTags()
{ {
if (null === $this->tags) { if (null === $this->tags) {
$resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/' $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/tags';
. $this->owner . '/' . $this->repository . '/tags';
$tagsData = JsonFile::parseJson($this->getContents($resource), $resource); $tagsData = JsonFile::parseJson($this->getContents($resource), $resource);
$this->tags = array(); $this->tags = array();
foreach ($tagsData as $tag => $data) { foreach ($tagsData as $tag => $data) {
@ -96,8 +91,7 @@ class HgBitbucketDriver extends BitbucketDriver
public function getBranches() public function getBranches()
{ {
if (null === $this->branches) { if (null === $this->branches) {
$resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/' $resource = $this->getScheme() . '://bitbucket.org/api/1.0/repositories/'.$this->owner.'/'.$this->repository.'/branches';
. $this->owner . '/' . $this->repository . '/branches';
$branchData = JsonFile::parseJson($this->getContents($resource), $resource); $branchData = JsonFile::parseJson($this->getContents($resource), $resource);
$this->branches = array(); $this->branches = array();
foreach ($branchData as $branch => $data) { foreach ($branchData as $branch => $data) {
@ -118,11 +112,7 @@ class HgBitbucketDriver extends BitbucketDriver
} }
if (!extension_loaded('openssl')) { if (!extension_loaded('openssl')) {
$io->writeError( $io->writeError('Skipping Bitbucket hg driver for '.$url.' because the OpenSSL PHP extension is missing.', true, IOInterface::VERBOSE);
'Skipping Bitbucket hg driver for ' . $url . ' because the OpenSSL PHP extension is missing.',
true,
IOInterface::VERBOSE
);
return false; return false;
} }

View File

@ -45,10 +45,7 @@ class HgDriver extends VcsDriver
$fs->ensureDirectoryExists($cacheDir); $fs->ensureDirectoryExists($cacheDir);
if (!is_writable(dirname($this->repoDir))) { if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException( throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.$cacheDir.'" directory is not writable by the current user.');
'Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir
. '" directory is not writable by the current user.'
);
} }
// Ensure we are allowed to use this URL by config // Ensure we are allowed to use this URL by config
@ -57,36 +54,20 @@ class HgDriver extends VcsDriver
// update the repo if it is a valid hg repository // update the repo if it is a valid hg repository
if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) { if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) {
if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) { if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) {
$this->io->writeError( $this->io->writeError('<error>Failed to update '.$this->url.', package information from this repository may be outdated ('.$this->process->getErrorOutput().')</error>');
'<error>Failed to update ' . $this->url . ', package information from this repository may be'
. ' outdated ('.$this->process->getErrorOutput().')</error>'
);
} }
} else { } else {
// clean up directory and do a fresh clone into it // clean up directory and do a fresh clone into it
$fs->removeDirectory($this->repoDir); $fs->removeDirectory($this->repoDir);
if (0 !== $this->process->execute( if (0 !== $this->process->execute(sprintf('hg clone --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoDir)), $output, $cacheDir)) {
sprintf(
'hg clone --noupdate %s %s',
ProcessExecutor::escape($this->url),
ProcessExecutor::escape($this->repoDir)
),
$output,
$cacheDir
)) {
$output = $this->process->getErrorOutput(); $output = $this->process->getErrorOutput();
if (0 !== $this->process->execute('hg --version', $ignoredOutput)) { if (0 !== $this->process->execute('hg --version', $ignoredOutput)) {
throw new \RuntimeException( throw new \RuntimeException('Failed to clone '.$this->url.', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
'Failed to clone ' . $this->url . ', hg was not found, check that it is installed and in'
. ' your PATH env.' . "\n\n" . $this->process->getErrorOutput()
);
} }
throw new \RuntimeException( throw new \RuntimeException('Failed to clone '.$this->url.', could not read packages from it' . "\n\n" .$output);
'Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" .$output
);
} }
} }
} }

View File

@ -77,10 +77,7 @@ class SvnDriver extends VcsDriver
$this->baseUrl = substr($this->url, 0, $pos); $this->baseUrl = substr($this->url, 0, $pos);
} }
$this->cache = new Cache( $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.preg_replace('{[^a-z0-9.]}i', '-', $this->baseUrl));
$this->io,
$this->config->get('cache-repo-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->baseUrl)
);
$this->getBranches(); $this->getBranches();
$this->getTags(); $this->getTags();
@ -384,10 +381,7 @@ class SvnDriver extends VcsDriver
return $this->util->execute($command, $url); return $this->util->execute($command, $url);
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
if (0 !== $this->process->execute('svn --version', $ignoredOutput)) { if (0 !== $this->process->execute('svn --version', $ignoredOutput)) {
throw new \RuntimeException( throw new \RuntimeException('Failed to load '.$this->url.', svn was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
'Failed to load ' . $this->url . ', svn was not found, check that it is installed and in your'
. ' PATH env.' . "\n\n" . $this->process->getErrorOutput()
);
} }
throw new \RuntimeException( throw new \RuntimeException(

View File

@ -54,13 +54,8 @@ abstract class VcsDriver implements VcsDriverInterface
* @param ProcessExecutor $process Process instance, injectable for mocking * @param ProcessExecutor $process Process instance, injectable for mocking
* @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking * @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking
*/ */
final public function __construct( final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
array $repoConfig, {
IOInterface $io,
Config $config,
ProcessExecutor $process = null,
RemoteFilesystem $remoteFilesystem = null
) {
if (Filesystem::isLocalPath($repoConfig['url'])) { if (Filesystem::isLocalPath($repoConfig['url'])) {
$repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']); $repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']);
} }