Cleanup of new executor changes.

This commit is contained in:
Dan Cryer 2015-10-09 09:16:05 +01:00
parent 4375c524a9
commit 68249d2f5d

View file

@ -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;