Let CommandExecutor::findBinary throw an exception when the binary is missing.
Close #910
This commit is contained in:
parent
7f46b650dc
commit
f25b1d25dc
|
@ -259,12 +259,14 @@ class Builder implements LoggerAwareInterface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a binary required by a plugin.
|
* Find a binary required by a plugin.
|
||||||
* @param $binary
|
* @param string $binary
|
||||||
|
* @param bool $quiet
|
||||||
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function findBinary($binary)
|
public function findBinary($binary, $quiet = false)
|
||||||
{
|
{
|
||||||
return $this->commandExecutor->findBinary($binary, $this->buildPath);
|
return $this->commandExecutor->findBinary($binary, $quiet = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
namespace PHPCI\Helper;
|
namespace PHPCI\Helper;
|
||||||
|
|
||||||
use \PHPCI\Logging\BuildLogger;
|
use Exception;
|
||||||
|
use PHPCI\Logging\BuildLogger;
|
||||||
use Psr\Log\LogLevel;
|
use Psr\Log\LogLevel;
|
||||||
use PHPCI\Helper\Lang;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles running system commands with variables.
|
* Handles running system commands with variables.
|
||||||
|
@ -20,7 +20,7 @@ use PHPCI\Helper\Lang;
|
||||||
abstract class BaseCommandExecutor implements CommandExecutor
|
abstract class BaseCommandExecutor implements CommandExecutor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \PHPCI\Logging\BuildLogger
|
* @var BuildLogger
|
||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
|
@ -144,13 +144,12 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
||||||
/**
|
/**
|
||||||
* Find a binary required by a plugin.
|
* Find a binary required by a plugin.
|
||||||
* @param string $binary
|
* @param string $binary
|
||||||
* @param null $buildPath
|
* @param bool $quiet
|
||||||
* @return null|string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function findBinary($binary, $buildPath = null)
|
public function findBinary($binary, $quiet = false)
|
||||||
{
|
{
|
||||||
$binaryPath = null;
|
$composerBin = $this->getComposerBinDir(realpath($this->buildPath));
|
||||||
$composerBin = $this->getComposerBinDir(realpath($buildPath));
|
|
||||||
|
|
||||||
if (is_string($binary)) {
|
if (is_string($binary)) {
|
||||||
$binary = array($binary);
|
$binary = array($binary);
|
||||||
|
@ -161,30 +160,30 @@ abstract class BaseCommandExecutor implements CommandExecutor
|
||||||
|
|
||||||
if (is_dir($composerBin) && is_file($composerBin.'/'.$bin)) {
|
if (is_dir($composerBin) && is_file($composerBin.'/'.$bin)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG);
|
||||||
$binaryPath = $composerBin . '/' . $bin;
|
return $composerBin . '/' . $bin;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_file($this->rootDir . $bin)) {
|
if (is_file($this->rootDir . $bin)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG);
|
||||||
$binaryPath = $this->rootDir . $bin;
|
return $this->rootDir . $bin;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
|
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG);
|
||||||
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
|
return $this->rootDir . 'vendor/bin/' . $bin;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$findCmdResult = $this->findGlobalBinary($bin);
|
$findCmdResult = $this->findGlobalBinary($bin);
|
||||||
if (is_file($findCmdResult)) {
|
if (is_file($findCmdResult)) {
|
||||||
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
|
$this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG);
|
||||||
$binaryPath = $findCmdResult;
|
return $findCmdResult;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $binaryPath;
|
|
||||||
|
if ($quiet) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Exception(Lang::get('could_not_find', implode('/', $binary)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,10 +26,13 @@ interface CommandExecutor
|
||||||
/**
|
/**
|
||||||
* Find a binary required by a plugin.
|
* Find a binary required by a plugin.
|
||||||
* @param string $binary
|
* @param string $binary
|
||||||
* @param string $buildPath the current build path
|
* @param bool $quiet Returns null instead of throwing an execption.
|
||||||
|
*
|
||||||
* @return null|string
|
* @return null|string
|
||||||
|
*
|
||||||
|
* @throws \Exception when no binary has been found and $quiet is false.
|
||||||
*/
|
*/
|
||||||
public function findBinary($binary, $buildPath = null);
|
public function findBinary($binary, $quiet = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the buildPath property.
|
* Set the buildPath property.
|
||||||
|
|
|
@ -133,12 +133,6 @@ class Codeception implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
} else {
|
} else {
|
||||||
$codecept = $this->phpci->findBinary('codecept');
|
$codecept = $this->phpci->findBinary('codecept');
|
||||||
|
|
||||||
if (!$codecept) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'codecept'));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --tap ' . $this->args;
|
$cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --tap ' . $this->args;
|
||||||
|
|
||||||
if (IS_WIN) {
|
if (IS_WIN) {
|
||||||
|
|
|
@ -81,11 +81,6 @@ class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
{
|
{
|
||||||
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
|
$composerLocation = $this->phpci->findBinary(array('composer', 'composer.phar'));
|
||||||
|
|
||||||
if (!$composerLocation) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'composer'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = '';
|
$cmd = '';
|
||||||
|
|
||||||
if (IS_WIN) {
|
if (IS_WIN) {
|
||||||
|
|
|
@ -79,15 +79,10 @@ class Pdepend implements \PHPCI\Plugin
|
||||||
|
|
||||||
$pdepend = $this->phpci->findBinary('pdepend');
|
$pdepend = $this->phpci->findBinary('pdepend');
|
||||||
|
|
||||||
if (!$pdepend) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'pdepend'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
||||||
|
|
||||||
$this->removeBuildArtifacts();
|
$this->removeBuildArtifacts();
|
||||||
|
|
||||||
// If we need to ignore directories
|
// If we need to ignore directories
|
||||||
if (count($this->phpci->ignore)) {
|
if (count($this->phpci->ignore)) {
|
||||||
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
||||||
|
|
|
@ -81,11 +81,6 @@ class Phing implements \PHPCI\Plugin
|
||||||
{
|
{
|
||||||
$phingExecutable = $this->phpci->findBinary('phing');
|
$phingExecutable = $this->phpci->findBinary('phing');
|
||||||
|
|
||||||
if (!$phingExecutable) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'phing'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd[] = $phingExecutable . ' -f ' . $this->getBuildFilePath();
|
$cmd[] = $phingExecutable . ' -f ' . $this->getBuildFilePath();
|
||||||
|
|
||||||
if ($this->getPropertyFile()) {
|
if ($this->getPropertyFile()) {
|
||||||
|
|
|
@ -149,11 +149,6 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
|
|
||||||
$phpcs = $this->phpci->findBinary('phpcs');
|
$phpcs = $this->phpci->findBinary('phpcs');
|
||||||
|
|
||||||
if (!$phpcs) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpcs'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->phpci->logExecOutput(false);
|
$this->phpci->logExecOutput(false);
|
||||||
|
|
||||||
$cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
|
$cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
|
||||||
|
|
|
@ -90,18 +90,13 @@ class PhpCpd implements \PHPCI\Plugin
|
||||||
|
|
||||||
$phpcpd = $this->phpci->findBinary('phpcpd');
|
$phpcpd = $this->phpci->findBinary('phpcpd');
|
||||||
|
|
||||||
if (!$phpcpd) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'phpcpd'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tmpfilename = tempnam('/tmp', 'phpcpd');
|
$tmpfilename = tempnam('/tmp', 'phpcpd');
|
||||||
|
|
||||||
$cmd = $phpcpd . ' --log-pmd "%s" %s "%s"';
|
$cmd = $phpcpd . ' --log-pmd "%s" %s "%s"';
|
||||||
$success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path);
|
$success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path);
|
||||||
|
|
||||||
print $this->phpci->getLastOutput();
|
print $this->phpci->getLastOutput();
|
||||||
|
|
||||||
list($errorCount, $data) = $this->processReport(file_get_contents($tmpfilename));
|
list($errorCount, $data) = $this->processReport(file_get_contents($tmpfilename));
|
||||||
$this->build->storeMeta('phpcpd-warnings', $errorCount);
|
$this->build->storeMeta('phpcpd-warnings', $errorCount);
|
||||||
$this->build->storeMeta('phpcpd-data', $data);
|
$this->build->storeMeta('phpcpd-data', $data);
|
||||||
|
|
|
@ -69,11 +69,6 @@ class PhpCsFixer implements \PHPCI\Plugin
|
||||||
|
|
||||||
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
|
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
|
||||||
|
|
||||||
if (!$phpcsfixer) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'php-cs-fixer'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = $phpcsfixer . ' fix . %s %s %s';
|
$cmd = $phpcsfixer . ' fix . %s %s %s';
|
||||||
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
||||||
|
|
||||||
|
|
|
@ -104,11 +104,6 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
// Check that the binary exists:
|
// Check that the binary exists:
|
||||||
$checker = $this->phpci->findBinary('phpdoccheck');
|
$checker = $this->phpci->findBinary('phpdoccheck');
|
||||||
|
|
||||||
if (!$checker) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpdoccheck'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build ignore string:
|
// Build ignore string:
|
||||||
$ignore = '';
|
$ignore = '';
|
||||||
if (count($this->ignore)) {
|
if (count($this->ignore)) {
|
||||||
|
|
|
@ -80,11 +80,6 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
|
|
||||||
$phploc = $this->phpci->findBinary('phploc');
|
$phploc = $this->phpci->findBinary('phploc');
|
||||||
|
|
||||||
if (!$phploc) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phploc'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
|
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
|
||||||
$output = $this->phpci->getLastOutput();
|
$output = $this->phpci->getLastOutput();
|
||||||
|
|
||||||
|
|
|
@ -121,11 +121,6 @@ class PhpMessDetector implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
|
|
||||||
$phpmdBinaryPath = $this->phpci->findBinary('phpmd');
|
$phpmdBinaryPath = $this->phpci->findBinary('phpmd');
|
||||||
|
|
||||||
if (!$phpmdBinaryPath) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpmd'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->executePhpMd($phpmdBinaryPath);
|
$this->executePhpMd($phpmdBinaryPath);
|
||||||
|
|
||||||
list($errorCount, $data) = $this->processReport(trim($this->phpci->getLastOutput()));
|
list($errorCount, $data) = $this->processReport(trim($this->phpci->getLastOutput()));
|
||||||
|
|
|
@ -78,11 +78,6 @@ class PhpParallelLint implements \PHPCI\Plugin
|
||||||
|
|
||||||
$phplint = $this->phpci->findBinary('parallel-lint');
|
$phplint = $this->phpci->findBinary('parallel-lint');
|
||||||
|
|
||||||
if (!$phplint) {
|
|
||||||
$this->phpci->logFailure(Lang::get('could_not_find', 'parallel-lint'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = $phplint . ' %s "%s"';
|
$cmd = $phplint . ' %s "%s"';
|
||||||
$success = $this->phpci->executeCommand(
|
$success = $this->phpci->executeCommand(
|
||||||
$cmd,
|
$cmd,
|
||||||
|
|
|
@ -59,11 +59,6 @@ class PhpSpec implements PHPCI\Plugin
|
||||||
|
|
||||||
$phpspec = $this->phpci->findBinary(array('phpspec', 'phpspec.php'));
|
$phpspec = $this->phpci->findBinary(array('phpspec', 'phpspec.php'));
|
||||||
|
|
||||||
if (!$phpspec) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpspec'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
|
$success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
|
||||||
$output = $this->phpci->getLastOutput();
|
$output = $this->phpci->getLastOutput();
|
||||||
|
|
||||||
|
|
|
@ -197,15 +197,8 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
chdir($this->phpci->buildPath.'/'.$this->runFrom);
|
chdir($this->phpci->buildPath.'/'.$this->runFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$phpunit = $this->phpci->findBinary('phpunit');
|
$phpunit = $this->phpci->findBinary('phpunit');
|
||||||
|
|
||||||
if (!$phpunit) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpunit'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$cmd = $phpunit . ' --tap %s -c "%s" ' . $this->coverage . $this->path;
|
$cmd = $phpunit . ' --tap %s -c "%s" ' . $this->coverage . $this->path;
|
||||||
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
|
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $configPath);
|
||||||
|
|
||||||
|
@ -232,11 +225,6 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin
|
||||||
|
|
||||||
$phpunit = $this->phpci->findBinary('phpunit');
|
$phpunit = $this->phpci->findBinary('phpunit');
|
||||||
|
|
||||||
if (!$phpunit) {
|
|
||||||
$this->phpci->logFailure(PHPCI\Helper\Lang::get('could_not_find', 'phpunit'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cmd = $phpunit . ' --tap %s "%s"';
|
$cmd = $phpunit . ' --tap %s "%s"';
|
||||||
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $directory);
|
$success = $this->phpci->executeCommand($cmd, $this->args, $this->phpci->buildPath . $directory);
|
||||||
chdir($curdir);
|
chdir($curdir);
|
||||||
|
|
|
@ -148,12 +148,7 @@ class XMPP implements \PHPCI\Plugin
|
||||||
*/
|
*/
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$sendxmpp = $this->phpci->findBinary('/usr/bin/sendxmpp');
|
$sendxmpp = $this->phpci->findBinary('sendxmpp');
|
||||||
|
|
||||||
if (!$sendxmpp) {
|
|
||||||
$this->phpci->logFailure('Could not find sendxmpp.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Without recipients we can't send notification
|
* Without recipients we can't send notification
|
||||||
|
|
|
@ -27,7 +27,8 @@ class CommandExecutorTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
|
$mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger');
|
||||||
$this->testedExecutor = new UnixCommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/");
|
$class = IS_WIN ? 'PHPCI\Helper\WindowsCommandExecutor' : 'PHPCI\Helper\UnixCommandExecutor';
|
||||||
|
$this->testedExecutor = new $class($mockBuildLogger->reveal(), __DIR__ . "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetLastOutput_ReturnsOutputOfCommand()
|
public function testGetLastOutput_ReturnsOutputOfCommand()
|
||||||
|
@ -63,4 +64,20 @@ class CommandExecutorTest extends \PHPUnit_Framework_TestCase
|
||||||
$returnValue = $this->testedExecutor->findBinary($thisFileName);
|
$returnValue = $this->testedExecutor->findBinary($thisFileName);
|
||||||
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
|
$this->assertEquals(__DIR__ . "/" . $thisFileName, $returnValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Exception
|
||||||
|
* @expectedMessageRegex WorldWidePeace
|
||||||
|
*/
|
||||||
|
public function testFindBinary_ThrowsWhenNotFound()
|
||||||
|
{
|
||||||
|
$thisFileName = "WorldWidePeace";
|
||||||
|
$this->testedExecutor->findBinary($thisFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindBinary_ReturnsNullWihQuietArgument()
|
||||||
|
{
|
||||||
|
$thisFileName = "WorldWidePeace";
|
||||||
|
$this->assertNull($this->testedExecutor->findBinary($thisFileName, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue