Refactored plugins

This commit is contained in:
Dmitry Khomutov 2016-07-11 22:00:04 +06:00
commit 16a5add859
45 changed files with 404 additions and 1224 deletions

View file

@ -8,6 +8,7 @@ use PHPCensor\Helper\Lang;
use PHPCensor\Logging\BuildLogger;
use PHPCensor\Model\Build;
use PHPCensor\Store\BuildStore;
use PHPCensor\Builder;
/**
* Plugin Executor - Runs the configured plugins for a given build stage.
@ -15,6 +16,16 @@ use PHPCensor\Store\BuildStore;
*/
class Executor
{
/**
* @var \PHPCI\Builder
*/
protected $phpci;
/**
* @var \PHPCI\Model\Build
*/
protected $build;
/**
* @var BuildLogger
*/
@ -31,14 +42,16 @@ class Executor
protected $store;
/**
* @param Factory $pluginFactory
* @param Builder $phpci
* @param Build $build
* @param BuildLogger $logger
*/
public function __construct(Factory $pluginFactory, BuildLogger $logger, BuildStore $store = null)
public function __construct(Builder $phpci, Build $build, BuildLogger $logger)
{
$this->pluginFactory = $pluginFactory;
$this->phpci = $phpci;
$this->build = $build;
$this->logger = $logger;
$this->store = $store ?: StoreFactory::getStore('Build');
$this->store = StoreFactory::getStore('Build');
}
/**
@ -78,7 +91,7 @@ class Executor
protected function getBranchSpecificPlugins(&$config, $stage, $pluginsToExecute)
{
/** @var \PHPCensor\Model\Build $build */
$build = $this->pluginFactory->getResourceFor('PHPCensor\Model\Build');
$build = $this->build;
$branch = $build->getBranch();
// If we don't have any branch-specific plugins:
@ -190,10 +203,7 @@ class Executor
}
try {
// Build and run it
$obj = $this->pluginFactory->buildPlugin($class, $options);
return $obj->execute();
return (new $class($this->phpci, $this->build, $options))->execute();
} catch (\Exception $ex) {
$this->logger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex);
@ -235,7 +245,7 @@ class Executor
private function getBuildSummary()
{
/** @var Build $build */
$build = $this->pluginFactory->getResourceFor('PHPCensor\Model\Build');
$build = $this->build;
$metas = $this->store->getMeta('plugin-summary', $build->getProjectId(), $build->getId());
return isset($metas[0]['meta_value']) ? $metas[0]['meta_value'] : [];
}
@ -248,7 +258,7 @@ class Executor
private function setBuildSummary($summary)
{
/** @var Build $build */
$build = $this->pluginFactory->getResourceFor('PHPCensor\Model\Build');
$build = $this->build;
$this->store->setMeta($build->getProjectId(), $build->getId(), 'plugin-summary', json_encode($summary));
}
}