From 82e73281e45849d7eb15f226fbc9b572560aba7e Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Sun, 10 Jul 2016 14:05:10 +0600 Subject: [PATCH] Improved build log, added more debug info --- src/PHPCI/Builder.php | 36 ++++++++++++----- src/PHPCI/Helper/Email.php | 7 +++- src/PHPCI/Languages/lang.en.php | 40 +++++++++++++++---- src/PHPCI/Languages/lang.ru.php | 40 +++++++++++++++---- src/PHPCI/Logging/BuildLogger.php | 8 +--- src/PHPCI/Model/Base/BuildBase.php | 36 ++++++++--------- src/PHPCI/Model/Build.php | 13 ++++++ src/PHPCI/Plugin/Behat.php | 2 + src/PHPCI/Plugin/Campfire.php | 1 - src/PHPCI/Plugin/CleanBuild.php | 2 + src/PHPCI/Plugin/Codeception.php | 2 + src/PHPCI/Plugin/Composer.php | 2 + src/PHPCI/Plugin/CopyBuild.php | 2 + src/PHPCI/Plugin/Email.php | 53 ++++++++++++++++--------- src/PHPCI/Plugin/Env.php | 6 ++- src/PHPCI/Plugin/Git.php | 6 ++- src/PHPCI/Plugin/Grunt.php | 2 + src/PHPCI/Plugin/Gulp.php | 2 + src/PHPCI/Plugin/HipchatNotify.php | 1 - src/PHPCI/Plugin/Irc.php | 2 + src/PHPCI/Plugin/Lint.php | 2 + src/PHPCI/Plugin/Mysql.php | 2 + src/PHPCI/Plugin/PackageBuild.php | 2 + src/PHPCI/Plugin/Pdepend.php | 2 + src/PHPCI/Plugin/Pgsql.php | 2 + src/PHPCI/Plugin/Phar.php | 2 + src/PHPCI/Plugin/PhpCodeSniffer.php | 2 + src/PHPCI/Plugin/PhpCpd.php | 2 + src/PHPCI/Plugin/PhpCsFixer.php | 2 + src/PHPCI/Plugin/PhpDocblockChecker.php | 2 + src/PHPCI/Plugin/PhpLoc.php | 2 + src/PHPCI/Plugin/PhpMessDetector.php | 2 + src/PHPCI/Plugin/PhpParallelLint.php | 2 + src/PHPCI/Plugin/PhpSpec.php | 6 ++- src/PHPCI/Plugin/PhpTalLint.php | 2 + src/PHPCI/Plugin/PhpUnit.php | 2 + src/PHPCI/Plugin/Shell.php | 2 + src/PHPCI/Plugin/Sqlite.php | 2 + src/PHPCI/Plugin/TechnicalDebt.php | 2 + src/PHPCI/Plugin/Util/Executor.php | 18 ++++++--- src/PHPCI/Plugin/Util/Factory.php | 9 ----- src/PHPCI/Plugin/Wipe.php | 2 + src/PHPCI/Plugin/Xmpp.php | 2 + 43 files changed, 248 insertions(+), 88 deletions(-) diff --git a/src/PHPCI/Builder.php b/src/PHPCI/Builder.php index c11e3508..11a9e36a 100644 --- a/src/PHPCI/Builder.php +++ b/src/PHPCI/Builder.php @@ -220,32 +220,37 @@ class Builder implements LoggerAwareInterface if ($previous_state == Build::STATUS_FAILED) { $this->pluginExecutor->executePlugins($this->config, 'fixed'); } - - $this->buildLogger->logSuccess(Lang::get('build_success')); } else { $this->pluginExecutor->executePlugins($this->config, 'failure'); if ($previous_state == Build::STATUS_SUCCESS || $previous_state == Build::STATUS_NEW) { $this->pluginExecutor->executePlugins($this->config, 'broken'); } - - $this->buildLogger->logFailure(Lang::get('build_failed')); } } catch (\Exception $ex) { $this->build->setStatus(Build::STATUS_FAILED); $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); - }finally{ - // Complete stage plugins are always run - $this->pluginExecutor->executePlugins($this->config, 'complete'); + } + + if (Build::STATUS_FAILED === $this->build->getStatus()) { + $this->buildLogger->logFailure("\n" . Lang::get('build_failed')); + } else { + $this->buildLogger->logSuccess("\n" . Lang::get('build_success')); } + try { + // Complete stage plugins are always run + $this->pluginExecutor->executePlugins($this->config, 'complete'); + } catch (\Exception $ex) { + $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); + } // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback(); $this->build->setFinished(new \DateTime()); // Clean up: - $this->buildLogger->log(Lang::get('removing_build')); + $this->buildLogger->log("\n" . Lang::get('removing_build')); $this->build->removeBuildDirectory(); $this->store->save($this->build); @@ -355,8 +360,9 @@ class Builder implements LoggerAwareInterface $this->buildLogger->log($message, $level, $context); } - /** + /** * Add a success-coloured message to the log. + * * @param string */ public function logSuccess($message) @@ -366,6 +372,7 @@ class Builder implements LoggerAwareInterface /** * Add a failure-coloured message to the log. + * * @param string $message * @param \Exception $exception The exception that caused the error. */ @@ -373,6 +380,17 @@ class Builder implements LoggerAwareInterface { $this->buildLogger->logFailure($message, $exception); } + + /** + * Add a debug message to the log. + * + * @param string + */ + public function logDebug($message) + { + $this->buildLogger->logDebug($message); + } + /** * Returns a configured instance of the plugin factory. * diff --git a/src/PHPCI/Helper/Email.php b/src/PHPCI/Helper/Email.php index f9523007..b06cdc3e 100644 --- a/src/PHPCI/Helper/Email.php +++ b/src/PHPCI/Helper/Email.php @@ -10,6 +10,7 @@ namespace PHPCI\Helper; use b8\Config; +use PHPCI\Builder; /** * Helper class for sending emails using PHPCI's email configuration. @@ -98,11 +99,15 @@ class Email /** * Send the email. + * + * @param Builder $phpci + * * @return bool|int */ - public function send() + public function send(Builder $phpci) { $smtpServer = $this->config->get('phpci.email_settings.smtp_address'); + $phpci->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false')); if (empty($smtpServer)) { return $this->sendViaMail(); diff --git a/src/PHPCI/Languages/lang.en.php b/src/PHPCI/Languages/lang.en.php index fa4e3950..2867b746 100644 --- a/src/PHPCI/Languages/lang.en.php +++ b/src/PHPCI/Languages/lang.en.php @@ -195,15 +195,12 @@ PHPCI', 'phpdoccheck_warnings' => 'Missing Docblocks', 'issues' => 'Issues', - 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Missing Docblocks', 'phpmd' => 'PHP Mess Detector', 'phpspec' => 'PHP Spec', 'phpunit' => 'PHP Unit', - 'technical_debt' => 'Technical Debt', - 'behat' => 'Behat', 'codeception_feature' => 'Feature', 'codeception_suite' => 'Suite', @@ -419,6 +416,7 @@ PHPCI', 'plugin_missing' => 'Plugin does not exist: %s', 'tap_version' => 'TapParser only supports TAP version 13', 'tap_error' => 'Invalid TAP string, number of tests does not match specified test count.', + 'failed_allowed' => 'Allowed', // Build Plugins: 'no_tests_performed' => 'No tests have been performed.', @@ -453,9 +451,37 @@ PHPCI', 'low' => 'Low', // Plugins that generate errors: - 'php_mess_detector' => 'PHP Mess Detector', - 'php_code_sniffer' => 'PHP Code Sniffer', - 'php_unit' => 'PHP Unit', - 'php_cpd' => 'PHP Copy/Paste Detector', + 'php_mess_detector' => 'PHP Mess Detector', + 'php_code_sniffer' => 'PHP Code Sniffer', + 'php_unit' => 'PHP Unit', + 'php_cpd' => 'PHP Copy/Paste Detector', 'php_docblock_checker' => 'PHP Docblock Checker', + 'composer' => 'Composer', + 'php_loc' => 'PHPLOC', + 'php_parallel_lint' => 'PHP Parallel Lint', + 'email' => 'Email', + 'atoum' => 'Atoum', + 'behat' => 'Behat', + 'campfire' => 'Campfire', + 'clean_build' => 'Clean Build', + 'codeception' => 'Codeception', + 'copy_build' => 'Copy Build', + 'deployer' => 'Deployer', + 'env' => 'Env', + 'grunt' => 'Grunt', + 'hipchat_notify' => 'Hipchat', + 'irc' => 'IRC', + 'lint' => 'Lint', + 'mysql' => 'MySQL', + 'package_build' => 'Package Build', + 'pdepend' => 'PDepend', + 'pgsql' => 'PostgreSQL', + 'phar' => 'Phar', + 'phing' => 'Phing', + 'php_cs_fixer' => 'PHP Coding Standards Fixer', + 'php_spec' => 'PHP Spec', + 'shell' => 'Shell', + 'slack_notify' => 'Slack', + 'technical_debt' => 'Technical Debt', + 'xmpp' => 'XMPP', ]; diff --git a/src/PHPCI/Languages/lang.ru.php b/src/PHPCI/Languages/lang.ru.php index 3be4a77b..9d960f99 100644 --- a/src/PHPCI/Languages/lang.ru.php +++ b/src/PHPCI/Languages/lang.ru.php @@ -187,15 +187,12 @@ PHPCI', 'phpdoccheck_warnings' => 'Пропущенные Docblocks', 'issues' => 'Проблемы', - 'codeception' => 'Codeception', 'phpcpd' => 'PHP Copy/Paste Detector', 'phpcs' => 'PHP Code Sniffer', 'phpdoccheck' => 'Missing Docblocks', 'phpmd' => 'PHP Mess Detector', 'phpspec' => 'PHP Spec', 'phpunit' => 'PHP Unit', - 'technical_debt' => 'Технические долги', - 'behat' => 'Behat', 'codeception_feature' => 'Свойство', 'codeception_suite' => 'Набор', @@ -405,6 +402,7 @@ PHPCI', 'plugin_missing' => 'Плагина не существует: %s', 'tap_version' => 'TapParser поддерживает только TAP версии 13', 'tap_error' => 'Некорректная TAP-строка, количество тестов не совпадает с заявленным.', + 'failed_allowed' => 'Разрешен', // Build Plugins: 'no_tests_performed' => 'Никакие тесты не были запущены.', @@ -438,9 +436,37 @@ PHPCI', 'low' => 'Низкий', // Plugins that generate errors: - 'php_mess_detector' => 'PHP Mess Detector', - 'php_code_sniffer' => 'PHP Code Sniffer', - 'php_unit' => 'PHP Unit', - 'php_cpd' => 'PHP Copy/Paste Detector', + 'php_mess_detector' => 'PHP Mess Detector', + 'php_code_sniffer' => 'PHP Code Sniffer', + 'php_unit' => 'PHP Unit', + 'php_cpd' => 'PHP Copy/Paste Detector', 'php_docblock_checker' => 'PHP Docblock Checker', + 'composer' => 'Composer', + 'php_loc' => 'PHPLOC', + 'php_parallel_lint' => 'PHP Parallel Lint', + 'email' => 'Email', + 'atoum' => 'Atoum', + 'behat' => 'Behat', + 'campfire' => 'Campfire', + 'clean_build' => 'Clean Build', + 'codeception' => 'Codeception', + 'copy_build' => 'Copy Build', + 'deployer' => 'Deployer', + 'env' => 'Env', + 'grunt' => 'Grunt', + 'hipchat_notify' => 'Hipchat', + 'irc' => 'IRC', + 'lint' => 'Lint', + 'mysql' => 'MySQL', + 'package_build' => 'Package Build', + 'pdepend' => 'PDepend', + 'pgsql' => 'PostgreSQL', + 'phar' => 'Phar', + 'phing' => 'Phing', + 'php_cs_fixer' => 'PHP Coding Standards Fixer', + 'php_spec' => 'PHP Spec', + 'shell' => 'Shell', + 'slack_notify' => 'Slack', + 'technical_debt' => 'Technical Debt', + 'xmpp' => 'XMPP', ]; diff --git a/src/PHPCI/Logging/BuildLogger.php b/src/PHPCI/Logging/BuildLogger.php index 509aade6..ddaeb61b 100644 --- a/src/PHPCI/Logging/BuildLogger.php +++ b/src/PHPCI/Logging/BuildLogger.php @@ -91,11 +91,7 @@ class BuildLogger implements LoggerAwareInterface $context['exception'] = $exception; } - $this->log( - "\033[0;31m" . $message . "\033[0m", - LogLevel::ERROR, - $context - ); + $this->log("\033[0;31m" . $message . "\033[0m", LogLevel::ERROR, $context); } /** @@ -105,7 +101,7 @@ class BuildLogger implements LoggerAwareInterface public function logDebug($message) { if (defined('PHPCI_DEBUG_MODE') && PHPCI_DEBUG_MODE) { - $this->log("\033[0;33m" . $message . "\033[0m"); + $this->log("\033[0;36m" . $message . "\033[0m"); } } diff --git a/src/PHPCI/Model/Base/BuildBase.php b/src/PHPCI/Model/Base/BuildBase.php index 632f5a69..02c804dd 100644 --- a/src/PHPCI/Model/Base/BuildBase.php +++ b/src/PHPCI/Model/Base/BuildBase.php @@ -190,7 +190,7 @@ class BuildBase extends Model */ public function getId() { - $rtn = $this->data['id']; + $rtn = $this->data['id']; return $rtn; } @@ -202,7 +202,7 @@ class BuildBase extends Model */ public function getProjectId() { - $rtn = $this->data['project_id']; + $rtn = $this->data['project_id']; return $rtn; } @@ -214,7 +214,7 @@ class BuildBase extends Model */ public function getCommitId() { - $rtn = $this->data['commit_id']; + $rtn = $this->data['commit_id']; return $rtn; } @@ -226,7 +226,7 @@ class BuildBase extends Model */ public function getStatus() { - $rtn = $this->data['status']; + $rtn = $this->data['status']; return $rtn; } @@ -238,7 +238,7 @@ class BuildBase extends Model */ public function getLog() { - $rtn = $this->data['log']; + $rtn = $this->data['log']; return $rtn; } @@ -250,7 +250,7 @@ class BuildBase extends Model */ public function getBranch() { - $rtn = $this->data['branch']; + $rtn = $this->data['branch']; return $rtn; } @@ -262,10 +262,10 @@ class BuildBase extends Model */ public function getCreated() { - $rtn = $this->data['created']; + $rtn = $this->data['created']; if (!empty($rtn)) { - $rtn = new \DateTime($rtn); + $rtn = new \DateTime($rtn); } return $rtn; @@ -278,10 +278,10 @@ class BuildBase extends Model */ public function getStarted() { - $rtn = $this->data['started']; + $rtn = $this->data['started']; if (!empty($rtn)) { - $rtn = new \DateTime($rtn); + $rtn = new \DateTime($rtn); } return $rtn; @@ -294,10 +294,10 @@ class BuildBase extends Model */ public function getFinished() { - $rtn = $this->data['finished']; + $rtn = $this->data['finished']; if (!empty($rtn)) { - $rtn = new \DateTime($rtn); + $rtn = new \DateTime($rtn); } return $rtn; @@ -310,7 +310,7 @@ class BuildBase extends Model */ public function getCommitterEmail() { - $rtn = $this->data['committer_email']; + $rtn = $this->data['committer_email']; return $rtn; } @@ -322,7 +322,7 @@ class BuildBase extends Model */ public function getCommitMessage() { - $rtn = $this->data['commit_message']; + $rtn = $this->data['commit_message']; return $rtn; } @@ -334,7 +334,7 @@ class BuildBase extends Model */ public function getExtra() { - $rtn = $this->data['extra']; + $rtn = $this->data['extra']; return $rtn; } @@ -580,11 +580,11 @@ class BuildBase extends Model return null; } - $cacheKey = 'Cache.Project.' . $key; - $rtn = $this->cache->get($cacheKey, null); + $cacheKey = 'Cache.Project.' . $key; + $rtn = $this->cache->get($cacheKey, null); if (empty($rtn)) { - $rtn = Factory::getStore('Project', 'PHPCI')->getById($key); + $rtn = Factory::getStore('Project', 'PHPCI')->getById($key); $this->cache->set($cacheKey, $rtn); } diff --git a/src/PHPCI/Model/Build.php b/src/PHPCI/Model/Build.php index 6b3322fc..499926a0 100644 --- a/src/PHPCI/Model/Build.php +++ b/src/PHPCI/Model/Build.php @@ -298,4 +298,17 @@ class Build extends BuildBase return $end->getTimestamp() - $start->getTimestamp(); } + + /** + * Create a working copy by cloning, copying, or similar. + * + * @param Builder $builder + * @param string $buildPath + * + * @return boolean + */ + public function createWorkingCopy(Builder $builder, $buildPath) + { + return false; + } } diff --git a/src/PHPCI/Plugin/Behat.php b/src/PHPCI/Plugin/Behat.php index b5a2b338..5bf4d372 100644 --- a/src/PHPCI/Plugin/Behat.php +++ b/src/PHPCI/Plugin/Behat.php @@ -54,6 +54,8 @@ class Behat implements Plugin if (!empty($options['features'])) { $this->features = $options['features']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Campfire.php b/src/PHPCI/Plugin/Campfire.php index 50a862a0..666ff9e8 100644 --- a/src/PHPCI/Plugin/Campfire.php +++ b/src/PHPCI/Plugin/Campfire.php @@ -55,7 +55,6 @@ class Campfire implements Plugin } else { throw new \Exception(Lang::get('no_campfire_settings')); } - } /** diff --git a/src/PHPCI/Plugin/CleanBuild.php b/src/PHPCI/Plugin/CleanBuild.php index 21ec7ef8..e537af39 100644 --- a/src/PHPCI/Plugin/CleanBuild.php +++ b/src/PHPCI/Plugin/CleanBuild.php @@ -43,6 +43,8 @@ class CleanBuild implements Plugin $this->phpci = $phpci; $this->build = $build; $this->remove = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : []; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Codeception.php b/src/PHPCI/Plugin/Codeception.php index 1f08dfa1..c7f160ac 100644 --- a/src/PHPCI/Plugin/Codeception.php +++ b/src/PHPCI/Plugin/Codeception.php @@ -98,6 +98,8 @@ class Codeception implements Plugin, ZeroConfigPlugin if (isset($options['path'])) { $this->path = $options['path']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Composer.php b/src/PHPCI/Plugin/Composer.php index b37c3fe4..46ef1ec9 100644 --- a/src/PHPCI/Plugin/Composer.php +++ b/src/PHPCI/Plugin/Composer.php @@ -90,6 +90,8 @@ class Composer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin if (array_key_exists('ignore_platform_reqs', $options)) { $this->ignorePlatformReqs = (bool)$options['ignore_platform_reqs']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/CopyBuild.php b/src/PHPCI/Plugin/CopyBuild.php index 6552048f..c1ffb216 100644 --- a/src/PHPCI/Plugin/CopyBuild.php +++ b/src/PHPCI/Plugin/CopyBuild.php @@ -42,6 +42,8 @@ class CopyBuild implements Plugin $this->directory = isset($options['directory']) ? $options['directory'] : $path; $this->wipe = isset($options['wipe']) ? (bool)$options['wipe'] : false; $this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Email.php b/src/PHPCI/Plugin/Email.php index a22ec1fb..cdd370dd 100644 --- a/src/PHPCI/Plugin/Email.php +++ b/src/PHPCI/Plugin/Email.php @@ -43,18 +43,16 @@ class Email implements Plugin /** * Set up the plugin, configure options, etc. * @param Builder $phpci - * @param Build $build - * @param \Swift_Mailer $mailer - * @param array $options + * @param Build $build + * @param array $options */ - public function __construct( - Builder $phpci, - Build $build, - array $options = [] - ) { + public function __construct(Builder $phpci, Build $build, array $options = []) + { $this->phpci = $phpci; $this->build = $build; $this->options = $options; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** @@ -83,14 +81,14 @@ class Email implements Plugin $view = $this->getDefaultMailTemplate(); } - $view->build = $this->build; + $view->build = $this->build; $view->project = $this->build->getProject(); - $layout = new View('Email/layout'); - $layout->build = $this->build; + $layout = new View('Email/layout'); + $layout->build = $this->build; $layout->project = $this->build->getProject(); $layout->content = $view->render(); - $body = $layout->render(); + $body = $layout->render(); $sendFailures = $this->sendSeparateEmails( $addresses, @@ -127,7 +125,7 @@ class Email implements Plugin } } - return $email->send(); + return $email->send($this->phpci); } /** @@ -145,13 +143,14 @@ class Email implements Plugin public function sendSeparateEmails(array $toAddresses, $subject, $body) { $failures = 0; - $ccList = $this->getCcAddresses(); + $ccList = $this->getCcAddresses(); foreach ($toAddresses as $address) { if (!$this->sendEmail($address, $ccList, $subject, $body)) { $failures++; } } + return $failures; } @@ -164,17 +163,35 @@ class Email implements Plugin $addresses = []; $committer = $this->build->getCommitterEmail(); - if (isset($this->options['committer']) && !empty($committer)) { - $addresses[] = $committer; + $this->phpci->logDebug(sprintf("Committer email: '%s'", $committer)); + $this->phpci->logDebug(sprintf( + "Committer option: '%s'", + (!empty($this->options['committer']) && $this->options['committer']) ? 'true' : 'false' + )); + + if (!empty($this->options['committer']) && $this->options['committer']) { + if ($committer) { + $addresses[] = $committer; + } } - if (isset($this->options['addresses'])) { + $this->phpci->logDebug(sprintf( + "Addresses option: '%s'", + (!empty($this->options['addresses']) && is_array($this->options['addresses'])) ? implode(', ', $this->options['addresses']) : 'false' + )); + + if (!empty($this->options['addresses']) && is_array($this->options['addresses'])) { foreach ($this->options['addresses'] as $address) { $addresses[] = $address; } } - if (empty($addresses) && isset($this->options['default_mailto_address'])) { + $this->phpci->logDebug(sprintf( + "Default mailTo option: '%s'", + !empty($this->options['default_mailto_address']) ? $this->options['default_mailto_address'] : 'false' + )); + + if (empty($addresses) && !empty($this->options['default_mailto_address'])) { $addresses[] = $this->options['default_mailto_address']; } diff --git a/src/PHPCI/Plugin/Env.php b/src/PHPCI/Plugin/Env.php index e53d06a9..7813ff72 100644 --- a/src/PHPCI/Plugin/Env.php +++ b/src/PHPCI/Plugin/Env.php @@ -34,9 +34,11 @@ class Env implements Plugin */ public function __construct(Builder $phpci, Build $build, array $options = []) { - $this->phpci = $phpci; - $this->build = $build; + $this->phpci = $phpci; + $this->build = $build; $this->env_vars = $options; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Git.php b/src/PHPCI/Plugin/Git.php index e8952c0d..53835844 100644 --- a/src/PHPCI/Plugin/Git.php +++ b/src/PHPCI/Plugin/Git.php @@ -34,9 +34,11 @@ class Git implements Plugin */ public function __construct(Builder $phpci, Build $build, array $options = []) { - $this->phpci = $phpci; - $this->build = $build; + $this->phpci = $phpci; + $this->build = $build; $this->actions = $options; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Grunt.php b/src/PHPCI/Plugin/Grunt.php index 42ee4f44..79e43b43 100644 --- a/src/PHPCI/Plugin/Grunt.php +++ b/src/PHPCI/Plugin/Grunt.php @@ -67,6 +67,8 @@ class Grunt implements Plugin if (isset($options['gruntfile'])) { $this->gruntfile = $options['gruntfile']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Gulp.php b/src/PHPCI/Plugin/Gulp.php index b58b9798..8291c514 100644 --- a/src/PHPCI/Plugin/Gulp.php +++ b/src/PHPCI/Plugin/Gulp.php @@ -67,6 +67,8 @@ class Gulp implements Plugin if (isset($options['gulpfile'])) { $this->gulpfile = $options['gulpfile']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/HipchatNotify.php b/src/PHPCI/Plugin/HipchatNotify.php index ff0eb598..be9e2b8c 100644 --- a/src/PHPCI/Plugin/HipchatNotify.php +++ b/src/PHPCI/Plugin/HipchatNotify.php @@ -66,7 +66,6 @@ class HipchatNotify implements Plugin } else { throw new \Exception(Lang::get('hipchat_settings')); } - } /** diff --git a/src/PHPCI/Plugin/Irc.php b/src/PHPCI/Plugin/Irc.php index 4fe37cd7..0f907a45 100644 --- a/src/PHPCI/Plugin/Irc.php +++ b/src/PHPCI/Plugin/Irc.php @@ -59,6 +59,8 @@ class Irc implements Plugin $this->room = $irc['room']; $this->nick = $irc['nick']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Lint.php b/src/PHPCI/Plugin/Lint.php index 3948a6dd..e481e61a 100644 --- a/src/PHPCI/Plugin/Lint.php +++ b/src/PHPCI/Plugin/Lint.php @@ -57,6 +57,8 @@ class Lint implements PHPCI\Plugin if (array_key_exists('recursive', $options)) { $this->recursive = $options['recursive']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Mysql.php b/src/PHPCI/Plugin/Mysql.php index 41412a6a..e504a9cd 100644 --- a/src/PHPCI/Plugin/Mysql.php +++ b/src/PHPCI/Plugin/Mysql.php @@ -90,6 +90,8 @@ class Mysql implements Plugin if (array_key_exists('pass', $buildSettings['mysql'])) { $this->pass = $buildSettings['mysql']['pass']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PackageBuild.php b/src/PHPCI/Plugin/PackageBuild.php index 5a4ccf73..e311d0c5 100644 --- a/src/PHPCI/Plugin/PackageBuild.php +++ b/src/PHPCI/Plugin/PackageBuild.php @@ -40,6 +40,8 @@ class PackageBuild implements Plugin $this->directory = isset($options['directory']) ? $options['directory'] : $path; $this->filename = isset($options['filename']) ? $options['filename'] : 'build'; $this->format = isset($options['format']) ? $options['format'] : 'zip'; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Pdepend.php b/src/PHPCI/Plugin/Pdepend.php index bb35ec4a..71c3f6b6 100644 --- a/src/PHPCI/Plugin/Pdepend.php +++ b/src/PHPCI/Plugin/Pdepend.php @@ -66,6 +66,8 @@ class Pdepend implements Plugin $this->pyramid = $title . '-pyramid.svg'; $this->chart = $title . '-chart.svg'; $this->location = $this->phpci->buildPath . '..' . DIRECTORY_SEPARATOR . 'pdepend'; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Pgsql.php b/src/PHPCI/Plugin/Pgsql.php index 0594e46a..9b55221a 100644 --- a/src/PHPCI/Plugin/Pgsql.php +++ b/src/PHPCI/Plugin/Pgsql.php @@ -71,6 +71,8 @@ class Pgsql implements Plugin $this->user = $sql['user']; $this->pass = $sql['pass']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Phar.php b/src/PHPCI/Plugin/Phar.php index 8e1a4a22..3a999e04 100644 --- a/src/PHPCI/Plugin/Phar.php +++ b/src/PHPCI/Plugin/Phar.php @@ -87,6 +87,8 @@ class Phar implements Plugin if (isset($options['stub'])) { $this->setStub($options['stub']); } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpCodeSniffer.php b/src/PHPCI/Plugin/PhpCodeSniffer.php index b8fde6d8..962a4e25 100644 --- a/src/PHPCI/Plugin/PhpCodeSniffer.php +++ b/src/PHPCI/Plugin/PhpCodeSniffer.php @@ -126,6 +126,8 @@ class PhpCodeSniffer implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin } $this->setOptions($options); + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpCpd.php b/src/PHPCI/Plugin/PhpCpd.php index 32a0cb96..d49a7525 100644 --- a/src/PHPCI/Plugin/PhpCpd.php +++ b/src/PHPCI/Plugin/PhpCpd.php @@ -65,6 +65,8 @@ class PhpCpd implements Plugin if (!empty($options['ignore'])) { $this->ignore = $options['ignore']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpCsFixer.php b/src/PHPCI/Plugin/PhpCsFixer.php index af30691d..8f88d5c1 100644 --- a/src/PHPCI/Plugin/PhpCsFixer.php +++ b/src/PHPCI/Plugin/PhpCsFixer.php @@ -56,6 +56,8 @@ class PhpCsFixer implements Plugin $this->workingdir = $this->phpci->buildPath; $this->buildArgs($options); + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpDocblockChecker.php b/src/PHPCI/Plugin/PhpDocblockChecker.php index 220acd6c..e90db2ff 100644 --- a/src/PHPCI/Plugin/PhpDocblockChecker.php +++ b/src/PHPCI/Plugin/PhpDocblockChecker.php @@ -94,6 +94,8 @@ class PhpDocblockChecker implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin if (array_key_exists('allowed_warnings', $options)) { $this->allowed_warnings = (int)$options['allowed_warnings']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpLoc.php b/src/PHPCI/Plugin/PhpLoc.php index 37b4479c..a3d92e5d 100644 --- a/src/PHPCI/Plugin/PhpLoc.php +++ b/src/PHPCI/Plugin/PhpLoc.php @@ -61,6 +61,8 @@ class PhpLoc implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin if (isset($options['directory'])) { $this->directory .= $options['directory']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpMessDetector.php b/src/PHPCI/Plugin/PhpMessDetector.php index 1174c476..da938093 100644 --- a/src/PHPCI/Plugin/PhpMessDetector.php +++ b/src/PHPCI/Plugin/PhpMessDetector.php @@ -108,6 +108,8 @@ class PhpMessDetector implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin foreach (['rules', 'ignore', 'suffixes'] as $key) { $this->overrideSetting($options, $key); } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpParallelLint.php b/src/PHPCI/Plugin/PhpParallelLint.php index 0320b848..b69763bf 100644 --- a/src/PHPCI/Plugin/PhpParallelLint.php +++ b/src/PHPCI/Plugin/PhpParallelLint.php @@ -67,6 +67,8 @@ class PhpParallelLint implements Plugin if (isset($options['ignore'])) { $this->ignore = $options['ignore']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpSpec.php b/src/PHPCI/Plugin/PhpSpec.php index 70521bb2..17540683 100644 --- a/src/PHPCI/Plugin/PhpSpec.php +++ b/src/PHPCI/Plugin/PhpSpec.php @@ -44,9 +44,11 @@ class PhpSpec implements PHPCI\Plugin */ public function __construct(Builder $phpci, Build $build, array $options = []) { - $this->phpci = $phpci; - $this->build = $build; + $this->phpci = $phpci; + $this->build = $build; $this->options = $options; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpTalLint.php b/src/PHPCI/Plugin/PhpTalLint.php index d5124a25..3bccba7e 100644 --- a/src/PHPCI/Plugin/PhpTalLint.php +++ b/src/PHPCI/Plugin/PhpTalLint.php @@ -83,6 +83,8 @@ class PhpTalLint implements PHPCI\Plugin } $this->setOptions($options); + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/PhpUnit.php b/src/PHPCI/Plugin/PhpUnit.php index 82c77a87..696bb9cb 100644 --- a/src/PHPCI/Plugin/PhpUnit.php +++ b/src/PHPCI/Plugin/PhpUnit.php @@ -135,6 +135,8 @@ class PhpUnit implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin if (isset($options['coverage'])) { $this->coverage = ' --coverage-html ' . $this->phpci->interpolate($options['coverage']) . ' '; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Shell.php b/src/PHPCI/Plugin/Shell.php index e22445b4..e7c80317 100644 --- a/src/PHPCI/Plugin/Shell.php +++ b/src/PHPCI/Plugin/Shell.php @@ -72,6 +72,8 @@ class Shell implements Plugin if (is_array($options)) { $this->commands = $options; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Sqlite.php b/src/PHPCI/Plugin/Sqlite.php index 52482fe5..d0752bae 100644 --- a/src/PHPCI/Plugin/Sqlite.php +++ b/src/PHPCI/Plugin/Sqlite.php @@ -58,6 +58,8 @@ class Sqlite implements Plugin $sql = $buildSettings['sqlite']; $this->path = $sql['path']; } + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/TechnicalDebt.php b/src/PHPCI/Plugin/TechnicalDebt.php index f4f1de36..e006c02a 100755 --- a/src/PHPCI/Plugin/TechnicalDebt.php +++ b/src/PHPCI/Plugin/TechnicalDebt.php @@ -101,6 +101,8 @@ class TechnicalDebt implements PHPCI\Plugin, PHPCI\ZeroConfigPlugin } $this->setOptions($options); + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Util/Executor.php b/src/PHPCI/Plugin/Util/Executor.php index 20c51f3f..0f58cf0b 100644 --- a/src/PHPCI/Plugin/Util/Executor.php +++ b/src/PHPCI/Plugin/Util/Executor.php @@ -78,7 +78,7 @@ class Executor protected function getBranchSpecificPlugins(&$config, $stage, $pluginsToExecute) { /** @var \PHPCI\Model\Build $build */ - $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); + $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); $branch = $build->getBranch(); // If we don't have any branch-specific plugins: @@ -133,7 +133,7 @@ class Executor $success = true; foreach ($plugins as $plugin => $options) { - $this->logger->log(Lang::get('running_plugin', $plugin)); + $this->logger->log("\n" . Lang::get('running_plugin', Lang::get($plugin)) . ' (' . Lang::get('stage') . ': ' . Lang::get('stage_' . $stage) . ')'); $this->setPluginStatus($stage, $plugin, Build::STATUS_RUNNING); @@ -144,18 +144,21 @@ class Executor $this->setPluginStatus($stage, $plugin, Build::STATUS_SUCCESS); } else { // Execution failed - $this->logger->logFailure(Lang::get('plugin_failed')); $this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED); if ($stage === 'setup') { + $this->logger->logFailure(Lang::get('plugin_failed')); // If we're in the "setup" stage, execution should not continue after // a plugin has failed: throw new Exception('Plugin failed: ' . $plugin); - } elseif ($stage === 'test') { + } else { // If we're in the "test" stage and the plugin is not allowed to fail, // then mark the build as failed: - if (empty($options['allow_failures'])) { + if (empty($options['allow_failures']) && $stage === 'test') { + $this->logger->logFailure(Lang::get('plugin_failed')); $success = false; + } else { + $this->logger->logFailure(Lang::get('plugin_failed') . ' (' . Lang::get('failed_allowed') . ')'); } } } @@ -182,15 +185,18 @@ class Executor if (!class_exists($class)) { $this->logger->logFailure(Lang::get('plugin_missing', $plugin)); + return false; } try { // Build and run it $obj = $this->pluginFactory->buildPlugin($class, $options); + return $obj->execute(); } catch (\Exception $ex) { $this->logger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex); + return false; } } @@ -228,6 +234,7 @@ class Executor */ private function getBuildSummary() { + /** @var Build $build */ $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); $metas = $this->store->getMeta('plugin-summary', $build->getProjectId(), $build->getId()); return isset($metas[0]['meta_value']) ? $metas[0]['meta_value'] : []; @@ -240,6 +247,7 @@ class Executor */ private function setBuildSummary($summary) { + /** @var Build $build */ $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); $this->store->setMeta($build->getProjectId(), $build->getId(), 'plugin-summary', json_encode($summary)); } diff --git a/src/PHPCI/Plugin/Util/Factory.php b/src/PHPCI/Plugin/Util/Factory.php index 8e869fca..4e30f52d 100644 --- a/src/PHPCI/Plugin/Util/Factory.php +++ b/src/PHPCI/Plugin/Util/Factory.php @@ -31,15 +31,6 @@ class Factory } else { $this->container = new Container(); } - - $self = $this; - $this->registerResource( - function () use ($self) { - return $self->getLastOptions(); - }, - 'options', - 'array' - ); } /** diff --git a/src/PHPCI/Plugin/Wipe.php b/src/PHPCI/Plugin/Wipe.php index 8b53d2cd..8357d908 100644 --- a/src/PHPCI/Plugin/Wipe.php +++ b/src/PHPCI/Plugin/Wipe.php @@ -45,6 +45,8 @@ class Wipe implements Plugin $this->phpci = $phpci; $this->build = $build; $this->directory = isset($options['directory']) ? $this->phpci->interpolate($options['directory']) : $path; + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /** diff --git a/src/PHPCI/Plugin/Xmpp.php b/src/PHPCI/Plugin/Xmpp.php index 2431911a..546fe79e 100644 --- a/src/PHPCI/Plugin/Xmpp.php +++ b/src/PHPCI/Plugin/Xmpp.php @@ -91,6 +91,8 @@ class XMPP implements Plugin } $this->setOptions($options); + + $this->phpci->logDebug('Plugin options: ' . json_encode($options)); } /**