From 3ea6b720b1c8dc9c103db3c20248817f009ebb50 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 14:57:22 +0700 Subject: [PATCH 01/12] Few fixes for windows --- PHPCI/Plugin/CleanBuild.php | 3 +++ PHPCI/Plugin/CopyBuild.php | 6 ++++++ PHPCI/Plugin/Wipe.php | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/PHPCI/Plugin/CleanBuild.php b/PHPCI/Plugin/CleanBuild.php index 73a7305f..38c1ccde 100644 --- a/PHPCI/Plugin/CleanBuild.php +++ b/PHPCI/Plugin/CleanBuild.php @@ -38,6 +38,9 @@ class CleanBuild implements \PHPCI\Plugin public function execute() { $cmd = 'rm -Rf "%s"'; + if (IS_WIN) { + $cmd = 'rmdir /S /Q "%s"'; + } $this->phpci->executeCommand($cmd, $this->phpci->buildPath . 'composer.phar'); $this->phpci->executeCommand($cmd, $this->phpci->buildPath . 'composer.lock'); diff --git a/PHPCI/Plugin/CopyBuild.php b/PHPCI/Plugin/CopyBuild.php index 021d5e80..83ed6ebe 100644 --- a/PHPCI/Plugin/CopyBuild.php +++ b/PHPCI/Plugin/CopyBuild.php @@ -46,11 +46,17 @@ class CopyBuild implements \PHPCI\Plugin } $cmd = 'mkdir -p "%s" && cp -R "%s" "%s"'; + if (IS_WIN) { + $cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"'; + } $success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory); if ($this->ignore) { foreach ($this->phpci->ignore as $file) { $cmd = 'rm -Rf "%s/%s"'; + if (IS_WIN) { + $cmd = 'rmdir /S /Q "%s\%s"'; + } $this->phpci->executeCommand($cmd, $this->directory, $file); } } diff --git a/PHPCI/Plugin/Wipe.php b/PHPCI/Plugin/Wipe.php index 7a0c2107..4d55009c 100644 --- a/PHPCI/Plugin/Wipe.php +++ b/PHPCI/Plugin/Wipe.php @@ -52,7 +52,10 @@ class Wipe implements \PHPCI\Plugin return true; } if (is_dir($this->directory)) { - $cmd = 'rm -rf %s*'; + $cmd = 'rm -Rf "%s"'; + if (IS_WIN) { + $cmd = 'rmdir /S /Q "%s"'; + } $success = $this->phpci->executeCommand($cmd, $this->directory); } return $success; From c6feef9da37c9def58a24cf931bb462cde16acd1 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 15:21:53 +0700 Subject: [PATCH 02/12] Fixed phpdocs --- PHPCI/Helper/CommandExecutor.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index dc284b6a..46bead2f 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -2,7 +2,6 @@ namespace PHPCI\Helper; - use \PHPCI\Logging\BuildLogger; use Psr\Log\LogLevel; @@ -36,9 +35,9 @@ class CommandExecutor /** * @param BuildLogger $logger - * @param $rootDir - * @param bool $quiet - * @param bool $verbose + * @param string $rootDir + * @param bool $quiet + * @param bool $verbose */ public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false) { @@ -106,7 +105,7 @@ class CommandExecutor /** * Find a binary required by a plugin. - * @param $binary + * @param string $binary * @return null|string */ public function findBinary($binary) From ac69b13ac1c6762e62bce63596a708d3f451e214 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 15:23:30 +0700 Subject: [PATCH 03/12] Added CommandExecutorInterface --- PHPCI/Helper/CommandExecutorInterface.php | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 PHPCI/Helper/CommandExecutorInterface.php diff --git a/PHPCI/Helper/CommandExecutorInterface.php b/PHPCI/Helper/CommandExecutorInterface.php new file mode 100644 index 00000000..8e75b166 --- /dev/null +++ b/PHPCI/Helper/CommandExecutorInterface.php @@ -0,0 +1,35 @@ + Date: Fri, 9 May 2014 19:09:27 +0700 Subject: [PATCH 04/12] Separeted CommandExecutor for different OS --- PHPCI/Builder.php | 9 +- PHPCI/Helper/BaseCommandExecutor.php | 127 ++++++++++++++++++++++ PHPCI/Helper/CommandExecutor.php | 112 ++----------------- PHPCI/Helper/CommandExecutorInterface.php | 35 ------ PHPCI/Helper/UnixCommandExecutor.php | 33 ++++++ PHPCI/Helper/WindowsCommandExecutor.php | 33 ++++++ vars.php | 4 - 7 files changed, 206 insertions(+), 147 deletions(-) create mode 100644 PHPCI/Helper/BaseCommandExecutor.php delete mode 100644 PHPCI/Helper/CommandExecutorInterface.php create mode 100644 PHPCI/Helper/UnixCommandExecutor.php create mode 100644 PHPCI/Helper/WindowsCommandExecutor.php diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 69db31e1..ced3c510 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -10,7 +10,6 @@ namespace PHPCI; use PHPCI\Helper\BuildInterpolator; -use PHPCI\Helper\CommandExecutor; use PHPCI\Helper\MailerFactory; use PHPCI\Logging\BuildLogger; use PHPCI\Model\Build; @@ -118,7 +117,12 @@ class Builder implements LoggerAwareInterface $pluginFactory->addConfigFromFile(PHPCI_DIR . "/pluginconfig.php"); $this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger); - $this->commandExecutor = new CommandExecutor( + $executorClass = 'PHPCI\Helper\UnixCommandExecutor'; + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { + $executorClass = 'PHPCI\Helper\WindowsCommandExecutor'; + } + + $this->commandExecutor = new $executorClass( $this->buildLogger, PHPCI_DIR, $this->quiet, @@ -126,7 +130,6 @@ class Builder implements LoggerAwareInterface ); $this->interpolator = new BuildInterpolator(); - } /** diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php new file mode 100644 index 00000000..cc4b8ca0 --- /dev/null +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -0,0 +1,127 @@ +logger = $logger; + $this->quiet = $quiet; + $this->verbose = $verbose; + + $this->lastOutput = array(); + + $this->rootDir = $rootDir; + } + + /** + * Executes shell commands. + * @param array $args + * @return bool Indicates success + */ + public function executeCommand($args = array()) + { + $this->lastOutput = array(); + + $command = call_user_func_array('sprintf', $args); + + if ($this->quiet) { + $this->logger->log('Executing: ' . $command); + } + + $status = 0; + exec($command, $this->lastOutput, $status); + + foreach ($this->lastOutput as &$lastOutput) { + $lastOutput = trim($lastOutput, '"'); + } + + if ($this->logExecOutput && !empty($this->lastOutput) && ($this->verbose|| $status != 0)) { + $this->logger->log($this->lastOutput); + } + + $rtn = false; + + if ($status == 0) { + $rtn = true; + } + + return $rtn; + } + + /** + * Returns the output from the last command run. + */ + public function getLastOutput() + { + return implode(PHP_EOL, $this->lastOutput); + } + + /** + * Find a binary required by a plugin. + * @param string $binary + * @return null|string + */ + public function findBinary($binary) + { + $binaryPath = null; + + if (is_string($binary)) { + $binary = array($binary); + } + + foreach ($binary as $bin) { + $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); + // Check project root directory: + if (is_file($this->rootDir . $bin)) { + $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . $bin; + break; + } + + // Check Composer bin dir: + if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { + $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; + break; + } + } + return $binaryPath; + } +} diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index b008c14e..3dce9a44 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -3,131 +3,33 @@ namespace PHPCI\Helper; use \PHPCI\Logging\BuildLogger; -use Psr\Log\LogLevel; -class CommandExecutor +interface CommandExecutor { - /** - * @var \PHPCI\Logging\BuildLogger - */ - protected $logger; - - /** - * @var bool - */ - protected $quiet; - - /** - * @var bool - */ - protected $verbose; - - protected $lastOutput; - - public $logExecOutput = true; - - - /** - * The path which findBinary will look in. - * @var string - */ - protected $rootDir; - /** * @param BuildLogger $logger * @param string $rootDir * @param bool $quiet * @param bool $verbose */ - public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false) - { - $this->logger = $logger; - $this->quiet = $quiet; - $this->verbose = $verbose; - - $this->lastOutput = array(); - - $this->rootDir = $rootDir; - } + public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false); /** - * Executes shell commands. - * @param array $args + * Executes shell commands. Accepts multiple arguments the first + * is the template and everything else is inserted in. c.f. sprintf * @return bool Indicates success */ - public function executeCommand($args = array()) - { - $this->lastOutput = array(); - - $command = call_user_func_array('sprintf', $args); - - if ($this->quiet) { - $this->logger->log('Executing: ' . $command); - } - - $status = 0; - exec($command, $this->lastOutput, $status); - - foreach ($this->lastOutput as &$lastOutput) { - $lastOutput = trim($lastOutput, '"'); - } - - if ($this->logExecOutput && !empty($this->lastOutput) && ($this->verbose|| $status != 0)) { - $this->logger->log($this->lastOutput); - } - - $rtn = false; - - if ($status == 0) { - $rtn = true; - } - - return $rtn; - } + public function executeCommand(); /** * Returns the output from the last command run. */ - public function getLastOutput() - { - return implode(PHP_EOL, $this->lastOutput); - } + public function getLastOutput(); /** * Find a binary required by a plugin. * @param string $binary * @return null|string */ - public function findBinary($binary) - { - if (is_string($binary)) { - $binary = array($binary); - } - - foreach ($binary as $bin) { - $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); - // Check project root directory: - if (is_file($this->rootDir . $bin)) { - $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); - return $this->rootDir . $bin; - } - - // Check Composer bin dir: - if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { - $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); - return $this->rootDir . 'vendor/bin/' . $bin; - } - - // Use "where" for windows and "which" for other OS - $findCmd = IS_WIN ? 'where' : 'which'; - $findCmdResult = trim(shell_exec($findCmd . ' ' . $bin)); - - if (!empty($findCmdResult)) { - $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); - return $findCmdResult; - } - } - - return null; - } + public function findBinary($binary); } diff --git a/PHPCI/Helper/CommandExecutorInterface.php b/PHPCI/Helper/CommandExecutorInterface.php deleted file mode 100644 index 8e75b166..00000000 --- a/PHPCI/Helper/CommandExecutorInterface.php +++ /dev/null @@ -1,35 +0,0 @@ -logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); + $binaryPath = $findCmdResult; + break; + } + } + } + return $binaryPath; + } +} diff --git a/PHPCI/Helper/WindowsCommandExecutor.php b/PHPCI/Helper/WindowsCommandExecutor.php new file mode 100644 index 00000000..ad0ce236 --- /dev/null +++ b/PHPCI/Helper/WindowsCommandExecutor.php @@ -0,0 +1,33 @@ +logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); + $binaryPath = $findCmdResult; + break; + } + } + } + return $binaryPath; + } +} diff --git a/vars.php b/vars.php index 2408d41d..5725805e 100644 --- a/vars.php +++ b/vars.php @@ -25,7 +25,3 @@ if (!defined('ENABLE_SHELL_PLUGIN')) { if (!defined('PHPCI_IS_CONSOLE')) { define('PHPCI_IS_CONSOLE', false); } - -if (!defined('IS_WIN')) { - define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false)); -} From 3174ec1e0b49611779b9c1847f54d150095983e8 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 23:41:26 +0700 Subject: [PATCH 05/12] Added Sqlite plugin --- PHPCI/Plugin/Sqlite.php | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 PHPCI/Plugin/Sqlite.php diff --git a/PHPCI/Plugin/Sqlite.php b/PHPCI/Plugin/Sqlite.php new file mode 100644 index 00000000..4753b6e7 --- /dev/null +++ b/PHPCI/Plugin/Sqlite.php @@ -0,0 +1,81 @@ + +* @package PHPCI +* @subpackage Plugins +*/ +class Sqlite implements \PHPCI\Plugin +{ + /** + * @var \PHPCI\Builder + */ + protected $phpci; + + /** + * @var \PHPCI\Model\Build + */ + protected $build; + + /** + * @var array + */ + protected $queries = array(); + + /** + * @var string + */ + protected $path; + + /** + * @param Builder $phpci + * @param Build $build + * @param array $options + */ + public function __construct(Builder $phpci, Build $build, array $options = array()) + { + $this->phpci = $phpci; + $this->build = $build; + $this->queries = $options; + $buildSettings = $phpci->getConfig('build_settings'); + + if (isset($buildSettings['sqlite'])) { + $sql = $buildSettings['sqlite']; + $this->path = $sql['path']; + } + } + + /** + * Connects to SQLite and runs a specified set of queries. + * @return boolean + */ + public function execute() + { + try { + $opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); + $pdo = new PDO('sqlite:' . $this->path, $opts); + + foreach ($this->queries as $query) { + $pdo->query($query); + } + } catch (\Exception $ex) { + $this->phpci->logFailure($ex->getMessage()); + return false; + } + return true; + } +} From 47b5dea03c09c3f9b994c66dec3286174574a681 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 23:49:20 +0700 Subject: [PATCH 06/12] Small fixes for SQL plugins (phpdocs, some fixes) --- PHPCI/Plugin.php | 1 - PHPCI/Plugin/Mysql.php | 42 +++++++++++++++++++++++++++++++----------- PHPCI/Plugin/Pgsql.php | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/PHPCI/Plugin.php b/PHPCI/Plugin.php index 6f915e3b..d4e90ef0 100644 --- a/PHPCI/Plugin.php +++ b/PHPCI/Plugin.php @@ -9,7 +9,6 @@ namespace PHPCI; -use PHPCI\Builder; use PHPCI\Model\Build; /** diff --git a/PHPCI/Plugin/Mysql.php b/PHPCI/Plugin/Mysql.php index c66f77cb..d2a4314e 100755 --- a/PHPCI/Plugin/Mysql.php +++ b/PHPCI/Plugin/Mysql.php @@ -22,24 +22,41 @@ use PHPCI\Model\Build; */ class Mysql implements \PHPCI\Plugin { - /** * @var \PHPCI\Builder */ protected $phpci; + + /** + * @var \PHPCI\Model\Build + */ protected $build; + + /** + * @var array + */ protected $queries = array(); + /** + * @var string + */ protected $host; + + /** + * @var string + */ protected $user; + + /** + * @var string + */ protected $pass; /** - * Database Connection - * @var PDO + * @param Builder $phpci + * @param Build $build + * @param array $options */ - protected $pdo; - public function __construct(Builder $phpci, Build $build, array $options = array()) { $this->phpci = $phpci; @@ -74,19 +91,18 @@ class Mysql implements \PHPCI\Plugin /** * Connects to MySQL and runs a specified set of queries. + * @return boolean */ public function execute() { - $success = true; - try { $opts = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); - $this->pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts); + $pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts); foreach ($this->queries as $query) { if (!is_array($query)) { // Simple query - $this->pdo->query($this->phpci->interpolate($query)); + $pdo->query($this->phpci->interpolate($query)); } elseif (isset($query['import'])) { // SQL file execution $this->executeFile($query['import']); @@ -98,10 +114,14 @@ class Mysql implements \PHPCI\Plugin $this->phpci->logFailure($ex->getMessage()); return false; } - - return $success; + return true; } + /** + * @param string $query + * @return boolean + * @throws \Exception + */ protected function executeFile($query) { if (!isset($query['file'])) { diff --git a/PHPCI/Plugin/Pgsql.php b/PHPCI/Plugin/Pgsql.php index a05068d2..e4001132 100644 --- a/PHPCI/Plugin/Pgsql.php +++ b/PHPCI/Plugin/Pgsql.php @@ -21,18 +21,45 @@ use PHPCI\Model\Build; */ class Pgsql implements \PHPCI\Plugin { + /** + * @var \PHPCI\Builder + */ protected $phpci; + + /** + * @var \PHPCI\Model\Build + */ protected $build; + + /** + * @var array + */ protected $queries = array(); + /** + * @var string + */ protected $host; + + /** + * @var string + */ protected $user; + + /** + * @var string + */ protected $pass; + /** + * @param Builder $phpci + * @param Build $build + * @param array $options + */ public function __construct(Builder $phpci, Build $build, array $options = array()) { - $this->phpci = $phpci; - $this->build = $build; + $this->phpci = $phpci; + $this->build = $build; $this->queries = $options; $buildSettings = $phpci->getConfig('build_settings'); @@ -47,6 +74,7 @@ class Pgsql implements \PHPCI\Plugin /** * Connects to PgSQL and runs a specified set of queries. + * @return boolean */ public function execute() { @@ -61,7 +89,6 @@ class Pgsql implements \PHPCI\Plugin $this->phpci->logFailure($ex->getMessage()); return false; } - return true; } } From a6cbd7cad8612a31e2a8b96c3c64063457fc6462 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Fri, 9 May 2014 23:55:13 +0700 Subject: [PATCH 07/12] Fixes --- PHPCI/Builder.php | 2 +- vars.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index ced3c510..7365f42f 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -118,7 +118,7 @@ class Builder implements LoggerAwareInterface $this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger); $executorClass = 'PHPCI\Helper\UnixCommandExecutor'; - if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { + if (IS_WIN) { $executorClass = 'PHPCI\Helper\WindowsCommandExecutor'; } diff --git a/vars.php b/vars.php index 5725805e..2408d41d 100644 --- a/vars.php +++ b/vars.php @@ -25,3 +25,7 @@ if (!defined('ENABLE_SHELL_PLUGIN')) { if (!defined('PHPCI_IS_CONSOLE')) { define('PHPCI_IS_CONSOLE', false); } + +if (!defined('IS_WIN')) { + define('IS_WIN', ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false)); +} From 174a9ee95ec607603c38a396000d4807af4fa151 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sat, 10 May 2014 21:06:16 +0700 Subject: [PATCH 08/12] Fixed public key text outinf of panel border --- public/assets/css/phpci.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/assets/css/phpci.css b/public/assets/css/phpci.css index 7093c2aa..ce98017a 100644 --- a/public/assets/css/phpci.css +++ b/public/assets/css/phpci.css @@ -80,4 +80,8 @@ h1 { position: absolute; right: 25px; width: 200px; +} + +.panel-body { + overflow: auto; } \ No newline at end of file From 940c1841ffe5e9a72744d1a3375ddec07e7defe4 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 11 May 2014 22:38:33 +0700 Subject: [PATCH 09/12] Pull request review fixes --- PHPCI/Helper/BaseCommandExecutor.php | 32 +++------------------- PHPCI/Helper/CommandExecutor.php | 10 ------- PHPCI/Helper/UnixCommandExecutor.php | 35 +++++++++++++++++-------- PHPCI/Helper/WindowsCommandExecutor.php | 35 +++++++++++++++++-------- 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index cc4b8ca0..08364606 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -3,9 +3,8 @@ namespace PHPCI\Helper; use \PHPCI\Logging\BuildLogger; -use Psr\Log\LogLevel; -class BaseCommandExecutor implements CommandExecutor +abstract class BaseCommandExecutor implements CommandExecutor { /** * @var \PHPCI\Logging\BuildLogger @@ -98,30 +97,5 @@ class BaseCommandExecutor implements CommandExecutor * @param string $binary * @return null|string */ - public function findBinary($binary) - { - $binaryPath = null; - - if (is_string($binary)) { - $binary = array($binary); - } - - foreach ($binary as $bin) { - $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); - // Check project root directory: - if (is_file($this->rootDir . $bin)) { - $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); - $binaryPath = $this->rootDir . $bin; - break; - } - - // Check Composer bin dir: - if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { - $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); - $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; - break; - } - } - return $binaryPath; - } -} + abstract public function findBinary($binary); +} \ No newline at end of file diff --git a/PHPCI/Helper/CommandExecutor.php b/PHPCI/Helper/CommandExecutor.php index 3dce9a44..633618bb 100644 --- a/PHPCI/Helper/CommandExecutor.php +++ b/PHPCI/Helper/CommandExecutor.php @@ -2,18 +2,8 @@ namespace PHPCI\Helper; -use \PHPCI\Logging\BuildLogger; - interface CommandExecutor { - /** - * @param BuildLogger $logger - * @param string $rootDir - * @param bool $quiet - * @param bool $verbose - */ - public function __construct(BuildLogger $logger, $rootDir, &$quiet = false, &$verbose = false); - /** * Executes shell commands. Accepts multiple arguments the first * is the template and everything else is inserted in. c.f. sprintf diff --git a/PHPCI/Helper/UnixCommandExecutor.php b/PHPCI/Helper/UnixCommandExecutor.php index 208ebb33..5ab0fbc0 100644 --- a/PHPCI/Helper/UnixCommandExecutor.php +++ b/PHPCI/Helper/UnixCommandExecutor.php @@ -2,6 +2,8 @@ namespace PHPCI\Helper; +use Psr\Log\LogLevel; + class UnixCommandExecutor extends BaseCommandExecutor { /** @@ -11,21 +13,32 @@ class UnixCommandExecutor extends BaseCommandExecutor */ public function findBinary($binary) { - $binaryPath = parent::findBinary($binary); - if (is_null($binaryPath)) { + $binaryPath = null; - if (is_string($binary)) { - $binary = array($binary); + if (is_string($binary)) { + $binary = array($binary); + } + + foreach ($binary as $bin) { + $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); + + if (is_file($this->rootDir . $bin)) { + $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . $bin; + break; } - foreach ($binary as $bin) { - $findCmdResult = trim(shell_exec('which ' . $bin)); + if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { + $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; + break; + } - if (!empty($findCmdResult)) { - $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); - $binaryPath = $findCmdResult; - break; - } + $findCmdResult = trim(shell_exec('which ' . $bin)); + if (!empty($findCmdResult)) { + $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); + $binaryPath = $findCmdResult; + break; } } return $binaryPath; diff --git a/PHPCI/Helper/WindowsCommandExecutor.php b/PHPCI/Helper/WindowsCommandExecutor.php index ad0ce236..83136d2a 100644 --- a/PHPCI/Helper/WindowsCommandExecutor.php +++ b/PHPCI/Helper/WindowsCommandExecutor.php @@ -2,6 +2,8 @@ namespace PHPCI\Helper; +use Psr\Log\LogLevel; + class WindowsCommandExecutor extends BaseCommandExecutor { /** @@ -11,21 +13,32 @@ class WindowsCommandExecutor extends BaseCommandExecutor */ public function findBinary($binary) { - $binaryPath = parent::findBinary($binary); - if (is_null($binaryPath)) { + $binaryPath = null; - if (is_string($binary)) { - $binary = array($binary); + if (is_string($binary)) { + $binary = array($binary); + } + + foreach ($binary as $bin) { + $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); + + if (is_file($this->rootDir . $bin)) { + $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . $bin; + break; } - foreach ($binary as $bin) { - $findCmdResult = trim(shell_exec('where ' . $bin)); + if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { + $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); + $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; + break; + } - if (!empty($findCmdResult)) { - $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); - $binaryPath = $findCmdResult; - break; - } + $findCmdResult = trim(shell_exec('where ' . $bin)); + if (!empty($findCmdResult)) { + $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); + $binaryPath = $findCmdResult; + break; } } return $binaryPath; From 3fe7c18e0902d2a9665084012aeec24bdbe1b764 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 12 May 2014 00:43:41 +0700 Subject: [PATCH 10/12] Repaired tests for CommandExecutor --- Tests/PHPCI/Helper/CommandExecutorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/PHPCI/Helper/CommandExecutorTest.php b/Tests/PHPCI/Helper/CommandExecutorTest.php index ae6809d5..f911b994 100644 --- a/Tests/PHPCI/Helper/CommandExecutorTest.php +++ b/Tests/PHPCI/Helper/CommandExecutorTest.php @@ -2,7 +2,7 @@ namespace PHPCI\Plugin\Tests\Helper; -use PHPCI\Helper\CommandExecutor; +use PHPCI\Helper\UnixCommandExecutor; use \Prophecy\PhpUnit\ProphecyTestCase; class CommandExecutorTest extends ProphecyTestCase @@ -16,7 +16,7 @@ class CommandExecutorTest extends ProphecyTestCase { parent::setUp(); $mockBuildLogger = $this->prophesize('PHPCI\Logging\BuildLogger'); - $this->testedExecutor = new CommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/"); + $this->testedExecutor = new UnixCommandExecutor($mockBuildLogger->reveal(), __DIR__ . "/"); } public function testGetLastOutput_ReturnsOutputOfCommand() From 6a1732c5b7d1a271f4a18506ba84d76a73373080 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 12 May 2014 00:44:13 +0700 Subject: [PATCH 11/12] Fixed annotation --- Tests/PHPCI/Helper/CommandExecutorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/PHPCI/Helper/CommandExecutorTest.php b/Tests/PHPCI/Helper/CommandExecutorTest.php index f911b994..8ae045dc 100644 --- a/Tests/PHPCI/Helper/CommandExecutorTest.php +++ b/Tests/PHPCI/Helper/CommandExecutorTest.php @@ -8,7 +8,7 @@ use \Prophecy\PhpUnit\ProphecyTestCase; class CommandExecutorTest extends ProphecyTestCase { /** - * @var CommandExecutor + * @var UnixCommandExecutor */ protected $testedExecutor; From 176000f1bdbdce7bd4cb07c1eeee7af7821c6c0f Mon Sep 17 00:00:00 2001 From: "steve.brazier" Date: Mon, 12 May 2014 09:07:27 +0100 Subject: [PATCH 12/12] Add missing newline to end of BaseCommandExecutor. --- PHPCI/Helper/BaseCommandExecutor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPCI/Helper/BaseCommandExecutor.php b/PHPCI/Helper/BaseCommandExecutor.php index 08364606..7dbd7b18 100644 --- a/PHPCI/Helper/BaseCommandExecutor.php +++ b/PHPCI/Helper/BaseCommandExecutor.php @@ -98,4 +98,4 @@ abstract class BaseCommandExecutor implements CommandExecutor * @return null|string */ abstract public function findBinary($binary); -} \ No newline at end of file +}