Added findBinary, fixes #115

This commit is contained in:
Dan Cryer 2013-10-08 08:50:10 +01:00
parent f7e466bdb1
commit 0c8d9c0f74
12 changed files with 112 additions and 33 deletions

View file

@ -459,4 +459,37 @@ class Builder
$value = json_encode($value);
$this->store->setMeta($this->build->getProjectId(), $this->build->getId(), $key, $value);
}
/**
* Find a binary required by a plugin.
* @param $binary
* @return null|string
*/
public function findBinary($binary)
{
if (is_string($binary)) {
$binary = array($binary);
}
foreach ($binary as $bin) {
// Check project root directory:
if (is_file(PHPCI_DIR . $bin)) {
return PHPCI_DIR . $bin;
}
// Check Composer bin dir:
if (is_file(PHPCI_DIR . 'vendor/bin/' . $bin)) {
return PHPCI_DIR . 'vendor/bin/' . $bin;
}
// Use "which"
$which = trim(shell_exec('which ' . $bin));
if (!empty($which)) {
return $which;
}
}
return null;
}
}

View file

@ -15,7 +15,7 @@ class Atoum implements \PHPCI\Plugin
if (isset($options['executable'])) {
$this->executable = $this->phpci->buildPath . DIRECTORY_SEPARATOR.$options['executable'];
} else {
$this->executable = PHPCI_BIN_DIR.'atoum';
$this->executable = $this->phpci->findBinary('atoum');
}
if (isset($options['args'])) {

View file

@ -36,7 +36,7 @@ class Composer implements \PHPCI\Plugin
*/
public function execute()
{
$composerLocation = $this->whereIsComposer();
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
if (!$composerLocation) {
$this->phpci->logFailure('Could not find Composer.');
@ -47,25 +47,4 @@ class Composer implements \PHPCI\Plugin
return $this->phpci->executeCommand($cmd, $this->directory, $this->action);
}
protected function whereIsComposer()
{
if (is_file(PHPCI_DIR . 'composer.phar')) {
return PHPCI_DIR . 'composer.phar';
}
$which = trim(shell_exec('which composer'));
if (!empty($which)) {
return $which;
}
$which = trim(shell_exec('which composer.phar'));
if (!empty($which)) {
return $which;
}
return null;
}
}

View file

@ -30,7 +30,7 @@ class Grunt implements \PHPCI\Plugin
$this->phpci = $phpci;
$this->directory = isset($options['directory']) ? $path . '/' . $options['directory'] : $path;
$this->task = isset($options['task']) ? $options['task'] : null;
$this->grunt = isset($options['grunt']) ? $options['grunt'] : 'grunt';
$this->grunt = isset($options['grunt']) ? $options['grunt'] : $this->phpci->findBinary('grunt');
$this->gruntfile = isset($options['gruntfile']) ? $options['gruntfile'] : 'Gruntfile.js';
}

View file

@ -66,7 +66,14 @@ class Pdepend implements \PHPCI\Plugin
throw new \Exception(sprintf('The location %s is not writable.', $this->location));
}
$cmd = PHPCI_BIN_DIR . 'pdepend --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
$pdepend = $this->phpci->findBinary('pdepend');
if (!$pdepend) {
$this->phpci->logFailure('Could not find pdepend.');
return false;
}
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
$this->removeBuildArtifacts();

View file

@ -105,7 +105,14 @@ class PhpCodeSniffer implements \PHPCI\Plugin
$encoding = ' --encoding='.$this->encoding;
}
$cmd = PHPCI_BIN_DIR . 'phpcs %s %s %s %s %s "%s"';
$phpcs = $this->phpci->findBinary('phpcs');
if (!$phpcs) {
$this->phpci->logFailure('Could not find phpcs.');
return false;
}
$cmd = $phpcs . ' %s %s %s %s %s "%s"';
$success = $this->phpci->executeCommand($cmd, $standard, $suffixes, $ignore, $tab_width, $encoding, $this->phpci->buildPath . $this->path);
$output = $this->phpci->getLastOutput();

View file

@ -57,7 +57,14 @@ class PhpCpd implements \PHPCI\Plugin
$ignore = implode('', $ignore);
}
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpcpd %s "%s"', $ignore, $this->phpci->buildPath.$this->path);
$phpcpd = $this->phpci->findBinary('phpcpd');
if (!$phpcpd) {
$this->phpci->logFailure('Could not find phpcpd.');
return false;
}
$success = $this->phpci->executeCommand($phpcpd . ' %s "%s"', $ignore, $this->phpci->buildPath.$this->path);
print $this->phpci->getLastOutput();

View file

@ -42,7 +42,14 @@ class PhpCsFixer implements \PHPCI\Plugin
$curdir = getcwd();
chdir($this->workingdir);
$cmd = PHPCI_BIN_DIR . 'php-cs-fixer fix . %s';
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
if (!$phpcsfixer) {
$this->phpci->logFailure('Could not find php-cs-fixer.');
return false;
}
$cmd = $phpcsfixer . ' fix . %s';
$success = $this->phpci->executeCommand($cmd, $this->args);
chdir($curdir);

View file

@ -47,7 +47,14 @@ class PhpLoc implements \PHPCI\Plugin
$ignore = implode('', $ignore);
}
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phploc %s "%s"', $ignore, $this->phpci->buildPath);
$phploc = $this->phpci->findBinary('phploc');
if (!$phploc) {
$this->phpci->logFailure('Could not find phploc.');
return false;
}
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->phpci->buildPath);
$output = $this->phpci->getLastOutput();
if (preg_match_all('/\((LOC|CLOC|NCLOC|LLOC)\)\s+([0-9]+)/', $output, $matches)) {

View file

@ -82,7 +82,14 @@ class PhpMessDetector implements \PHPCI\Plugin
$suffixes = ' --suffixes ' . implode(',', $this->suffixes);
}
$cmd = PHPCI_BIN_DIR . 'phpmd "%s" text %s %s %s';
$phpmd = $this->phpci->findBinary('phpmd');
if (!$phpmd) {
$this->phpci->logFailure('Could not find phpmd.');
return false;
}
$cmd = $phpmd . ' "%s" text %s %s %s';
$success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $this->path, implode(',', $this->rules), $ignore, $suffixes);
$errors = count(array_filter(explode(PHP_EOL, $this->phpci->getLastOutput())));
$this->phpci->storeBuildMeta('phpmd-warnings', $errors);

View file

@ -31,7 +31,15 @@ class PhpSpec implements \PHPCI\Plugin
{
$curdir = getcwd();
chdir($this->phpci->buildPath);
$success = $this->phpci->executeCommand(PHPCI_BIN_DIR . 'phpspec');
$phpspec = $this->phpci->findBinary('phpspec');
if (!$phpspec) {
$this->phpci->logFailure('Could not find phpspec.');
return false;
}
$success = $this->phpci->executeCommand($phpspec);
chdir($curdir);
return $success;

View file

@ -102,7 +102,16 @@ class PhpUnit implements \PHPCI\Plugin
chdir($this->phpci->buildPath.'/'.$this->runFrom);
}
$cmd = PHPCI_BIN_DIR . 'phpunit %s -c "%s" ' . $this->coverage . $this->path;
$phpunit = $this->phpci->findBinary('phpunit');
if (!$phpunit) {
$this->phpci->logFailure('Could not find phpunit.');
return false;
}
$cmd = $phpunit . ' %s -c "%s" ' . $this->coverage . $this->path;
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
if ($this->runFrom) {
@ -120,7 +129,15 @@ class PhpUnit implements \PHPCI\Plugin
} else {
$curdir = getcwd();
chdir($this->phpci->buildPath);
$cmd = PHPCI_BIN_DIR . 'phpunit %s "%s"';
$phpunit = $this->phpci->findBinary('phpunit');
if (!$phpunit) {
$this->phpci->logFailure('Could not find phpunit.');
return false;
}
$cmd = $phpunit . ' %s "%s"';
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $dirPath);
chdir($curdir);
return $success;