1
0
Fork 0

make use of process component fixes #105

pull/180/head
digitalkaoz 2012-01-03 17:03:17 +01:00
parent 21ab41fa2d
commit a15567cea6
7 changed files with 65 additions and 31 deletions

View File

@ -13,6 +13,7 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Composer\Downloader\Util\Filesystem;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -38,7 +39,7 @@ class GitDownloader implements DownloaderInterface
$url = escapeshellarg($package->getSourceUrl());
$ref = escapeshellarg($package->getSourceReference());
system(sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref));
Filesystem::runProcess(sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref));
}
/**
@ -51,7 +52,7 @@ class GitDownloader implements DownloaderInterface
}
$this->enforceCleanDirectory($path);
system(sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $target->getSourceReference()));
Filesystem::runProcess(sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $target->getSourceReference()));
}
/**
@ -66,7 +67,7 @@ class GitDownloader implements DownloaderInterface
private function enforceCleanDirectory($path)
{
exec(sprintf('cd %s && git status --porcelain', $path), $output);
Filesystem::runProcess(sprintf('cd %s && git status --porcelain', $path),$output);
if (implode('', $output)) {
throw new \RuntimeException('Source directory has uncommitted changes');
}

View File

@ -13,6 +13,7 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Composer\Downloader\Util\Filesystem;
/**
* @author Per Bernhardt <plb@webfactory.de>
@ -38,7 +39,7 @@ class HgDownloader implements DownloaderInterface
$url = escapeshellarg($package->getSourceUrl());
$ref = escapeshellarg($package->getSourceReference());
system(sprintf('(hg clone %s %s 2> /dev/null) && cd %2$s && hg up %s', $url, $path, $ref));
Filesystem::runProcess(sprintf('(hg clone %s %s 2> /dev/null) && cd %2$s && hg up %s', $url, $path, $ref));
}
/**
@ -51,7 +52,7 @@ class HgDownloader implements DownloaderInterface
}
$this->enforceCleanDirectory($path);
system(sprintf('cd %s && hg pull && hg up %s', $path, escapeshellarg($target->getSourceReference())));
Filesystem::runProcess(sprintf('cd %s && hg pull && hg up %s', $path, escapeshellarg($target->getSourceReference())));
}
/**
@ -66,7 +67,7 @@ class HgDownloader implements DownloaderInterface
private function enforceCleanDirectory($path)
{
exec(sprintf('cd %s && hg st', $path), $output);
Filesystem::runProcess(sprintf('cd %s && hg st', $path), $output);
if (implode('', $output)) {
throw new \RuntimeException('Source directory has uncommitted changes');
}

View File

@ -3,6 +3,7 @@
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
use Composer\Downloader\Util\Filesystem;
/**
* @author Ben Bieker <mail@ben-bieker.de>
@ -28,7 +29,7 @@ class SvnDownloader implements DownloaderInterface
$url = escapeshellarg($package->getSourceUrl());
$ref = escapeshellarg($package->getSourceReference());
system(sprintf('svn co %s/%s %s', $url, $ref, $path));
Filesystem::runProcess(sprintf('svn co %s/%s %s', $url, $ref, $path));
}
/**
@ -42,7 +43,7 @@ class SvnDownloader implements DownloaderInterface
$url = escapeshellarg($target->getSourceUrl());
$ref = escapeshellarg($target->getSourceReference());
system(sprintf('cd %s && svn switch %s/%s', $path, $url, $ref));
Filesystem::runProcess(sprintf('cd %s && svn switch %s/%s', $path, $url, $ref));
}
/**

View File

@ -12,6 +12,8 @@
namespace Composer\Downloader\Util;
use Symfony\Component\Process\Process;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
@ -20,9 +22,9 @@ class Filesystem
public function removeDirectory($directory)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($directory))));
static::runProcess(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($directory))));
} else {
system(sprintf('rm -rf %s', escapeshellarg($directory)));
static::runProcess(sprintf('rm -rf %s', escapeshellarg($directory)));
}
}
@ -125,4 +127,30 @@ class Filesystem
{
return substr($path, 0, 1) === '/' || substr($path, 1, 1) === ':';
}
/**
* runs a process on the commandline
*
* @static
* @param $command the command to execute
* @param null $output the output will be written into this var if passed
* @return int statuscode
*/
public static function runProcess($command, &$output = null)
{
$process = new Process($command);
$process->run(function($type, $buffer) use ($output) {
if (null === $output) {
return;
}
echo $buffer;
});
if (null !== $output) {
$output = $process->getOutput();
}
return $process->getExitCode();
}
}

View File

@ -3,6 +3,7 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Composer\Downloader\Util\Filesystem;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -29,9 +30,9 @@ class GitDriver implements VcsDriverInterface
$url = escapeshellarg($this->url);
$tmpDir = escapeshellarg($this->tmpDir);
if (is_dir($this->tmpDir)) {
exec(sprintf('cd %s && git fetch origin', $tmpDir), $output);
Filesystem::runProcess(sprintf('cd %s && git fetch origin', $tmpDir), $output);
} else {
exec(sprintf('git clone %s %s', $url, $tmpDir), $output);
Filesystem::runProcess(sprintf('git clone %s %s', $url, $tmpDir), $output);
}
$this->getTags();
@ -45,7 +46,7 @@ class GitDriver implements VcsDriverInterface
{
if (null === $this->rootIdentifier) {
$this->rootIdentifier = 'master';
exec(sprintf('cd %s && git branch --no-color -r', escapeshellarg($this->tmpDir)), $output);
Filesystem::runProcess(sprintf('cd %s && git branch --no-color -r', escapeshellarg($this->tmpDir)), $output);
foreach ($output as $branch) {
if ($branch && preg_match('{/HEAD +-> +[^/]+/(\S+)}', $branch, $match)) {
$this->rootIdentifier = $match[1];
@ -89,7 +90,7 @@ class GitDriver implements VcsDriverInterface
public function getComposerInformation($identifier)
{
if (!isset($this->infoCache[$identifier])) {
exec(sprintf('cd %s && git show %s:composer.json', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
Filesystem::runProcess(sprintf('cd %s && git show %s:composer.json', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
$composer = implode("\n", $output);
unset($output);
@ -100,7 +101,7 @@ class GitDriver implements VcsDriverInterface
$composer = JsonFile::parseJson($composer);
if (!isset($composer['time'])) {
exec(sprintf('cd %s && git log -1 --format=%%at %s', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
Filesystem::runProcess(sprintf('cd %s && git log -1 --format=%%at %s', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
$date = new \DateTime('@'.$output[0]);
$composer['time'] = $date->format('Y-m-d H:i:s');
}
@ -116,7 +117,7 @@ class GitDriver implements VcsDriverInterface
public function getTags()
{
if (null === $this->tags) {
exec(sprintf('cd %s && git tag', escapeshellarg($this->tmpDir)), $output);
Filesystem::runProcess(sprintf('cd %s && git tag', escapeshellarg($this->tmpDir)), $output);
$this->tags = $output ? array_combine($output, $output) : array();
}
@ -131,7 +132,7 @@ class GitDriver implements VcsDriverInterface
if (null === $this->branches) {
$branches = array();
exec(sprintf('cd %s && git branch --no-color -rv', escapeshellarg($this->tmpDir)), $output);
Filesystem::runProcess(sprintf('cd %s && git branch --no-color -rv', escapeshellarg($this->tmpDir)), $output);
foreach ($output as $branch) {
if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
preg_match('{^ *[^/]+/(\S+) *([a-f0-9]+) .*$}', $branch, $match);

View File

@ -13,6 +13,7 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Composer\Downloader\Util\Filesystem;
/**
* @author Per Bernhardt <plb@webfactory.de>
@ -39,9 +40,9 @@ class HgDriver implements VcsDriverInterface
$url = escapeshellarg($this->url);
$tmpDir = escapeshellarg($this->tmpDir);
if (is_dir($this->tmpDir)) {
exec(sprintf('cd %s && hg pull -u', $tmpDir), $output);
Filesystem::runProcess(sprintf('cd %s && hg pull -u', $tmpDir), $output);
} else {
exec(sprintf('cd %s && hg clone %s %s', escapeshellarg(sys_get_temp_dir()), $url, $tmpDir), $output);
Filesystem::runProcess(sprintf('cd %s && hg clone %s %s', escapeshellarg(sys_get_temp_dir()), $url, $tmpDir), $output);
}
$this->getTags();
@ -55,7 +56,7 @@ class HgDriver implements VcsDriverInterface
{
$tmpDir = escapeshellarg($this->tmpDir);
if (null === $this->rootIdentifier) {
exec(sprintf('cd %s && hg tip --template "{node}"', $tmpDir), $output);
Filesystem::runProcess(sprintf('cd %s && hg tip --template "{node}"', $tmpDir), $output);
$this->rootIdentifier = $output[0];
}
@ -94,7 +95,7 @@ class HgDriver implements VcsDriverInterface
public function getComposerInformation($identifier)
{
if (!isset($this->infoCache[$identifier])) {
exec(sprintf('cd %s && hg cat -r %s composer.json', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
Filesystem::runProcess(sprintf('cd %s && hg cat -r %s composer.json', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
$composer = implode("\n", $output);
unset($output);
@ -105,7 +106,7 @@ class HgDriver implements VcsDriverInterface
$composer = JsonFile::parseJson($composer);
if (!isset($composer['time'])) {
exec(sprintf('cd %s && hg log --template "{date|rfc822date}" -r %s', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
Filesystem::runProcess(sprintf('cd %s && hg log --template "{date|rfc822date}" -r %s', escapeshellarg($this->tmpDir), escapeshellarg($identifier)), $output);
$date = new \DateTime($output[0]);
$composer['time'] = $date->format('Y-m-d H:i:s');
}
@ -123,7 +124,7 @@ class HgDriver implements VcsDriverInterface
if (null === $this->tags) {
$tags = array();
exec(sprintf('cd %s && hg tags', escapeshellarg($this->tmpDir)), $output);
Filesystem::runProcess(sprintf('cd %s && hg tags', escapeshellarg($this->tmpDir)), $output);
foreach ($output as $tag) {
if (preg_match('(^([^\s]+)\s+\d+:(.*)$)', $tag, $match))
$tags[$match[1]] = $match[2];
@ -143,7 +144,7 @@ class HgDriver implements VcsDriverInterface
if (null === $this->branches) {
$branches = array();
exec(sprintf('cd %s && hg branches', escapeshellarg($this->tmpDir)), $output);
Filesystem::runProcess(sprintf('cd %s && hg branches', escapeshellarg($this->tmpDir)), $output);
foreach ($output as $branch) {
if (preg_match('(^([^\s]+)\s+\d+:(.*)$)', $branch, $match))
$branches[$match[1]] = $match[2];
@ -182,7 +183,7 @@ class HgDriver implements VcsDriverInterface
return false;
}
exec(sprintf('cd %s && hg identify %s', escapeshellarg(sys_get_temp_dir()), escapeshellarg($url)), $ignored, $exit);
$exit = Filesystem::runProcess(sprintf('cd %s && hg identify %s', escapeshellarg(sys_get_temp_dir()), escapeshellarg($url)), $ignored);
return $exit === 0;
}
}

View File

@ -3,6 +3,7 @@
namespace Composer\Repository\Vcs;
use Composer\Json\JsonFile;
use Composer\Downloader\Util\Filesystem;
/**
* @author Jordi Boggiano <j.boggiano@seld.be>
@ -78,7 +79,7 @@ class SvnDriver implements VcsDriverInterface
$rev = '';
}
exec(sprintf('svn cat --non-interactive %s', escapeshellarg($this->baseUrl.$identifier.'composer.json'.$rev)), $output);
Filesystem::runProcess(sprintf('svn cat --non-interactive %s', escapeshellarg($this->baseUrl.$identifier.'composer.json'.$rev)),$output);
$composer = implode("\n", $output);
unset($output);
@ -89,7 +90,7 @@ class SvnDriver implements VcsDriverInterface
$composer = JsonFile::parseJson($composer);
if (!isset($composer['time'])) {
exec(sprintf('svn info %s', escapeshellarg($this->baseUrl.$identifier.$rev)), $output);
Filesystem::runProcess(sprintf('svn info %s', escapeshellarg($this->baseUrl.$identifier.$rev)), $output);
foreach ($output as $line) {
if (preg_match('{^Last Changed Date: ([^(]+)}', $line, $match)) {
$date = new \DateTime($match[1]);
@ -110,7 +111,7 @@ class SvnDriver implements VcsDriverInterface
public function getTags()
{
if (null === $this->tags) {
exec(sprintf('svn ls --non-interactive %s', escapeshellarg($this->baseUrl.'/tags')), $output);
Filesystem::runProcess(sprintf('svn ls --non-interactive %s', escapeshellarg($this->baseUrl.'/tags')), $output);
$this->tags = array();
foreach ($output as $tag) {
$this->tags[rtrim($tag, '/')] = '/tags/'.$tag;
@ -126,7 +127,7 @@ class SvnDriver implements VcsDriverInterface
public function getBranches()
{
if (null === $this->branches) {
exec(sprintf('svn ls --verbose --non-interactive %s', escapeshellarg($this->baseUrl.'/')), $output);
Filesystem::runProcess(sprintf('svn ls --verbose --non-interactive %s', escapeshellarg($this->baseUrl.'/')), $output);
$this->branches = array();
foreach ($output as $line) {
@ -138,7 +139,7 @@ class SvnDriver implements VcsDriverInterface
}
unset($output);
exec(sprintf('svn ls --verbose --non-interactive %s', escapeshellarg($this->baseUrl.'/branches')), $output);
Filesystem::runProcess(sprintf('svn ls --verbose --non-interactive %s', escapeshellarg($this->baseUrl.'/branches')), $output);
foreach ($output as $line) {
preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match);
if ($match[2] === './') {
@ -178,7 +179,7 @@ class SvnDriver implements VcsDriverInterface
return false;
}
exec(sprintf('svn info --non-interactive %s 2>/dev/null', escapeshellarg($url)), $ignored, $exit);
$exit = Filesystem::runProcess(sprintf('svn info --non-interactive %s 2>/dev/null', escapeshellarg($url)), $ignored);
return $exit === 0;
}
}