From 58f7d8a9161903ae3f55b51a246f9368ea8d57bd Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Fri, 9 Oct 2015 09:16:05 +0100 Subject: [PATCH] Cleanup of new executor changes. --- PHPCI/Plugin/Util/Executor.php | 90 +++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 29 deletions(-) diff --git a/PHPCI/Plugin/Util/Executor.php b/PHPCI/Plugin/Util/Executor.php index b085ac87..bdd06b7e 100644 --- a/PHPCI/Plugin/Util/Executor.php +++ b/PHPCI/Plugin/Util/Executor.php @@ -50,10 +50,6 @@ class Executor public function executePlugins(&$config, $stage) { $success = true; - - /** @var \PHPCI\Model\Build $build */ - $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); - $branch = $build->getBranch(); $pluginsToExecute = array(); // If we have global plugins to execute for this stage, add them to the list to be executed: @@ -61,31 +57,7 @@ class Executor $pluginsToExecute[] = $config[$stage]; } - // If we have branch-specific plugins to execute, add them to the list to be executed: - if (isset($config['branch-' . $branch][$stage]) && is_array($config['branch-' . $branch][$stage])) { - $branchConfig = $config['branch-' . $branch]; - $runOption = isset($branchConfig['run-option']) ? $branchConfig['run-option'] : 'after'; - $plugins = $config['branch-' . $branch][$stage]; - - switch ($runOption) { - case 'replace': - $pluginsToExecute = array(); - $pluginsToExecute[] = $plugins; - break; - - case 'before': - array_unshift($pluginsToExecute, $plugins); - break; - - case 'after': - array_push($pluginsToExecute, $plugins); - break; - - default: - array_push($pluginsToExecute, $plugins); - break; - } - } + $pluginsToExecute = $this->getBranchSpecificPlugins($config, $stage, $pluginsToExecute); foreach ($pluginsToExecute as $pluginSet) { if (!$this->doExecutePlugins($pluginSet, $stage)) { @@ -96,6 +68,66 @@ class Executor return $success; } + /** + * Check the config for any plugins specific to the branch we're currently building. + * @param $config + * @param $stage + * @param $pluginsToExecute + * @return array + */ + protected function getBranchSpecificPlugins(&$config, $stage, $pluginsToExecute) + { + /** @var \PHPCI\Model\Build $build */ + $build = $this->pluginFactory->getResourceFor('PHPCI\Model\Build'); + $branch = $build->getBranch(); + + // If we don't have any branch-specific plugins: + if (!isset($config['branch-' . $branch][$stage]) || !is_array($config['branch-' . $branch][$stage])) { + return $pluginsToExecute; + } + + // If we have branch-specific plugins to execute, add them to the list to be executed: + $branchConfig = $config['branch-' . $branch]; + $plugins = $branchConfig[$stage]; + + $runOption = 'after'; + + if (!empty($branchConfig['run-option'])) { + $runOption = $branchConfig['run-option']; + } + + switch ($runOption) { + // Replace standard plugin set for this stage with just the branch-specific ones: + case 'replace': + $pluginsToExecute = array(); + $pluginsToExecute[] = $plugins; + break; + + // Run branch-specific plugins before standard plugins: + case 'before': + array_unshift($pluginsToExecute, $plugins); + break; + + // Run branch-specific plugins after standard plugins: + case 'after': + array_push($pluginsToExecute, $plugins); + break; + + default: + array_push($pluginsToExecute, $plugins); + break; + } + + return $pluginsToExecute; + } + + /** + * Execute the list of plugins found for a given testing stage. + * @param $plugins + * @param $stage + * @return bool + * @throws \Exception + */ protected function doExecutePlugins(&$plugins, $stage) { $success = true;