Merge branch 'feature-plugins'
This commit is contained in:
commit
f514cdafc3
47 changed files with 640 additions and 1510 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,5 @@
|
|||
/composer.phar
|
||||
/runtime
|
||||
/app/loggerconfig.php
|
||||
/app/pluginconfig.php
|
||||
/app/config.yml
|
||||
/public/assets/vendor
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
return function (PHPCensor\Plugin\Util\Factory $factory) {
|
||||
$factory->registerResource(
|
||||
// This function will be called when the resource is needed.
|
||||
function() {
|
||||
return [
|
||||
'Foo' => "Stuff",
|
||||
'Bar' => "More Stuff"
|
||||
];
|
||||
},
|
||||
|
||||
// In addition to the function for building the resource the system
|
||||
// also needs to be told when to load the resource. Either or both
|
||||
// of the following arguments can be used (null to ignore)
|
||||
|
||||
// This resource will only be given when the argument name is:
|
||||
"ResourceArray",
|
||||
|
||||
// The resource will only be given when the type hint is:
|
||||
PHPCensor\Plugin\Util\Factory::TYPE_ARRAY
|
||||
);
|
||||
};
|
||||
|
|
@ -110,9 +110,7 @@ class Builder implements LoggerAwareInterface
|
|||
|
||||
$this->buildLogger = new BuildLogger($logger, $build);
|
||||
|
||||
$pluginFactory = $this->buildPluginFactory($build);
|
||||
$pluginFactory->addConfigFromFile(APP_DIR . "pluginconfig.php");
|
||||
$this->pluginExecutor = new Plugin\Util\Executor($pluginFactory, $this->buildLogger);
|
||||
$this->pluginExecutor = new Plugin\Util\Executor($this, $build, $this->buildLogger);
|
||||
|
||||
$executorClass = 'PHPCensor\Helper\UnixCommandExecutor';
|
||||
if (IS_WIN) {
|
||||
|
|
@ -391,52 +389,4 @@ class Builder implements LoggerAwareInterface
|
|||
{
|
||||
$this->buildLogger->logDebug($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a configured instance of the plugin factory.
|
||||
*
|
||||
* @param Build $build
|
||||
* @return PluginFactory
|
||||
*/
|
||||
private function buildPluginFactory(Build $build)
|
||||
{
|
||||
$pluginFactory = new PluginFactory();
|
||||
|
||||
$self = $this;
|
||||
$pluginFactory->registerResource(
|
||||
function () use ($self) {
|
||||
return $self;
|
||||
},
|
||||
null,
|
||||
'PHPCensor\Builder'
|
||||
);
|
||||
|
||||
$pluginFactory->registerResource(
|
||||
function () use ($build) {
|
||||
return $build;
|
||||
},
|
||||
null,
|
||||
'PHPCensor\Model\Build'
|
||||
);
|
||||
|
||||
$logger = $this->logger;
|
||||
$pluginFactory->registerResource(
|
||||
function () use ($logger) {
|
||||
return $logger;
|
||||
},
|
||||
null,
|
||||
'Psr\Log\LoggerInterface'
|
||||
);
|
||||
|
||||
$pluginFactory->registerResource(
|
||||
function () use ($self) {
|
||||
$factory = new MailerFactory($self->getSystemConfig('php-censor'));
|
||||
return $factory->getSwiftMailerFromConfig();
|
||||
},
|
||||
null,
|
||||
'Swift_Mailer'
|
||||
);
|
||||
|
||||
return $pluginFactory;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,46 @@
|
|||
|
||||
namespace PHPCensor;
|
||||
|
||||
use PHPCensor\Model\Build;
|
||||
|
||||
/**
|
||||
* PHPCI Plugin Interface - Used by all build plugins.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* PHPCI Plugin class - Used by all build plugins.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
interface Plugin
|
||||
abstract class Plugin
|
||||
{
|
||||
public function execute();
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->builder = $builder;
|
||||
$this->build = $build;
|
||||
$this->options = $options;
|
||||
|
||||
$this->builder->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
abstract public function execute();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,29 +16,27 @@ use PHPCensor\Plugin;
|
|||
|
||||
/**
|
||||
* Atoum plugin, runs Atoum tests within a project.
|
||||
*
|
||||
* @package PHPCensor\Plugin
|
||||
*/
|
||||
class Atoum implements Plugin
|
||||
class Atoum extends Plugin
|
||||
{
|
||||
private $args;
|
||||
private $config;
|
||||
private $directory;
|
||||
protected $executable;
|
||||
protected $args;
|
||||
protected $config;
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
if (isset($options['executable'])) {
|
||||
$this->executable = $this->phpci->buildPath . DIRECTORY_SEPARATOR.$options['executable'];
|
||||
$this->executable = $this->builder->buildPath . DIRECTORY_SEPARATOR.$options['executable'];
|
||||
} else {
|
||||
$this->executable = $this->phpci->findBinary('atoum');
|
||||
$this->executable = $this->builder->findBinary('atoum');
|
||||
}
|
||||
|
||||
if (isset($options['args'])) {
|
||||
|
|
@ -69,21 +67,21 @@ class Atoum implements Plugin
|
|||
$cmd .= " -c '{$this->config}'";
|
||||
}
|
||||
if ($this->directory !== null) {
|
||||
$dirPath = $this->phpci->buildPath . DIRECTORY_SEPARATOR . $this->directory;
|
||||
$dirPath = $this->builder->buildPath . DIRECTORY_SEPARATOR . $this->directory;
|
||||
$cmd .= " -d '{$dirPath}'";
|
||||
}
|
||||
chdir($this->phpci->buildPath);
|
||||
chdir($this->builder->buildPath);
|
||||
$output = '';
|
||||
$status = true;
|
||||
exec($cmd, $output);
|
||||
|
||||
if (count(preg_grep("/Success \(/", $output)) == 0) {
|
||||
$status = false;
|
||||
$this->phpci->log($output);
|
||||
$this->builder->log($output);
|
||||
}
|
||||
if (count($output) == 0) {
|
||||
$status = false;
|
||||
$this->phpci->log(Lang::get('no_tests_performed'));
|
||||
$this->builder->log(Lang::get('no_tests_performed'));
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
|
|
|||
|
|
@ -17,45 +17,34 @@ use PHPCensor\Plugin;
|
|||
|
||||
/**
|
||||
* Behat BDD Plugin
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Behat implements Plugin
|
||||
class Behat extends Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $features;
|
||||
protected $executable;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->features = '';
|
||||
|
||||
if (isset($options['executable'])) {
|
||||
$this->executable = $options['executable'];
|
||||
} else {
|
||||
$this->executable = $this->phpci->findBinary('behat');
|
||||
$this->executable = $this->builder->findBinary('behat');
|
||||
}
|
||||
|
||||
if (!empty($options['features'])) {
|
||||
$this->features = $options['features'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,19 +52,19 @@ class Behat implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$curdir = getcwd();
|
||||
chdir($this->phpci->buildPath);
|
||||
$current_dir = getcwd();
|
||||
chdir($this->builder->buildPath);
|
||||
|
||||
$behat = $this->executable;
|
||||
|
||||
if (!$behat) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'behat'));
|
||||
$this->builder->logFailure(Lang::get('could_not_find', 'behat'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($behat . ' %s', $this->features);
|
||||
chdir($curdir);
|
||||
$success = $this->builder->executeCommand($behat . ' %s', $this->features);
|
||||
chdir($current_dir);
|
||||
|
||||
list($errorCount, $data) = $this->parseBehatOutput();
|
||||
|
||||
|
|
@ -92,7 +81,7 @@ class Behat implements Plugin
|
|||
*/
|
||||
public function parseBehatOutput()
|
||||
{
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$output = $this->builder->getLastOutput();
|
||||
|
||||
$parts = explode('---', $output);
|
||||
|
||||
|
|
@ -124,7 +113,7 @@ class Behat implements Plugin
|
|||
];
|
||||
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'behat',
|
||||
'Behat scenario failed.',
|
||||
BuildError::SEVERITY_HIGH,
|
||||
|
|
|
|||
|
|
@ -21,31 +21,28 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Campfire implements Plugin
|
||||
class Campfire extends Plugin
|
||||
{
|
||||
private $url;
|
||||
private $authToken;
|
||||
private $userAgent;
|
||||
private $cookie;
|
||||
private $verbose;
|
||||
private $roomId;
|
||||
protected $url;
|
||||
protected $authToken;
|
||||
protected $userAgent;
|
||||
protected $cookie;
|
||||
protected $verbose;
|
||||
protected $roomId;
|
||||
protected $message;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->message = $options['message'];
|
||||
$this->userAgent = "PHP Censor/1.0";
|
||||
$this->cookie = "php-censor-cookie";
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
$buildSettings = $this->builder->getConfig('build_settings');
|
||||
|
||||
if (isset($buildSettings['campfire'])) {
|
||||
$campfire = $buildSettings['campfire'];
|
||||
|
|
|
|||
|
|
@ -20,31 +20,18 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class CleanBuild implements Plugin
|
||||
class CleanBuild extends Plugin
|
||||
{
|
||||
protected $remove;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->remove = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : [];
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
$this->remove = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,13 +43,13 @@ class CleanBuild implements Plugin
|
|||
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');
|
||||
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.phar');
|
||||
$this->builder->executeCommand($cmd, $this->builder->buildPath . 'composer.lock');
|
||||
|
||||
$success = true;
|
||||
|
||||
foreach ($this->remove as $file) {
|
||||
$ok = $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $file);
|
||||
$ok = $this->builder->executeCommand($cmd, $this->builder->buildPath . $file);
|
||||
|
||||
if (!$ok) {
|
||||
$success = false;
|
||||
|
|
|
|||
|
|
@ -25,17 +25,11 @@ use PHPCensor\ZeroConfigPlugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Codeception implements Plugin, ZeroConfigPlugin
|
||||
class Codeception extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/** @var string */
|
||||
protected $args = '';
|
||||
|
||||
/** @var Builder */
|
||||
protected $phpci;
|
||||
|
||||
/** @var Build */
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string $ymlConfigFile The path of a yml config for Codeception
|
||||
*/
|
||||
|
|
@ -46,6 +40,28 @@ class Codeception implements Plugin, ZeroConfigPlugin
|
|||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->path = 'tests' . DIRECTORY_SEPARATOR . '_output' . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (empty($options['config'])) {
|
||||
$this->ymlConfigFile = self::findConfigFile($this->builder->buildPath);
|
||||
} else {
|
||||
$this->ymlConfigFile = $options['config'];
|
||||
}
|
||||
if (isset($options['args'])) {
|
||||
$this->args = (string) $options['args'];
|
||||
}
|
||||
if (isset($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $stage
|
||||
* @param Builder $builder
|
||||
|
|
@ -75,33 +91,6 @@ class Codeception implements Plugin, ZeroConfigPlugin
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->path = 'tests' . DIRECTORY_SEPARATOR . '_output' . DIRECTORY_SEPARATOR;
|
||||
|
||||
if (empty($options['config'])) {
|
||||
$this->ymlConfigFile = self::findConfigFile($this->phpci->buildPath);
|
||||
} else {
|
||||
$this->ymlConfigFile = $options['config'];
|
||||
}
|
||||
if (isset($options['args'])) {
|
||||
$this->args = (string) $options['args'];
|
||||
}
|
||||
if (isset($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs Codeception tests
|
||||
*/
|
||||
|
|
@ -123,32 +112,32 @@ class Codeception implements Plugin, ZeroConfigPlugin
|
|||
*/
|
||||
protected function runConfigFile($configPath)
|
||||
{
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
$codecept = $this->phpci->findBinary('codecept');
|
||||
$codeception = $this->builder->findBinary('codecept');
|
||||
|
||||
if (!$codecept) {
|
||||
$this->phpci->logFailure(Lang::get('could_not_find', 'codecept'));
|
||||
if (!$codeception) {
|
||||
$this->builder->logFailure(Lang::get('could_not_find', 'codecept'));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$cmd = 'cd "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
|
||||
$cmd = 'cd "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
|
||||
|
||||
if (IS_WIN) {
|
||||
$cmd = 'cd /d "%s" && ' . $codecept . ' run -c "%s" --xml ' . $this->args;
|
||||
$cmd = 'cd /d "%s" && ' . $codeception . ' run -c "%s" --xml ' . $this->args;
|
||||
}
|
||||
|
||||
$configPath = $this->phpci->buildPath . $configPath;
|
||||
$success = $this->phpci->executeCommand($cmd, $this->phpci->buildPath, $configPath);
|
||||
$configPath = $this->builder->buildPath . $configPath;
|
||||
$success = $this->builder->executeCommand($cmd, $this->builder->buildPath, $configPath);
|
||||
|
||||
$this->phpci->log(
|
||||
'Codeception XML path: '. $this->phpci->buildPath . $this->path . 'report.xml',
|
||||
$this->builder->log(
|
||||
'Codeception XML path: '. $this->builder->buildPath . $this->path . 'report.xml',
|
||||
Loglevel::DEBUG
|
||||
);
|
||||
|
||||
$xml = file_get_contents($this->phpci->buildPath . $this->path . 'report.xml', false);
|
||||
$parser = new Parser($this->phpci, $xml);
|
||||
$xml = file_get_contents($this->builder->buildPath . $this->path . 'report.xml', false);
|
||||
$parser = new Parser($this->builder, $xml);
|
||||
$output = $parser->parse();
|
||||
|
||||
$meta = [
|
||||
|
|
@ -160,7 +149,7 @@ class Codeception implements Plugin, ZeroConfigPlugin
|
|||
$this->build->storeMeta('codeception-meta', $meta);
|
||||
$this->build->storeMeta('codeception-data', $output);
|
||||
$this->build->storeMeta('codeception-errors', $parser->getTotalFailures());
|
||||
$this->phpci->logExecOutput(true);
|
||||
$this->builder->logExecOutput(true);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* Composer Plugin - Provides access to Composer functionality.
|
||||
|
|
@ -19,46 +21,23 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Composer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class Composer extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $action;
|
||||
protected $preferDist;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $nodev;
|
||||
protected $ignorePlatformReqs;
|
||||
protected $preferSource;
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
* @param $stage
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @return bool
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function canExecute($stage, Builder $builder, Build $build)
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json';
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
if (file_exists($path) && $stage == 'setup') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$path = $this->builder->buildPath;
|
||||
$this->directory = $path;
|
||||
$this->action = 'install';
|
||||
$this->preferDist = false;
|
||||
|
|
@ -90,8 +69,24 @@ class Composer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
if (array_key_exists('ignore_platform_reqs', $options)) {
|
||||
$this->ignorePlatformReqs = (bool)$options['ignore_platform_reqs'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
* @param $stage
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @return bool
|
||||
*/
|
||||
public static function canExecute($stage, Builder $builder, Build $build)
|
||||
{
|
||||
$path = $builder->buildPath . DIRECTORY_SEPARATOR . 'composer.json';
|
||||
|
||||
if (file_exists($path) && $stage == 'setup') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,7 +94,7 @@ class Composer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$composerLocation = $this->phpci->findBinary(['composer', 'composer.phar']);
|
||||
$composerLocation = $this->builder->findBinary(['composer', 'composer.phar']);
|
||||
|
||||
$cmd = '';
|
||||
|
||||
|
|
@ -110,27 +105,27 @@ class Composer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$cmd .= $composerLocation . ' --no-ansi --no-interaction ';
|
||||
|
||||
if ($this->preferDist) {
|
||||
$this->phpci->log('Using --prefer-dist flag');
|
||||
$this->builder->log('Using --prefer-dist flag');
|
||||
$cmd .= ' --prefer-dist';
|
||||
}
|
||||
|
||||
if ($this->preferSource) {
|
||||
$this->phpci->log('Using --prefer-source flag');
|
||||
$this->builder->log('Using --prefer-source flag');
|
||||
$cmd .= ' --prefer-source';
|
||||
}
|
||||
|
||||
if ($this->nodev) {
|
||||
$this->phpci->log('Using --no-dev flag');
|
||||
$this->builder->log('Using --no-dev flag');
|
||||
$cmd .= ' --no-dev';
|
||||
}
|
||||
|
||||
if ($this->ignorePlatformReqs) {
|
||||
$this->phpci->log('Using --ignore-platform-reqs flag');
|
||||
$this->builder->log('Using --ignore-platform-reqs flag');
|
||||
$cmd .= ' --ignore-platform-reqs';
|
||||
}
|
||||
|
||||
$cmd .= ' --working-dir="%s" %s';
|
||||
|
||||
return $this->phpci->executeCommand($cmd, $this->directory, $this->action);
|
||||
return $this->builder->executeCommand($cmd, $this->directory, $this->action);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,30 +20,23 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class CopyBuild implements Plugin
|
||||
class CopyBuild extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $ignore;
|
||||
protected $wipe;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$path = $this->builder->buildPath;
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +44,7 @@ class CopyBuild implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$build = $this->phpci->buildPath;
|
||||
$build = $this->builder->buildPath;
|
||||
|
||||
if ($this->directory == $build) {
|
||||
return false;
|
||||
|
|
@ -64,7 +57,7 @@ class CopyBuild implements Plugin
|
|||
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);
|
||||
$success = $this->builder->executeCommand($cmd, $this->directory, $build, $this->directory);
|
||||
|
||||
$this->deleteIgnoredFiles();
|
||||
|
||||
|
|
@ -79,7 +72,7 @@ class CopyBuild implements Plugin
|
|||
{
|
||||
if ($this->wipe === true && $this->directory != '/' && is_dir($this->directory)) {
|
||||
$cmd = 'rm -Rf "%s*"';
|
||||
$success = $this->phpci->executeCommand($cmd, $this->directory);
|
||||
$success = $this->builder->executeCommand($cmd, $this->directory);
|
||||
|
||||
if (!$success) {
|
||||
throw new \Exception(Lang::get('failed_to_wipe', $this->directory));
|
||||
|
|
@ -93,12 +86,12 @@ class CopyBuild implements Plugin
|
|||
protected function deleteIgnoredFiles()
|
||||
{
|
||||
if ($this->ignore) {
|
||||
foreach ($this->phpci->ignore as $file) {
|
||||
foreach ($this->builder->ignore as $file) {
|
||||
$cmd = 'rm -Rf "%s/%s"';
|
||||
if (IS_WIN) {
|
||||
$cmd = 'rmdir /S /Q "%s\%s"';
|
||||
}
|
||||
$this->phpci->executeCommand($cmd, $this->directory, $file);
|
||||
$this->builder->executeCommand($cmd, $this->directory, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,24 +20,20 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Deployer implements Plugin
|
||||
class Deployer extends Plugin
|
||||
{
|
||||
protected $webhookUrl;
|
||||
protected $reason;
|
||||
protected $updateOnly;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->reason = 'PHP Censor Build #%BUILD% - %COMMIT_MESSAGE%';
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->reason = 'PHP Censor Build #%BUILD% - %COMMIT_MESSAGE%';
|
||||
if (isset($options['webhook_url'])) {
|
||||
$this->webhookUrl = $options['webhook_url'];
|
||||
}
|
||||
|
|
@ -45,7 +41,7 @@ class Deployer implements Plugin
|
|||
if (isset($options['reason'])) {
|
||||
$this->reason = $options['reason'];
|
||||
}
|
||||
|
||||
|
||||
$this->updateOnly = isset($options['update_only']) ? (bool) $options['update_only'] : true;
|
||||
}
|
||||
|
||||
|
|
@ -55,17 +51,17 @@ class Deployer implements Plugin
|
|||
public function execute()
|
||||
{
|
||||
if (empty($this->webhookUrl)) {
|
||||
$this->phpci->logFailure('You must specify a webhook URL.');
|
||||
$this->builder->logFailure('You must specify a webhook URL.');
|
||||
return false;
|
||||
}
|
||||
|
||||
$http = new HttpClient();
|
||||
|
||||
$response = $http->post($this->webhookUrl, [
|
||||
'reason' => $this->phpci->interpolate($this->reason),
|
||||
'reason' => $this->builder->interpolate($this->reason),
|
||||
'source' => 'PHP Censor',
|
||||
'url' => $this->phpci->interpolate('%BUILD_URI%'),
|
||||
'branch' => $this->phpci->interpolate('%BRANCH%'),
|
||||
'url' => $this->builder->interpolate('%BUILD_URI%'),
|
||||
'branch' => $this->builder->interpolate('%BRANCH%'),
|
||||
'update_only' => $this->updateOnly
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,38 +26,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Email implements Plugin
|
||||
class Email extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification mail.
|
||||
*
|
||||
|
|
@ -76,7 +46,15 @@ class Email implements Plugin
|
|||
$buildStatus = $this->build->isSuccessful() ? "Passing Build" : "Failing Build";
|
||||
$projectName = $this->build->getProject()->getTitle();
|
||||
|
||||
$view = $this->getMailTemplate();
|
||||
try {
|
||||
$view = $this->getMailTemplate();
|
||||
} catch (ViewRuntimeException $e) {
|
||||
$this->builder->log(
|
||||
sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']),
|
||||
LogLevel::WARNING
|
||||
);
|
||||
$view = $this->getDefaultMailTemplate();
|
||||
}
|
||||
|
||||
$view->build = $this->build;
|
||||
$view->project = $this->build->getProject();
|
||||
|
|
@ -94,8 +72,8 @@ class Email implements Plugin
|
|||
);
|
||||
|
||||
// This is a success if we've not failed to send anything.
|
||||
$this->phpci->log(Lang::get('n_emails_sent', (count($addresses) - $sendFailures)));
|
||||
$this->phpci->log(Lang::get('n_emails_failed', $sendFailures));
|
||||
$this->builder->log(Lang::get('n_emails_sent', (count($addresses) - $sendFailures)));
|
||||
$this->builder->log(Lang::get('n_emails_failed', $sendFailures));
|
||||
|
||||
return ($sendFailures === 0);
|
||||
}
|
||||
|
|
@ -123,7 +101,7 @@ class Email implements Plugin
|
|||
}
|
||||
}
|
||||
|
||||
return $email->send($this->phpci);
|
||||
return $email->send($this->builder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -161,8 +139,8 @@ class Email implements Plugin
|
|||
$addresses = [];
|
||||
$committer = $this->build->getCommitterEmail();
|
||||
|
||||
$this->phpci->logDebug(sprintf("Committer email: '%s'", $committer));
|
||||
$this->phpci->logDebug(sprintf(
|
||||
$this->builder->logDebug(sprintf("Committer email: '%s'", $committer));
|
||||
$this->builder->logDebug(sprintf(
|
||||
"Committer option: '%s'",
|
||||
(!empty($this->options['committer']) && $this->options['committer']) ? 'true' : 'false'
|
||||
));
|
||||
|
|
@ -173,7 +151,7 @@ class Email implements Plugin
|
|||
}
|
||||
}
|
||||
|
||||
$this->phpci->logDebug(sprintf(
|
||||
$this->builder->logDebug(sprintf(
|
||||
"Addresses option: '%s'",
|
||||
(!empty($this->options['addresses']) && is_array($this->options['addresses'])) ? implode(', ', $this->options['addresses']) : 'false'
|
||||
));
|
||||
|
|
@ -184,7 +162,7 @@ class Email implements Plugin
|
|||
}
|
||||
}
|
||||
|
||||
$this->phpci->logDebug(sprintf(
|
||||
$this->builder->logDebug(sprintf(
|
||||
"Default mailTo option: '%s'",
|
||||
!empty($this->options['default_mailto_address']) ? $this->options['default_mailto_address'] : 'false'
|
||||
));
|
||||
|
|
@ -221,17 +199,8 @@ class Email implements Plugin
|
|||
*/
|
||||
protected function getMailTemplate()
|
||||
{
|
||||
try {
|
||||
if (isset($this->options['template'])) {
|
||||
return new View('Email/' . $this->options['template']);
|
||||
}
|
||||
} catch (ViewRuntimeException $e) {
|
||||
$this->phpci->log(
|
||||
sprintf('Unknown mail template "%s", falling back to default.', $this->options['template']),
|
||||
LogLevel::WARNING
|
||||
);
|
||||
|
||||
return $this->getDefaultMailTemplate();
|
||||
if (isset($this->options['template'])) {
|
||||
return new View('Email/' . $this->options['template']);
|
||||
}
|
||||
|
||||
return $this->getDefaultMailTemplate();
|
||||
|
|
|
|||
|
|
@ -20,34 +20,17 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Env implements Plugin
|
||||
class Env extends Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $env_vars;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->env_vars = $options;
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified environment variables to the builder environment
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$success = true;
|
||||
foreach ($this->env_vars as $key => $value) {
|
||||
foreach ($this->options as $key => $value) {
|
||||
if (is_numeric($key)) {
|
||||
// This allows the developer to specify env vars like " - FOO=bar" or " - FOO: bar"
|
||||
$env_var = is_array($value)? key($value).'='.current($value): $value;
|
||||
|
|
@ -56,9 +39,9 @@ class Env implements Plugin
|
|||
$env_var = "$key=$value";
|
||||
}
|
||||
|
||||
if (!putenv($this->phpci->interpolate($env_var))) {
|
||||
if (!putenv($this->builder->interpolate($env_var))) {
|
||||
$success = false;
|
||||
$this->phpci->logFailure(Lang::get('unable_to_set_env'));
|
||||
$this->builder->logFailure(Lang::get('unable_to_set_env'));
|
||||
}
|
||||
}
|
||||
return $success;
|
||||
|
|
|
|||
|
|
@ -20,30 +20,28 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class FlowdockNotify implements Plugin
|
||||
class FlowdockNotify extends Plugin
|
||||
{
|
||||
private $api_key;
|
||||
private $email;
|
||||
protected $api_key;
|
||||
protected $email;
|
||||
protected $message;
|
||||
|
||||
const MESSAGE_DEFAULT = 'Build %BUILD% has finished for commit <a href="%COMMIT_URI%">%SHORT_COMMIT%</a>
|
||||
(%COMMIT_EMAIL%)> on branch <a href="%BRANCH_URI%">%BRANCH%</a>';
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
if (!is_array($options) || !isset($options['api_key'])) {
|
||||
throw new \Exception('Please define the api_key for Flowdock Notify plugin!');
|
||||
}
|
||||
$this->api_key = trim($options['api_key']);
|
||||
$this->message = isset($options['message']) ? $options['message'] : self::MESSAGE_DEFAULT;
|
||||
$this->email = isset($options['email']) ? $options['email'] : 'PHP Censor';
|
||||
$this->email = isset($options['email']) ? $options['email'] : 'PHP Censor';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +52,7 @@ class FlowdockNotify implements Plugin
|
|||
public function execute()
|
||||
{
|
||||
|
||||
$message = $this->phpci->interpolate($this->message);
|
||||
$message = $this->builder->interpolate($this->message);
|
||||
$successfulBuild = $this->build->isSuccessful() ? 'Success' : 'Failed';
|
||||
$push = new Push($this->api_key);
|
||||
$flowMessage = TeamInboxMessage::create()
|
||||
|
|
|
|||
|
|
@ -20,34 +20,17 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Git implements Plugin
|
||||
class Git extends Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $actions = [];
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->actions = $options;
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the Git plugin.
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$buildPath = $this->phpci->buildPath;
|
||||
$buildPath = $this->builder->buildPath;
|
||||
|
||||
// Check if there are any actions to be run for the branch we're running on:
|
||||
if (!array_key_exists($this->build->getBranch(), $this->actions)) {
|
||||
|
|
@ -106,8 +89,8 @@ class Git implements Plugin
|
|||
{
|
||||
if (array_key_exists('branch', $options)) {
|
||||
$cmd = 'cd "%s" && git checkout %s && git merge "%s"';
|
||||
$path = $this->phpci->buildPath;
|
||||
return $this->phpci->executeCommand($cmd, $path, $options['branch'], $this->build->getBranch());
|
||||
$path = $this->builder->buildPath;
|
||||
return $this->builder->executeCommand($cmd, $path, $options['branch'], $this->build->getBranch());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,15 +105,15 @@ class Git implements Plugin
|
|||
$message = Lang::get('tag_created', date('Y-m-d H:i:s'));
|
||||
|
||||
if (array_key_exists('name', $options)) {
|
||||
$tagName = $this->phpci->interpolate($options['name']);
|
||||
$tagName = $this->builder->interpolate($options['name']);
|
||||
}
|
||||
|
||||
if (array_key_exists('message', $options)) {
|
||||
$message = $this->phpci->interpolate($options['message']);
|
||||
$message = $this->builder->interpolate($options['message']);
|
||||
}
|
||||
|
||||
$cmd = 'git tag %s -m "%s"';
|
||||
return $this->phpci->executeCommand($cmd, $tagName, $message);
|
||||
return $this->builder->executeCommand($cmd, $tagName, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -144,14 +127,14 @@ class Git implements Plugin
|
|||
$remote = 'origin';
|
||||
|
||||
if (array_key_exists('branch', $options)) {
|
||||
$branch = $this->phpci->interpolate($options['branch']);
|
||||
$branch = $this->builder->interpolate($options['branch']);
|
||||
}
|
||||
|
||||
if (array_key_exists('remote', $options)) {
|
||||
$remote = $this->phpci->interpolate($options['remote']);
|
||||
$remote = $this->builder->interpolate($options['remote']);
|
||||
}
|
||||
|
||||
return $this->phpci->executeCommand('git pull %s %s', $remote, $branch);
|
||||
return $this->builder->executeCommand('git pull %s %s', $remote, $branch);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -165,13 +148,13 @@ class Git implements Plugin
|
|||
$remote = 'origin';
|
||||
|
||||
if (array_key_exists('branch', $options)) {
|
||||
$branch = $this->phpci->interpolate($options['branch']);
|
||||
$branch = $this->builder->interpolate($options['branch']);
|
||||
}
|
||||
|
||||
if (array_key_exists('remote', $options)) {
|
||||
$remote = $this->phpci->interpolate($options['remote']);
|
||||
$remote = $this->builder->interpolate($options['remote']);
|
||||
}
|
||||
|
||||
return $this->phpci->executeCommand('git push %s %s', $remote, $branch);
|
||||
return $this->builder->executeCommand('git push %s %s', $remote, $branch);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,36 +19,25 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Grunt implements Plugin
|
||||
class Grunt extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $task;
|
||||
protected $preferDist;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $grunt;
|
||||
protected $gruntfile;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$this->build = $build;
|
||||
$this->phpci = $phpci;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$path = $this->builder->buildPath;
|
||||
$this->directory = $path;
|
||||
$this->task = null;
|
||||
$this->grunt = $this->phpci->findBinary('grunt');
|
||||
$this->task = null;
|
||||
$this->grunt = $this->builder->findBinary('grunt');
|
||||
$this->gruntfile = 'Gruntfile.js';
|
||||
|
||||
// Handle options:
|
||||
|
|
@ -67,8 +56,6 @@ class Grunt implements Plugin
|
|||
if (isset($options['gruntfile'])) {
|
||||
$this->gruntfile = $options['gruntfile'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,7 +68,7 @@ class Grunt implements Plugin
|
|||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && npm install';
|
||||
}
|
||||
if (!$this->phpci->executeCommand($cmd, $this->directory)) {
|
||||
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +82,6 @@ class Grunt implements Plugin
|
|||
$cmd .= ' %s'; // the task that will be executed
|
||||
|
||||
// and execute it
|
||||
return $this->phpci->executeCommand($cmd, $this->directory, $this->gruntfile, $this->task);
|
||||
return $this->builder->executeCommand($cmd, $this->directory, $this->gruntfile, $this->task);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,37 +19,26 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Gulp implements Plugin
|
||||
class Gulp extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $task;
|
||||
protected $preferDist;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $gulp;
|
||||
protected $gulpfile;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$this->build = $build;
|
||||
$this->phpci = $phpci;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$path = $this->builder->buildPath;
|
||||
$this->directory = $path;
|
||||
$this->task = null;
|
||||
$this->gulp = $this->phpci->findBinary('gulp');
|
||||
$this->gulpfile = 'gulpfile.js';
|
||||
$this->task = null;
|
||||
$this->gulp = $this->builder->findBinary('gulp');
|
||||
$this->gulpfile = 'gulpfile.js';
|
||||
|
||||
// Handle options:
|
||||
if (isset($options['directory'])) {
|
||||
|
|
@ -67,8 +56,6 @@ class Gulp implements Plugin
|
|||
if (isset($options['gulpfile'])) {
|
||||
$this->gulpfile = $options['gulpfile'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,7 +68,7 @@ class Gulp implements Plugin
|
|||
if (IS_WIN) {
|
||||
$cmd = 'cd /d %s && npm install';
|
||||
}
|
||||
if (!$this->phpci->executeCommand($cmd, $this->directory)) {
|
||||
if (!$this->builder->executeCommand($cmd, $this->directory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +82,6 @@ class Gulp implements Plugin
|
|||
$cmd .= ' %s'; // the task that will be executed
|
||||
|
||||
// and execute it
|
||||
return $this->phpci->executeCommand($cmd, $this->directory, $this->gulpfile, $this->task);
|
||||
return $this->builder->executeCommand($cmd, $this->directory, $this->gulpfile, $this->task);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,26 +21,25 @@ use HipChat\HipChat;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class HipchatNotify implements Plugin
|
||||
class HipchatNotify extends Plugin
|
||||
{
|
||||
protected $authToken;
|
||||
protected $color;
|
||||
protected $notify;
|
||||
protected $userAgent;
|
||||
protected $cookie;
|
||||
protected $message;
|
||||
protected $room;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->userAgent = "PHP Censor/1.0";
|
||||
$this->cookie = "php-censor-cookie";
|
||||
$this->cookie = "php-censor-cookie";
|
||||
|
||||
if (is_array($options) && isset($options['authToken']) && isset($options['room'])) {
|
||||
$this->authToken = $options['authToken'];
|
||||
|
|
@ -75,7 +74,7 @@ class HipchatNotify implements Plugin
|
|||
public function execute()
|
||||
{
|
||||
$hipChat = new HipChat($this->authToken);
|
||||
$message = $this->phpci->interpolate($this->message);
|
||||
$message = $this->builder->interpolate($this->message);
|
||||
|
||||
$result = true;
|
||||
if (is_array($this->room)) {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Irc implements Plugin
|
||||
class Irc extends Plugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $message;
|
||||
protected $server;
|
||||
protected $port;
|
||||
|
|
@ -31,36 +29,23 @@ class Irc implements Plugin
|
|||
protected $nick;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->message = $options['message'];
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
|
||||
$buildSettings = $this->builder->getConfig('build_settings');
|
||||
|
||||
if (isset($buildSettings['irc'])) {
|
||||
$irc = $buildSettings['irc'];
|
||||
|
||||
$this->server = $irc['server'];
|
||||
$this->port = $irc['port'];
|
||||
$this->room = $irc['room'];
|
||||
$this->nick = $irc['nick'];
|
||||
$this->port = $irc['port'];
|
||||
$this->room = $irc['room'];
|
||||
$this->nick = $irc['nick'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -69,10 +54,10 @@ class Irc implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$msg = $this->phpci->interpolate($this->message);
|
||||
$msg = $this->builder->interpolate($this->message);
|
||||
|
||||
if (empty($this->server) || empty($this->room) || empty($this->nick)) {
|
||||
$this->phpci->logFailure(Lang::get('irc_settings'));
|
||||
$this->builder->logFailure(Lang::get('irc_settings'));
|
||||
}
|
||||
|
||||
if (empty($this->port)) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* PHP Lint Plugin - Provides access to PHP lint functionality.
|
||||
|
|
@ -19,32 +20,21 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Lint implements PHPCensor\Plugin
|
||||
class Lint extends Plugin
|
||||
{
|
||||
protected $directories;
|
||||
protected $recursive = true;
|
||||
protected $ignore;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->directories = [''];
|
||||
$this->ignore = $phpci->ignore;
|
||||
$this->ignore = $this->builder->ignore;
|
||||
|
||||
if (!empty($options['directory'])) {
|
||||
$this->directories[] = $options['directory'];
|
||||
|
|
@ -57,8 +47,6 @@ class Lint implements PHPCensor\Plugin
|
|||
if (array_key_exists('recursive', $options)) {
|
||||
$this->recursive = $options['recursive'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,10 +54,10 @@ class Lint implements PHPCensor\Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->phpci->quiet = true;
|
||||
$success = true;
|
||||
$this->builder->quiet = true;
|
||||
$success = true;
|
||||
|
||||
$php = $this->phpci->findBinary('php');
|
||||
$php = $this->builder->findBinary('php');
|
||||
|
||||
foreach ($this->directories as $dir) {
|
||||
if (!$this->lintDirectory($php, $dir)) {
|
||||
|
|
@ -77,7 +65,7 @@ class Lint implements PHPCensor\Plugin
|
|||
}
|
||||
}
|
||||
|
||||
$this->phpci->quiet = false;
|
||||
$this->builder->quiet = false;
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
@ -111,7 +99,7 @@ class Lint implements PHPCensor\Plugin
|
|||
protected function lintDirectory($php, $path)
|
||||
{
|
||||
$success = true;
|
||||
$directory = new \DirectoryIterator($this->phpci->buildPath . $path);
|
||||
$directory = new \DirectoryIterator($this->builder->buildPath . $path);
|
||||
|
||||
foreach ($directory as $item) {
|
||||
if ($item->isDot()) {
|
||||
|
|
@ -142,8 +130,8 @@ class Lint implements PHPCensor\Plugin
|
|||
{
|
||||
$success = true;
|
||||
|
||||
if (!$this->phpci->executeCommand($php . ' -l "%s"', $this->phpci->buildPath . $path)) {
|
||||
$this->phpci->logFailure($path);
|
||||
if (!$this->builder->executeCommand($php . ' -l "%s"', $this->builder->buildPath . $path)) {
|
||||
$this->builder->logFailure($path);
|
||||
$success = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,23 +23,8 @@ use b8\Database;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Mysql implements Plugin
|
||||
class Mysql extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $queries = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -56,16 +41,11 @@ class Mysql implements Plugin
|
|||
protected $pass;
|
||||
|
||||
/**
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
|
||||
$this->queries = $options;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$config = Database::getConnection('write')->getDetails();
|
||||
|
||||
|
|
@ -73,25 +53,23 @@ class Mysql implements Plugin
|
|||
$this->user = $config['user'];
|
||||
$this->pass = $config['pass'];
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
$buildSettings = $this->builder->getConfig('build_settings');
|
||||
|
||||
if (!isset($buildSettings['mysql'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($buildSettings['mysql']['host'])) {
|
||||
$this->host = $this->phpci->interpolate($buildSettings['mysql']['host']);
|
||||
$this->host = $this->builder->interpolate($buildSettings['mysql']['host']);
|
||||
}
|
||||
|
||||
if (!empty($buildSettings['mysql']['user'])) {
|
||||
$this->user = $this->phpci->interpolate($buildSettings['mysql']['user']);
|
||||
$this->user = $this->builder->interpolate($buildSettings['mysql']['user']);
|
||||
}
|
||||
|
||||
if (array_key_exists('pass', $buildSettings['mysql'])) {
|
||||
$this->pass = $buildSettings['mysql']['pass'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -104,10 +82,10 @@ class Mysql implements Plugin
|
|||
$opts = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
|
||||
$pdo = new PDO('mysql:host=' . $this->host, $this->user, $this->pass, $opts);
|
||||
|
||||
foreach ($this->queries as $query) {
|
||||
foreach ($this->options as $query) {
|
||||
if (!is_array($query)) {
|
||||
// Simple query
|
||||
$pdo->query($this->phpci->interpolate($query));
|
||||
$pdo->query($this->builder->interpolate($query));
|
||||
} elseif (isset($query['import'])) {
|
||||
// SQL file execution
|
||||
$this->executeFile($query['import']);
|
||||
|
|
@ -116,7 +94,7 @@ class Mysql implements Plugin
|
|||
}
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->phpci->logFailure($ex->getMessage());
|
||||
$this->builder->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -133,15 +111,15 @@ class Mysql implements Plugin
|
|||
throw new \Exception(Lang::get('import_file_key'));
|
||||
}
|
||||
|
||||
$import_file = $this->phpci->buildPath . $this->phpci->interpolate($query['file']);
|
||||
$import_file = $this->builder->buildPath . $this->builder->interpolate($query['file']);
|
||||
if (!is_readable($import_file)) {
|
||||
throw new \Exception(Lang::get('cannot_open_import', $import_file));
|
||||
}
|
||||
|
||||
$database = isset($query['database']) ? $this->phpci->interpolate($query['database']) : null;
|
||||
$database = isset($query['database']) ? $this->builder->interpolate($query['database']) : null;
|
||||
|
||||
$import_command = $this->getImportCommand($import_file, $database);
|
||||
if (!$this->phpci->executeCommand($import_command)) {
|
||||
if (!$this->builder->executeCommand($import_command)) {
|
||||
throw new \Exception(Lang::get('unable_to_execute'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,29 +19,23 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PackageBuild implements Plugin
|
||||
class PackageBuild extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $filename;
|
||||
protected $format;
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$this->build = $build;
|
||||
$this->phpci = $phpci;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$path = $this->builder->buildPath;
|
||||
$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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +43,7 @@ class PackageBuild implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$path = $this->phpci->buildPath;
|
||||
$path = $this->builder->buildPath;
|
||||
$build = $this->build;
|
||||
|
||||
if ($this->directory == $path) {
|
||||
|
|
@ -65,7 +59,7 @@ class PackageBuild implements Plugin
|
|||
$filename = preg_replace('/([^a-zA-Z0-9_-]+)/', '', $filename);
|
||||
|
||||
$curdir = getcwd();
|
||||
chdir($this->phpci->buildPath);
|
||||
chdir($this->builder->buildPath);
|
||||
|
||||
if (!is_array($this->format)) {
|
||||
$this->format = [$this->format];
|
||||
|
|
@ -82,7 +76,7 @@ class PackageBuild implements Plugin
|
|||
break;
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand($cmd, $this->directory, $filename);
|
||||
$success = $this->builder->executeCommand($cmd, $this->directory, $filename);
|
||||
}
|
||||
|
||||
chdir($curdir);
|
||||
|
|
|
|||
|
|
@ -19,29 +19,30 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Pdepend implements Plugin
|
||||
class Pdepend extends Plugin
|
||||
{
|
||||
protected $args;
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var string Directory which needs to be scanned
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* @var string File where the summary.xml is stored
|
||||
*/
|
||||
protected $summary;
|
||||
|
||||
/**
|
||||
* @var string File where the chart.svg is stored
|
||||
*/
|
||||
protected $chart;
|
||||
|
||||
/**
|
||||
* @var string File where the pyramid.svg is stored
|
||||
*/
|
||||
protected $pyramid;
|
||||
|
||||
/**
|
||||
* @var string Location on the server where the files are stored. Preferably in the webroot for inclusion
|
||||
* in the readme.md of the repository
|
||||
|
|
@ -49,25 +50,19 @@ class Pdepend implements Plugin
|
|||
protected $location;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->directory = isset($options['directory']) ? $options['directory'] : $phpci->buildPath;
|
||||
$this->directory = isset($options['directory']) ? $options['directory'] : $this->builder->buildPath;
|
||||
|
||||
$title = $phpci->getBuildProjectTitle();
|
||||
$title = $this->builder->getBuildProjectTitle();
|
||||
$this->summary = $title . '-summary.xml';
|
||||
$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));
|
||||
$this->location = $this->builder->buildPath . '..' . DIRECTORY_SEPARATOR . 'pdepend';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,20 +77,20 @@ class Pdepend implements Plugin
|
|||
throw new \Exception(sprintf('The location %s is not writable or does not exist.', $this->location));
|
||||
}
|
||||
|
||||
$pdepend = $this->phpci->findBinary('pdepend');
|
||||
$pdepend = $this->builder->findBinary('pdepend');
|
||||
|
||||
$cmd = $pdepend . ' --summary-xml="%s" --jdepend-chart="%s" --overview-pyramid="%s" %s "%s"';
|
||||
|
||||
$this->removeBuildArtifacts();
|
||||
|
||||
// If we need to ignore directories
|
||||
if (count($this->phpci->ignore)) {
|
||||
$ignore = ' --ignore=' . implode(',', $this->phpci->ignore);
|
||||
if (count($this->builder->ignore)) {
|
||||
$ignore = ' --ignore=' . implode(',', $this->builder->ignore);
|
||||
} else {
|
||||
$ignore = '';
|
||||
}
|
||||
|
||||
$success = $this->phpci->executeCommand(
|
||||
$success = $this->builder->executeCommand(
|
||||
$cmd,
|
||||
$this->location . DIRECTORY_SEPARATOR . $this->summary,
|
||||
$this->location . DIRECTORY_SEPARATOR . $this->chart,
|
||||
|
|
@ -104,10 +99,10 @@ class Pdepend implements Plugin
|
|||
$this->directory
|
||||
);
|
||||
|
||||
$config = $this->phpci->getSystemConfig('php-censor');
|
||||
$config = $this->builder->getSystemConfig('php-censor');
|
||||
|
||||
if ($success) {
|
||||
$this->phpci->logSuccess(
|
||||
$this->builder->logSuccess(
|
||||
sprintf(
|
||||
"Pdepend successful. You can use %s\n, \n
|
||||
and \n
|
||||
|
|
|
|||
|
|
@ -20,23 +20,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Pgsql implements Plugin
|
||||
class Pgsql extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $queries = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -53,17 +38,13 @@ class Pgsql implements Plugin
|
|||
protected $pass;
|
||||
|
||||
/**
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->queries = $options;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
$buildSettings = $this->builder->getConfig('build_settings');
|
||||
|
||||
if (isset($buildSettings['pgsql'])) {
|
||||
$sql = $buildSettings['pgsql'];
|
||||
|
|
@ -71,8 +52,6 @@ class Pgsql implements Plugin
|
|||
$this->user = $sql['user'];
|
||||
$this->pass = $sql['pass'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,11 +64,11 @@ class Pgsql implements Plugin
|
|||
$opts = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
|
||||
$pdo = new PDO('pgsql:host=' . $this->host, $this->user, $this->pass, $opts);
|
||||
|
||||
foreach ($this->queries as $query) {
|
||||
$pdo->query($this->phpci->interpolate($query));
|
||||
foreach ($this->options as $query) {
|
||||
$pdo->query($this->builder->interpolate($query));
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->phpci->logFailure($ex->getMessage());
|
||||
$this->builder->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -12,20 +12,8 @@ use PHPCensor\Plugin;
|
|||
/**
|
||||
* Phar Plugin
|
||||
*/
|
||||
class Phar implements Plugin
|
||||
class Phar extends Plugin
|
||||
{
|
||||
/**
|
||||
* PHPCI
|
||||
* @var Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* Build
|
||||
* @var Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* Output Directory
|
||||
* @var string
|
||||
|
|
@ -51,22 +39,11 @@ class Phar implements Plugin
|
|||
protected $stub;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
// Basic
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
// Directory?
|
||||
if (isset($options['directory'])) {
|
||||
|
|
@ -87,28 +64,6 @@ class Phar implements Plugin
|
|||
if (isset($options['stub'])) {
|
||||
$this->setStub($options['stub']);
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PHPCI
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function getPHPCI()
|
||||
{
|
||||
return $this->phpci;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Build
|
||||
*
|
||||
* @return Build
|
||||
*/
|
||||
public function getBuild()
|
||||
{
|
||||
return $this->build;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,7 +86,7 @@ class Phar implements Plugin
|
|||
public function getDirectory()
|
||||
{
|
||||
if (!isset($this->directory)) {
|
||||
$this->setDirectory($this->getPHPCI()->buildPath);
|
||||
$this->setDirectory($this->builder->buildPath);
|
||||
}
|
||||
return $this->directory;
|
||||
}
|
||||
|
|
@ -217,7 +172,7 @@ class Phar implements Plugin
|
|||
$content = '';
|
||||
$filename = $this->getStub();
|
||||
if ($filename) {
|
||||
$content = file_get_contents($this->getPHPCI()->buildPath . DIRECTORY_SEPARATOR . $this->getStub());
|
||||
$content = file_get_contents($this->builder->buildPath . DIRECTORY_SEPARATOR . $this->getStub());
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
|
@ -233,7 +188,7 @@ class Phar implements Plugin
|
|||
try {
|
||||
$file = $this->getDirectory() . DIRECTORY_SEPARATOR . $this->getFilename();
|
||||
$phar = new PHPPhar($file, 0, $this->getFilename());
|
||||
$phar->buildFromDirectory($this->getPHPCI()->buildPath, $this->getRegExp());
|
||||
$phar->buildFromDirectory($this->builder->buildPath, $this->getRegExp());
|
||||
|
||||
$stub = $this->getStubContent();
|
||||
if ($stub) {
|
||||
|
|
@ -242,8 +197,8 @@ class Phar implements Plugin
|
|||
|
||||
$success = true;
|
||||
} catch (Exception $e) {
|
||||
$this->getPHPCI()->log(Lang::get('phar_internal_error'));
|
||||
$this->getPHPCI()->log($e->getMessage());
|
||||
$this->builder->log(Lang::get('phar_internal_error'));
|
||||
$this->builder->log($e->getMessage());
|
||||
}
|
||||
|
||||
return $success;
|
||||
|
|
|
|||
|
|
@ -21,36 +21,29 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Phing implements Plugin
|
||||
class Phing extends Plugin
|
||||
{
|
||||
|
||||
private $directory;
|
||||
private $buildFile = 'build.xml';
|
||||
private $targets = ['build'];
|
||||
private $properties = [];
|
||||
private $propertyFile;
|
||||
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
protected $directory;
|
||||
protected $buildFile = 'build.xml';
|
||||
protected $targets = ['build'];
|
||||
protected $properties = [];
|
||||
protected $propertyFile;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->setPhpci($phpci);
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
/*
|
||||
* Set working directory
|
||||
*/
|
||||
if (isset($options['directory'])) {
|
||||
$directory = $phpci->buildPath . DIRECTORY_SEPARATOR . $options['directory'];
|
||||
$directory = $this->builder->buildPath . DIRECTORY_SEPARATOR . $options['directory'];
|
||||
} else {
|
||||
$directory = $phpci->buildPath;
|
||||
$directory = $this->builder->buildPath;
|
||||
}
|
||||
|
||||
$this->setDirectory($directory);
|
||||
|
|
@ -80,7 +73,7 @@ class Phing implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$phingExecutable = $this->phpci->findBinary('phing');
|
||||
$phingExecutable = $this->builder->findBinary('phing');
|
||||
|
||||
$cmd[] = $phingExecutable . ' -f ' . $this->getBuildFilePath();
|
||||
|
||||
|
|
@ -94,25 +87,7 @@ class Phing implements Plugin
|
|||
$cmd[] = $this->targetsToString();
|
||||
$cmd[] = '2>&1';
|
||||
|
||||
return $this->phpci->executeCommand(implode(' ', $cmd), $this->directory, $this->targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \PHPCensor\Builder
|
||||
*/
|
||||
public function getPhpci()
|
||||
{
|
||||
return $this->phpci;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PHPCensor\Builder $phpci
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPhpci($phpci)
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
return $this->builder->executeCommand(implode(' ', $cmd), $this->directory, $this->targets);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ use PHPCensor;
|
|||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Model\BuildError;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* PHP Code Sniffer Plugin - Allows PHP Code Sniffer testing.
|
||||
|
|
@ -20,13 +22,8 @@ use PHPCensor\Model\BuildError;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class PhpCodeSniffer extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -73,6 +70,41 @@ class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
*/
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->suffixes = ['php'];
|
||||
$this->directory = $this->builder->buildPath;
|
||||
$this->standard = 'PSR2';
|
||||
$this->tab_width = '';
|
||||
$this->encoding = '';
|
||||
$this->path = '';
|
||||
$this->ignore = $this->builder->ignore;
|
||||
$this->allowed_warnings = 0;
|
||||
$this->allowed_errors = 0;
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_warnings = -1;
|
||||
$this->allowed_errors = -1;
|
||||
}
|
||||
|
||||
if (isset($options['suffixes'])) {
|
||||
$this->suffixes = (array)$options['suffixes'];
|
||||
}
|
||||
|
||||
if (!empty($options['tab_width'])) {
|
||||
$this->tab_width = ' --tab-width='.$options['tab_width'];
|
||||
}
|
||||
|
||||
if (!empty($options['encoding'])) {
|
||||
$this->encoding = ' --encoding=' . $options['encoding'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
* @param $stage
|
||||
|
|
@ -89,60 +121,6 @@ class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PHPCensor\Builder $phpci
|
||||
* @param \PHPCensor\Model\Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->suffixes = ['php'];
|
||||
$this->directory = $phpci->buildPath;
|
||||
$this->standard = 'PSR2';
|
||||
$this->tab_width = '';
|
||||
$this->encoding = '';
|
||||
$this->path = '';
|
||||
$this->ignore = $this->phpci->ignore;
|
||||
$this->allowed_warnings = 0;
|
||||
$this->allowed_errors = 0;
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_warnings = -1;
|
||||
$this->allowed_errors = -1;
|
||||
}
|
||||
|
||||
if (isset($options['suffixes'])) {
|
||||
$this->suffixes = (array)$options['suffixes'];
|
||||
}
|
||||
|
||||
if (!empty($options['tab_width'])) {
|
||||
$this->tab_width = ' --tab-width='.$options['tab_width'];
|
||||
}
|
||||
|
||||
if (!empty($options['encoding'])) {
|
||||
$this->encoding = ' --encoding=' . $options['encoding'];
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle this plugin's options.
|
||||
* @param $options
|
||||
*/
|
||||
protected function setOptions($options)
|
||||
{
|
||||
foreach (['directory', 'standard', 'path', 'ignore', 'allowed_warnings', 'allowed_errors'] as $key) {
|
||||
if (array_key_exists($key, $options)) {
|
||||
$this->{$key} = $options[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHP Code Sniffer in a specified directory, to a specified standard.
|
||||
*/
|
||||
|
|
@ -150,25 +128,25 @@ class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
{
|
||||
list($ignore, $standard, $suffixes) = $this->getFlags();
|
||||
|
||||
$phpcs = $this->phpci->findBinary('phpcs');
|
||||
$phpcs = $this->builder->findBinary('phpcs');
|
||||
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
$cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"';
|
||||
$this->phpci->executeCommand(
|
||||
$this->builder->executeCommand(
|
||||
$cmd,
|
||||
$standard,
|
||||
$suffixes,
|
||||
$ignore,
|
||||
$this->tab_width,
|
||||
$this->encoding,
|
||||
$this->phpci->buildPath . $this->path
|
||||
$this->builder->buildPath . $this->path
|
||||
);
|
||||
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$output = $this->builder->getLastOutput();
|
||||
list($errors, $warnings) = $this->processReport($output);
|
||||
|
||||
$this->phpci->logExecOutput(true);
|
||||
$this->builder->logExecOutput(true);
|
||||
|
||||
$success = true;
|
||||
$this->build->storeMeta('phpcs-warnings', $warnings);
|
||||
|
|
@ -221,7 +199,7 @@ class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$data = json_decode(trim($output), true);
|
||||
|
||||
if (!is_array($data)) {
|
||||
$this->phpci->log($output);
|
||||
$this->builder->log($output);
|
||||
throw new \Exception(PHPCensor\Helper\Lang::get('could_not_process_report'));
|
||||
}
|
||||
|
||||
|
|
@ -229,11 +207,11 @@ class PhpCodeSniffer implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$warnings = $data['totals']['warnings'];
|
||||
|
||||
foreach ($data['files'] as $fileName => $file) {
|
||||
$fileName = str_replace($this->phpci->buildPath, '', $fileName);
|
||||
$fileName = str_replace($this->builder->buildPath, '', $fileName);
|
||||
|
||||
foreach ($file['messages'] as $message) {
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'php_code_sniffer',
|
||||
'PHPCS: ' . $message['message'],
|
||||
$message['type'] == 'ERROR' ? BuildError::SEVERITY_HIGH : BuildError::SEVERITY_LOW,
|
||||
|
|
|
|||
|
|
@ -21,12 +21,10 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpCpd implements Plugin
|
||||
class PhpCpd extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $args;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string, based on the assumption the root may not hold the code to be
|
||||
|
|
@ -40,28 +38,22 @@ class PhpCpd implements Plugin
|
|||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->path = $phpci->buildPath;
|
||||
$this->ignore = $phpci->ignore;
|
||||
$this->path = $this->builder->buildPath;
|
||||
$this->ignore = $this->builder->ignore;
|
||||
|
||||
if (!empty($options['path'])) {
|
||||
$this->path = $phpci->buildPath . $options['path'];
|
||||
$this->path = $this->builder->buildPath . $options['path'];
|
||||
}
|
||||
|
||||
if (!empty($options['ignore'])) {
|
||||
$this->ignore = $options['ignore'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -87,14 +79,14 @@ class PhpCpd implements Plugin
|
|||
$ignore = implode('', $ignore);
|
||||
}
|
||||
|
||||
$phpcpd = $this->phpci->findBinary('phpcpd');
|
||||
$phpcpd = $this->builder->findBinary('phpcpd');
|
||||
|
||||
$tmpfilename = tempnam('/tmp', 'phpcpd');
|
||||
|
||||
$cmd = $phpcpd . ' --log-pmd "%s" %s "%s"';
|
||||
$success = $this->phpci->executeCommand($cmd, $tmpfilename, $ignore, $this->path);
|
||||
$success = $this->builder->executeCommand($cmd, $tmpfilename, $ignore, $this->path);
|
||||
|
||||
print $this->phpci->getLastOutput();
|
||||
print $this->builder->getLastOutput();
|
||||
|
||||
$errorCount = $this->processReport(file_get_contents($tmpfilename));
|
||||
$this->build->storeMeta('phpcpd-warnings', $errorCount);
|
||||
|
|
@ -115,7 +107,7 @@ class PhpCpd implements Plugin
|
|||
$xml = simplexml_load_string($xmlString);
|
||||
|
||||
if ($xml === false) {
|
||||
$this->phpci->log($xmlString);
|
||||
$this->builder->log($xmlString);
|
||||
throw new \Exception(Lang::get('could_not_process_report'));
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +115,7 @@ class PhpCpd implements Plugin
|
|||
foreach ($xml->duplication as $duplication) {
|
||||
foreach ($duplication->file as $file) {
|
||||
$fileName = (string)$file['path'];
|
||||
$fileName = str_replace($this->phpci->buildPath, '', $fileName);
|
||||
$fileName = str_replace($this->builder->buildPath, '', $fileName);
|
||||
|
||||
$message = <<<CPD
|
||||
Copy and paste detected:
|
||||
|
|
@ -134,7 +126,7 @@ Copy and paste detected:
|
|||
CPD;
|
||||
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'php_cpd',
|
||||
$message,
|
||||
BuildError::SEVERITY_NORMAL,
|
||||
|
|
|
|||
|
|
@ -19,45 +19,23 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpCsFixer implements Plugin
|
||||
class PhpCsFixer extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
protected $workingDir = '';
|
||||
protected $level = ' --level=psr2';
|
||||
protected $verbose = '';
|
||||
protected $diff = '';
|
||||
protected $levels = array('psr0', 'psr1', 'psr2', 'symfony');
|
||||
protected $levels = ['psr0', 'psr1', 'psr2', 'symfony'];
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->workingdir = $this->phpci->buildPath;
|
||||
$this->workingDir = $this->builder->buildPath;
|
||||
$this->buildArgs($options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -67,12 +45,12 @@ class PhpCsFixer implements Plugin
|
|||
public function execute()
|
||||
{
|
||||
$curdir = getcwd();
|
||||
chdir($this->workingdir);
|
||||
chdir($this->workingDir);
|
||||
|
||||
$phpcsfixer = $this->phpci->findBinary('php-cs-fixer');
|
||||
$phpcsfixer = $this->builder->findBinary('php-cs-fixer');
|
||||
|
||||
$cmd = $phpcsfixer . ' fix . %s %s %s';
|
||||
$success = $this->phpci->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
||||
$success = $this->builder->executeCommand($cmd, $this->verbose, $this->diff, $this->level);
|
||||
|
||||
chdir($curdir);
|
||||
|
||||
|
|
@ -98,7 +76,7 @@ class PhpCsFixer implements Plugin
|
|||
}
|
||||
|
||||
if (isset($options['workingdir']) && $options['workingdir']) {
|
||||
$this->workingdir = $this->phpci->buildPath . $options['workingdir'];
|
||||
$this->workingDir = $this->builder->buildPath . $options['workingdir'];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* PHP Docblock Checker Plugin - Checks your PHP files for appropriate uses of Docblocks
|
||||
|
|
@ -19,18 +21,8 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class PhpDocblockChecker extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string Based on the assumption the root may not hold the code to be
|
||||
* tested, extends the build path.
|
||||
|
|
@ -44,34 +36,16 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
|
||||
protected $skipClasses = false;
|
||||
protected $skipMethods = false;
|
||||
protected $allowed_warnings;
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
* @param $stage
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @return bool
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function canExecute($stage, Builder $builder, Build $build)
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
if ($stage == 'test') {
|
||||
return true;
|
||||
}
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->ignore = $phpci->ignore;
|
||||
$this->ignore = $this->builder->ignore;
|
||||
$this->path = '';
|
||||
$this->allowed_warnings = 0;
|
||||
|
||||
|
|
@ -94,8 +68,22 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
if (array_key_exists('allowed_warnings', $options)) {
|
||||
$this->allowed_warnings = (int)$options['allowed_warnings'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
* @param $stage
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @return bool
|
||||
*/
|
||||
public static function canExecute($stage, Builder $builder, Build $build)
|
||||
{
|
||||
if ($stage == 'test') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -104,7 +92,7 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
public function execute()
|
||||
{
|
||||
// Check that the binary exists:
|
||||
$checker = $this->phpci->findBinary('phpdoccheck');
|
||||
$checker = $this->builder->findBinary('phpdoccheck');
|
||||
|
||||
// Build ignore string:
|
||||
$ignore = '';
|
||||
|
|
@ -123,14 +111,14 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
}
|
||||
|
||||
// Build command string:
|
||||
$path = $this->phpci->buildPath . $this->path;
|
||||
$path = $this->builder->buildPath . $this->path;
|
||||
$cmd = $checker . ' --json --directory="%s"%s%s';
|
||||
|
||||
// Disable exec output logging, as we don't want the XML report in the log:
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
// Run checker:
|
||||
$this->phpci->executeCommand(
|
||||
$this->builder->executeCommand(
|
||||
$cmd,
|
||||
$path,
|
||||
$ignore,
|
||||
|
|
@ -138,9 +126,9 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
);
|
||||
|
||||
// Re-enable exec output logging:
|
||||
$this->phpci->logExecOutput(true);
|
||||
$this->builder->logExecOutput(true);
|
||||
|
||||
$output = json_decode($this->phpci->getLastOutput(), true);
|
||||
$output = json_decode($this->builder->getLastOutput(), true);
|
||||
$errors = count($output);
|
||||
$success = true;
|
||||
|
||||
|
|
@ -170,7 +158,7 @@ class PhpDocblockChecker implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
}
|
||||
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'php_docblock_checker',
|
||||
$message,
|
||||
$severity,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* PHP Loc - Allows PHP Copy / Lines of Code testing.
|
||||
|
|
@ -19,16 +21,12 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpLoc implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class PhpLoc extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
|
|
@ -47,22 +45,17 @@ class PhpLoc implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->directory = $phpci->buildPath;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->directory = $this->builder->buildPath;
|
||||
|
||||
if (isset($options['directory'])) {
|
||||
$this->directory .= $options['directory'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,19 +65,19 @@ class PhpLoc implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
{
|
||||
$ignore = '';
|
||||
|
||||
if (count($this->phpci->ignore)) {
|
||||
if (count($this->builder->ignore)) {
|
||||
$map = function ($item) {
|
||||
return ' --exclude ' . rtrim($item, DIRECTORY_SEPARATOR);
|
||||
};
|
||||
|
||||
$ignore = array_map($map, $this->phpci->ignore);
|
||||
$ignore = array_map($map, $this->builder->ignore);
|
||||
$ignore = implode('', $ignore);
|
||||
}
|
||||
|
||||
$phploc = $this->phpci->findBinary('phploc');
|
||||
$phploc = $this->builder->findBinary('phploc');
|
||||
|
||||
$success = $this->phpci->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$success = $this->builder->executeCommand($phploc . ' %s "%s"', $ignore, $this->directory);
|
||||
$output = $this->builder->getLastOutput();
|
||||
|
||||
if (preg_match_all('/\((LOC|CLOC|NCLOC|LLOC)\)\s+([0-9]+)/', $output, $matches)) {
|
||||
$data = [];
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* PHP Mess Detector Plugin - Allows PHP Mess Detector testing.
|
||||
|
|
@ -19,18 +21,8 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class PhpMessDetector extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -54,6 +46,37 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
* @var array
|
||||
*/
|
||||
protected $rules;
|
||||
protected $allowed_warnings;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->suffixes = ['php'];
|
||||
$this->ignore = $this->builder->ignore;
|
||||
$this->path = '';
|
||||
$this->rules = ['codesize', 'unusedcode', 'naming'];
|
||||
$this->allowed_warnings = 0;
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_warnings = -1;
|
||||
}
|
||||
|
||||
if (!empty($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
|
||||
if (array_key_exists('allowed_warnings', $options)) {
|
||||
$this->allowed_warnings = (int)$options['allowed_warnings'];
|
||||
}
|
||||
|
||||
foreach (['rules', 'ignore', 'suffixes'] as $key) {
|
||||
$this->overrideSetting($options, $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
|
|
@ -71,47 +94,6 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->suffixes = ['php'];
|
||||
$this->ignore = $phpci->ignore;
|
||||
$this->path = '';
|
||||
$this->rules = ['codesize', 'unusedcode', 'naming'];
|
||||
$this->allowed_warnings = 0;
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_warnings = -1;
|
||||
}
|
||||
|
||||
if (!empty($options['path'])) {
|
||||
$this->path = $options['path'];
|
||||
}
|
||||
|
||||
if (array_key_exists('allowed_warnings', $options)) {
|
||||
$this->allowed_warnings = (int)$options['allowed_warnings'];
|
||||
}
|
||||
|
||||
foreach (['rules', 'ignore', 'suffixes'] as $key) {
|
||||
$this->overrideSetting($options, $key);
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHP Mess Detector in a specified directory.
|
||||
*/
|
||||
|
|
@ -121,11 +103,11 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
$phpmdBinaryPath = $this->phpci->findBinary('phpmd');
|
||||
$phpmdBinaryPath = $this->builder->findBinary('phpmd');
|
||||
|
||||
$this->executePhpMd($phpmdBinaryPath);
|
||||
|
||||
$errorCount = $this->processReport(trim($this->phpci->getLastOutput()));
|
||||
$errorCount = $this->processReport(trim($this->builder->getLastOutput()));
|
||||
$this->build->storeMeta('phpmd-warnings', $errorCount);
|
||||
|
||||
return $this->wasLastExecSuccessful($errorCount);
|
||||
|
|
@ -145,8 +127,11 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
|
||||
/**
|
||||
* Process PHPMD's XML output report.
|
||||
*
|
||||
* @param $xmlString
|
||||
* @return array
|
||||
*
|
||||
* @return integer
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function processReport($xmlString)
|
||||
|
|
@ -154,7 +139,7 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$xml = simplexml_load_string($xmlString);
|
||||
|
||||
if ($xml === false) {
|
||||
$this->phpci->log($xmlString);
|
||||
$this->builder->log($xmlString);
|
||||
throw new \Exception('Could not process PHPMD report XML.');
|
||||
}
|
||||
|
||||
|
|
@ -162,13 +147,13 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
|
||||
foreach ($xml->file as $file) {
|
||||
$fileName = (string)$file['name'];
|
||||
$fileName = str_replace($this->phpci->buildPath, '', $fileName);
|
||||
$fileName = str_replace($this->builder->buildPath, '', $fileName);
|
||||
|
||||
foreach ($file->violation as $violation) {
|
||||
$warnings++;
|
||||
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'php_mess_detector',
|
||||
(string)$violation,
|
||||
PHPCensor\Model\BuildError::SEVERITY_HIGH,
|
||||
|
|
@ -183,19 +168,19 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* Try and process the rules parameter from phpci.yml.
|
||||
* Try and process the rules parameter from .php-censor.yml.
|
||||
* @return bool
|
||||
*/
|
||||
protected function tryAndProcessRules()
|
||||
{
|
||||
if (!empty($this->rules) && !is_array($this->rules)) {
|
||||
$this->phpci->logFailure('The "rules" option must be an array.');
|
||||
$this->builder->logFailure('The "rules" option must be an array.');
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->rules as &$rule) {
|
||||
if (strpos($rule, '/') !== false) {
|
||||
$rule = $this->phpci->buildPath . $rule;
|
||||
$rule = $this->builder->buildPath . $rule;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -223,10 +208,10 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
}
|
||||
|
||||
// Disable exec output logging, as we don't want the XML report in the log:
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
// Run PHPMD:
|
||||
$this->phpci->executeCommand(
|
||||
$this->builder->executeCommand(
|
||||
$cmd,
|
||||
$path,
|
||||
implode(',', $this->rules),
|
||||
|
|
@ -235,7 +220,7 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
);
|
||||
|
||||
// Re-enable exec output logging:
|
||||
$this->phpci->logExecOutput(true);
|
||||
$this->builder->logExecOutput(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -244,7 +229,7 @@ class PhpMessDetector implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
*/
|
||||
protected function getTargetPath()
|
||||
{
|
||||
$path = $this->phpci->buildPath . $this->path;
|
||||
$path = $this->builder->buildPath . $this->path;
|
||||
if (!empty($this->path) && $this->path{0} == '/') {
|
||||
$path = $this->path;
|
||||
return $path;
|
||||
|
|
|
|||
|
|
@ -19,18 +19,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpParallelLint implements Plugin
|
||||
class PhpParallelLint extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -42,33 +32,22 @@ class PhpParallelLint implements Plugin
|
|||
protected $ignore;
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->directory = $phpci->buildPath;
|
||||
$this->ignore = $this->phpci->ignore;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->directory = $this->builder->buildPath;
|
||||
$this->ignore = $this->builder->ignore;
|
||||
|
||||
if (isset($options['directory'])) {
|
||||
$this->directory = $phpci->buildPath.$options['directory'];
|
||||
$this->directory = $this->builder->buildPath.$options['directory'];
|
||||
}
|
||||
|
||||
if (isset($options['ignore'])) {
|
||||
$this->ignore = $options['ignore'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,16 +57,16 @@ class PhpParallelLint implements Plugin
|
|||
{
|
||||
list($ignore) = $this->getFlags();
|
||||
|
||||
$phplint = $this->phpci->findBinary('parallel-lint');
|
||||
$phplint = $this->builder->findBinary('parallel-lint');
|
||||
|
||||
$cmd = $phplint . ' %s "%s"';
|
||||
$success = $this->phpci->executeCommand(
|
||||
$success = $this->builder->executeCommand(
|
||||
$cmd,
|
||||
$ignore,
|
||||
$this->directory
|
||||
);
|
||||
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$output = $this->builder->getLastOutput();
|
||||
|
||||
$matches = [];
|
||||
if (preg_match_all('/Parse error\:/', $output, $matches)) {
|
||||
|
|
@ -105,7 +84,7 @@ class PhpParallelLint implements Plugin
|
|||
{
|
||||
$ignoreFlags = [];
|
||||
foreach ($this->ignore as $ignoreDir) {
|
||||
$ignoreFlags[] = '--exclude "' . $this->phpci->buildPath . $ignoreDir . '"';
|
||||
$ignoreFlags[] = '--exclude "' . $this->builder->buildPath . $ignoreDir . '"';
|
||||
}
|
||||
$ignore = implode(' ', $ignoreFlags);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* PHP Spec Plugin - Allows PHP Spec testing.
|
||||
|
|
@ -19,50 +20,20 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpSpec implements PHPCensor\Plugin
|
||||
class PhpSpec extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs PHP Spec tests.
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$curdir = getcwd();
|
||||
chdir($this->phpci->buildPath);
|
||||
chdir($this->builder->buildPath);
|
||||
|
||||
$phpspec = $this->phpci->findBinary(['phpspec', 'phpspec.php']);
|
||||
$phpspec = $this->builder->findBinary(['phpspec', 'phpspec.php']);
|
||||
|
||||
$success = $this->phpci->executeCommand($phpspec . ' --format=junit --no-code-generation run');
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$success = $this->builder->executeCommand($phpspec . ' --format=junit --no-code-generation run');
|
||||
$output = $this->builder->getLastOutput();
|
||||
|
||||
chdir($curdir);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,30 +12,22 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* PHPTAL Lint Plugin - Provides access to PHPTAL lint functionality.
|
||||
*
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpTalLint implements PHPCensor\Plugin
|
||||
class PhpTalLint extends Plugin
|
||||
{
|
||||
protected $directories;
|
||||
protected $recursive = true;
|
||||
protected $suffixes;
|
||||
protected $ignore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string The path to a file contain custom phptal_tales_ functions
|
||||
*/
|
||||
|
|
@ -57,19 +49,15 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
protected $failedPaths = [];
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->directories = [''];
|
||||
$this->suffixes = ['zpt'];
|
||||
$this->ignore = $phpci->ignore;
|
||||
$this->ignore = $this->builder->ignore;
|
||||
|
||||
$this->allowed_warnings = 0;
|
||||
$this->allowed_errors = 0;
|
||||
|
|
@ -81,23 +69,6 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
if (isset($options['suffixes'])) {
|
||||
$this->suffixes = (array)$options['suffixes'];
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle this plugin's options.
|
||||
* @param $options
|
||||
*/
|
||||
protected function setOptions($options)
|
||||
{
|
||||
foreach (['directories', 'tales', 'allowed_warnings', 'allowed_errors'] as $key) {
|
||||
if (array_key_exists($key, $options)) {
|
||||
$this->{$key} = $options[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -105,15 +76,15 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->phpci->quiet = true;
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->quiet = true;
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
foreach ($this->directories as $dir) {
|
||||
$this->lintDirectory($dir);
|
||||
}
|
||||
|
||||
$this->phpci->quiet = false;
|
||||
$this->phpci->logExecOutput(true);
|
||||
$this->builder->quiet = false;
|
||||
$this->builder->logExecOutput(true);
|
||||
|
||||
$errors = 0;
|
||||
$warnings = 0;
|
||||
|
|
@ -172,7 +143,7 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
protected function lintDirectory($path)
|
||||
{
|
||||
$success = true;
|
||||
$directory = new \DirectoryIterator($this->phpci->buildPath . $path);
|
||||
$directory = new \DirectoryIterator($this->builder->buildPath . $path);
|
||||
|
||||
foreach ($directory as $item) {
|
||||
if ($item->isDot()) {
|
||||
|
|
@ -209,9 +180,9 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
$lint .= 'tools' . DIRECTORY_SEPARATOR . 'phptal_lint.php';
|
||||
$cmd = '/usr/bin/env php ' . $lint . ' %s %s "%s"';
|
||||
|
||||
$this->phpci->executeCommand($cmd, $suffixes, $tales, $this->phpci->buildPath . $path);
|
||||
$this->builder->executeCommand($cmd, $suffixes, $tales, $this->builder->buildPath . $path);
|
||||
|
||||
$output = $this->phpci->getLastOutput();
|
||||
$output = $this->builder->getLastOutput();
|
||||
|
||||
if (preg_match('/Found (.+?) (error|warning)/i', $output, $matches)) {
|
||||
$rows = explode(PHP_EOL, $output);
|
||||
|
|
@ -254,7 +225,7 @@ class PhpTalLint implements PHPCensor\Plugin
|
|||
{
|
||||
$tales = '';
|
||||
if (!empty($this->tales)) {
|
||||
$tales = ' -i ' . $this->phpci->buildPath . $this->tales;
|
||||
$tales = ' -i ' . $this->builder->buildPath . $this->tales;
|
||||
}
|
||||
|
||||
$suffixes = '';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
|
|
@ -17,6 +16,8 @@ use PHPCensor\Model\Build;
|
|||
use PHPCensor\Model\BuildError;
|
||||
use PHPCensor\Plugin\Option\PhpUnitOptions;
|
||||
use PHPCensor\Plugin\Util\PhpUnitResult;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* PHP Unit Plugin - A rewrite of the original PHP Unit plugin
|
||||
|
|
@ -26,11 +27,8 @@ use PHPCensor\Plugin\Util\PhpUnitResult;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class PhpUnit extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/** @var string[] Raw options from the PHPCI config file */
|
||||
protected $options = array();
|
||||
|
||||
|
|
@ -42,14 +40,14 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
* $options['directory'] Optional directory or list of directories to run PHPUnit on.
|
||||
* $options['args'] Command line args (in string format) to pass to PHP Unit
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @param string[] $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = array())
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->options = new PhpUnitOptions($options);
|
||||
}
|
||||
|
||||
|
|
@ -79,11 +77,11 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$xmlConfigFiles = $this->options->getConfigFiles($this->build->getBuildPath());
|
||||
$directories = $this->options->getDirectories();
|
||||
if (empty($xmlConfigFiles) && empty($directories)) {
|
||||
$this->phpci->logFailure(Lang::get('phpunit_fail_init'));
|
||||
$this->builder->logFailure(Lang::get('phpunit_fail_init'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$success = array();
|
||||
$success = [];
|
||||
|
||||
// Run any directories
|
||||
if (!empty($directories)) {
|
||||
|
|
@ -120,9 +118,9 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
// Removes any current configurations files
|
||||
$options->removeArgument('configuration');
|
||||
|
||||
$arguments = $this->phpci->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->phpci->findBinary('phpunit') . ' %s "%s"';
|
||||
$success = $this->phpci->executeCommand($cmd, $arguments, $directory);
|
||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->builder->findBinary('phpunit') . ' %s "%s"';
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $directory);
|
||||
|
||||
$this->processResults($jsonFile);
|
||||
|
||||
|
|
@ -150,9 +148,9 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
// Only the add the configuration file been passed
|
||||
$options->addArgument('configuration', $buildPath . $configFile);
|
||||
|
||||
$arguments = $this->phpci->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->phpci->findBinary('phpunit') . ' %s %s';
|
||||
$success = $this->phpci->executeCommand($cmd, $arguments, $options->getTestsPath());
|
||||
$arguments = $this->builder->interpolate($options->buildArgumentString());
|
||||
$cmd = $this->builder->findBinary('phpunit') . ' %s %s';
|
||||
$success = $this->builder->executeCommand($cmd, $arguments, $options->getTestsPath());
|
||||
|
||||
$this->processResults($jsonFile);
|
||||
|
||||
|
|
@ -168,7 +166,6 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
*/
|
||||
protected function processResults($jsonFile)
|
||||
{
|
||||
var_dump('fuck!');
|
||||
if (file_exists($jsonFile)) {
|
||||
$parser = new PhpUnitResult($jsonFile, $this->build->getBuildPath());
|
||||
|
||||
|
|
@ -178,7 +175,7 @@ class PhpUnit implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
foreach ($parser->getErrors() as $error) {
|
||||
$severity = $error['severity'] == $parser::SEVERITY_ERROR ? BuildError::SEVERITY_CRITICAL : BuildError::SEVERITY_HIGH;
|
||||
$this->build->reportError(
|
||||
$this->phpci, 'php_unit', $error['message'], $severity, $error['file'], $error['line']
|
||||
$this->builder, 'php_unit', $error['message'], $severity, $error['file'], $error['line']
|
||||
);
|
||||
}
|
||||
@unlink($jsonFile);
|
||||
|
|
|
|||
|
|
@ -19,18 +19,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Shell implements Plugin
|
||||
class Shell extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
protected $args;
|
||||
|
||||
/**
|
||||
|
|
@ -39,25 +29,15 @@ class Shell implements Plugin
|
|||
protected $commands = [];
|
||||
|
||||
/**
|
||||
* Standard Constructor
|
||||
*
|
||||
* $options['directory'] Output Directory. Default: %BUILDPATH%
|
||||
* $options['filename'] Phar Filename. Default: build.phar
|
||||
* $options['regexp'] Regular Expression Filename Capture. Default: /\.php$/
|
||||
* $options['stub'] Stub Content. No Default Value
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
if (isset($options['command'])) {
|
||||
// Keeping this for backwards compatibility, new projects should use interpolation vars.
|
||||
$options['command'] = str_replace("%buildpath%", $this->phpci->buildPath, $options['command']);
|
||||
$options['command'] = str_replace("%buildpath%", $this->builder->buildPath, $options['command']);
|
||||
$this->commands = [$options['command']];
|
||||
return;
|
||||
}
|
||||
|
|
@ -72,8 +52,6 @@ class Shell implements Plugin
|
|||
if (is_array($options)) {
|
||||
$this->commands = $options;
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,9 +62,9 @@ class Shell implements Plugin
|
|||
$success = true;
|
||||
|
||||
foreach ($this->commands as $command) {
|
||||
$command = $this->phpci->interpolate($command);
|
||||
$command = $this->builder->interpolate($command);
|
||||
|
||||
if (!$this->phpci->executeCommand($command)) {
|
||||
if (!$this->builder->executeCommand($command)) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ use Maknz\Slack\AttachmentField;
|
|||
|
||||
/**
|
||||
* Slack Plugin
|
||||
*
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class SlackNotify implements Plugin
|
||||
class SlackNotify extends Plugin
|
||||
{
|
||||
private $webHook;
|
||||
private $room;
|
||||
|
|
@ -31,16 +32,11 @@ class SlackNotify implements Plugin
|
|||
private $show_status;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* @throws \Exception
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
if (is_array($options) && isset($options['webhook_url'])) {
|
||||
$this->webHook = trim($options['webhook_url']);
|
||||
|
|
@ -85,7 +81,7 @@ class SlackNotify implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$body = $this->phpci->interpolate($this->message);
|
||||
$body = $this->builder->interpolate($this->message);
|
||||
|
||||
$client = new Client($this->webHook);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,18 +20,8 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Sqlite implements Plugin
|
||||
class Sqlite extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -43,23 +33,18 @@ class Sqlite implements Plugin
|
|||
protected $path;
|
||||
|
||||
/**
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->queries = $options;
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$buildSettings = $this->builder->getConfig('build_settings');
|
||||
|
||||
if (isset($buildSettings['sqlite'])) {
|
||||
$sql = $buildSettings['sqlite'];
|
||||
$sql = $buildSettings['sqlite'];
|
||||
$this->path = $sql['path'];
|
||||
}
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,10 +58,10 @@ class Sqlite implements Plugin
|
|||
$pdo = new PDO('sqlite:' . $this->path, $opts);
|
||||
|
||||
foreach ($this->queries as $query) {
|
||||
$pdo->query($this->phpci->interpolate($query));
|
||||
$pdo->query($this->builder->interpolate($query));
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
$this->phpci->logFailure($ex->getMessage());
|
||||
$this->builder->logFailure($ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace PHPCensor\Plugin;
|
|||
use PHPCensor;
|
||||
use PHPCensor\Builder;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Plugin;
|
||||
use PHPCensor\ZeroConfigPlugin;
|
||||
|
||||
/**
|
||||
* Technical Debt Plugin - Checks for existence of "TODO", "FIXME", etc.
|
||||
|
|
@ -20,13 +22,8 @@ use PHPCensor\Model\Build;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class TechnicalDebt implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
||||
class TechnicalDebt extends Plugin implements ZeroConfigPlugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -58,6 +55,28 @@ class TechnicalDebt implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
*/
|
||||
protected $searches;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->suffixes = ['php'];
|
||||
$this->directory = $this->builder->buildPath;
|
||||
$this->path = '';
|
||||
$this->ignore = $this->builder->ignore;
|
||||
$this->allowed_errors = 0;
|
||||
$this->searches = ['TODO', 'FIXME', 'TO DO', 'FIX ME'];
|
||||
|
||||
if (isset($options['searches']) && is_array($options['searches'])) {
|
||||
$this->searches = $options['searches'];
|
||||
}
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_errors = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this plugin can be executed.
|
||||
|
|
@ -76,59 +95,17 @@ class TechnicalDebt implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PHPCensor\Builder $phpci
|
||||
* @param \PHPCensor\Model\Build $build
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
$this->suffixes = ['php'];
|
||||
$this->directory = $phpci->buildPath;
|
||||
$this->path = '';
|
||||
$this->ignore = $this->phpci->ignore;
|
||||
$this->allowed_errors = 0;
|
||||
$this->searches = ['TODO', 'FIXME', 'TO DO', 'FIX ME'];
|
||||
|
||||
if (isset($options['searches']) && is_array($options['searches'])) {
|
||||
$this->searches = $options['searches'];
|
||||
}
|
||||
|
||||
if (isset($options['zero_config']) && $options['zero_config']) {
|
||||
$this->allowed_errors = -1;
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle this plugin's options.
|
||||
* @param $options
|
||||
*/
|
||||
protected function setOptions($options)
|
||||
{
|
||||
foreach (['directory', 'path', 'ignore', 'allowed_errors'] as $key) {
|
||||
if (array_key_exists($key, $options)) {
|
||||
$this->{$key} = $options[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the plugin
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$success = true;
|
||||
$this->phpci->logExecOutput(false);
|
||||
$this->builder->logExecOutput(false);
|
||||
|
||||
$errorCount = $this->getErrorList();
|
||||
|
||||
$this->phpci->log("Found $errorCount instances of " . implode(', ', $this->searches));
|
||||
$this->builder->log("Found $errorCount instances of " . implode(', ', $this->searches));
|
||||
|
||||
$this->build->storeMeta('technical_debt-warnings', $errorCount);
|
||||
|
||||
|
|
@ -194,7 +171,7 @@ class TechnicalDebt implements PHPCensor\Plugin, PHPCensor\ZeroConfigPlugin
|
|||
$fileName = str_replace($this->directory, '', $file);
|
||||
|
||||
$this->build->reportError(
|
||||
$this->phpci,
|
||||
$this->builder,
|
||||
'technical_debt',
|
||||
$content,
|
||||
PHPCensor\Model\BuildError::SEVERITY_LOW,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use PHPCensor\Plugin;
|
|||
|
||||
/**
|
||||
* Class ComposerPluginInformation
|
||||
*
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class ComposerPluginInformation implements InstalledPluginInformation
|
||||
|
|
@ -34,15 +35,6 @@ class ComposerPluginInformation implements InstalledPluginInformation
|
|||
return new self($installed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass[] $composerPackages This should be the contents of the
|
||||
* installed.json file created by composer
|
||||
*/
|
||||
public function __construct(array $composerPackages)
|
||||
{
|
||||
$this->composerPackages = $composerPackages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of objects. Each one represents an available plugin
|
||||
* and will have the following properties:
|
||||
|
|
@ -52,7 +44,6 @@ class ComposerPluginInformation implements InstalledPluginInformation
|
|||
*/
|
||||
public function getInstalledPlugins()
|
||||
{
|
||||
$this->loadPluginInfo();
|
||||
return $this->pluginInfo;
|
||||
}
|
||||
|
||||
|
|
@ -72,44 +63,6 @@ class ComposerPluginInformation implements InstalledPluginInformation
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a list of available plugins from the installed composer packages.
|
||||
*/
|
||||
protected function loadPluginInfo()
|
||||
{
|
||||
if ($this->pluginInfo !== null) {
|
||||
return;
|
||||
}
|
||||
$this->pluginInfo = [];
|
||||
foreach ($this->composerPackages as $package) {
|
||||
$this->addPluginsFromPackage($package);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass $package
|
||||
*/
|
||||
protected function addPluginsFromPackage($package)
|
||||
{
|
||||
if (isset($package->extra->phpci)) {
|
||||
$phpciData = $package->extra->phpci;
|
||||
|
||||
if (isset($phpciData->pluginNamespace)) {
|
||||
$rootNamespace = $phpciData->pluginNamespace;
|
||||
} else {
|
||||
$rootNamespace = "";
|
||||
}
|
||||
|
||||
if (is_array($phpciData->suppliedPlugins)) {
|
||||
$this->addPlugins(
|
||||
$phpciData->suppliedPlugins,
|
||||
$package->name,
|
||||
$rootNamespace
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \stdClass[] $plugins
|
||||
* @param string $sourcePackageName
|
||||
|
|
|
|||
|
|
@ -8,37 +8,46 @@ 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.
|
||||
*
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class Executor
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var BuildLogger
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var Factory
|
||||
*/
|
||||
protected $pluginFactory;
|
||||
|
||||
/**
|
||||
* @var BuildStore
|
||||
*/
|
||||
protected $store;
|
||||
|
||||
/**
|
||||
* @param Factory $pluginFactory
|
||||
* @param Builder $builder
|
||||
* @param Build $build
|
||||
* @param BuildLogger $logger
|
||||
*/
|
||||
public function __construct(Factory $pluginFactory, BuildLogger $logger, BuildStore $store = null)
|
||||
public function __construct(Builder $builder, Build $build, BuildLogger $logger)
|
||||
{
|
||||
$this->pluginFactory = $pluginFactory;
|
||||
$this->logger = $logger;
|
||||
$this->store = $store ?: StoreFactory::getStore('Build');
|
||||
$this->builder = $builder;
|
||||
$this->build = $build;
|
||||
$this->logger = $logger;
|
||||
$this->store = StoreFactory::getStore('Build');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,7 +87,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 +199,7 @@ class Executor
|
|||
}
|
||||
|
||||
try {
|
||||
// Build and run it
|
||||
$obj = $this->pluginFactory->buildPlugin($class, $options);
|
||||
|
||||
return $obj->execute();
|
||||
return (new $class($this->builder, $this->build, $options))->execute();
|
||||
} catch (\Exception $ex) {
|
||||
$this->logger->logFailure(Lang::get('exception') . $ex->getMessage(), $ex);
|
||||
|
||||
|
|
@ -235,7 +241,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 +254,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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Plugin\Util;
|
||||
|
||||
use Pimple\Container;
|
||||
|
||||
/**
|
||||
* Plugin Factory - Loads Plugins and passes required dependencies.
|
||||
* @package PHPCensor\Plugin\Util
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
const TYPE_ARRAY = "array";
|
||||
const TYPE_CALLABLE = "callable";
|
||||
const INTERFACE_PLUGIN = '\PHPCensor\Plugin';
|
||||
|
||||
private $currentPluginOptions;
|
||||
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
*/
|
||||
public function __construct(Container $container = null)
|
||||
{
|
||||
if ($container) {
|
||||
$this->container = $container;
|
||||
} else {
|
||||
$this->container = new Container();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trys to get a function from the file path specified. If the
|
||||
* file returns a function then $this will be passed to it.
|
||||
* This enables the config file to call any public methods.
|
||||
*
|
||||
* @param $configPath
|
||||
* @return bool - true if the function exists else false.
|
||||
*/
|
||||
public function addConfigFromFile($configPath)
|
||||
{
|
||||
// The file is expected to return a function which can
|
||||
// act on the pluginFactory to register any resources needed.
|
||||
if (file_exists($configPath)) {
|
||||
$configFunction = require($configPath);
|
||||
if (is_callable($configFunction)) {
|
||||
$configFunction($this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get most recently used factory options.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLastOptions()
|
||||
{
|
||||
return $this->currentPluginOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an instance of plugin of class $className. $options will
|
||||
* be passed along with any resources registered with the factory.
|
||||
*
|
||||
* @param $className
|
||||
* @param array|null $options
|
||||
* @throws \InvalidArgumentException if $className doesn't represent a valid plugin
|
||||
* @return \PHPCensor\Plugin
|
||||
*/
|
||||
public function buildPlugin($className, $options = [])
|
||||
{
|
||||
$this->currentPluginOptions = $options;
|
||||
|
||||
$reflectedPlugin = new \ReflectionClass($className);
|
||||
|
||||
if (!$reflectedPlugin->implementsInterface(self::INTERFACE_PLUGIN)) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Requested class must implement " . self:: INTERFACE_PLUGIN
|
||||
);
|
||||
}
|
||||
|
||||
$constructor = $reflectedPlugin->getConstructor();
|
||||
|
||||
if ($constructor) {
|
||||
$argsToUse = [];
|
||||
foreach ($constructor->getParameters() as $param) {
|
||||
if ('options' === $param->getName()) {
|
||||
$argsToUse[] = $options;
|
||||
} else {
|
||||
$argsToUse = $this->addArgFromParam($argsToUse, $param);
|
||||
}
|
||||
}
|
||||
$plugin = $reflectedPlugin->newInstanceArgs($argsToUse);
|
||||
} else {
|
||||
$plugin = $reflectedPlugin->newInstance();
|
||||
}
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $loader
|
||||
* @param string|null $name
|
||||
* @param string|null $type
|
||||
* @throws \InvalidArgumentException
|
||||
* @internal param mixed $resource
|
||||
*/
|
||||
public function registerResource(
|
||||
$loader,
|
||||
$name = null,
|
||||
$type = null
|
||||
) {
|
||||
if ($name === null && $type === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
"Type or Name must be specified"
|
||||
);
|
||||
}
|
||||
|
||||
if (!($loader instanceof \Closure)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'$loader is expected to be a function'
|
||||
);
|
||||
}
|
||||
|
||||
$resourceID = $this->getInternalID($type, $name);
|
||||
|
||||
$this->container[$resourceID] = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an internal resource ID.
|
||||
* @param null $type
|
||||
* @param null $name
|
||||
* @return string
|
||||
*/
|
||||
private function getInternalID($type = null, $name = null)
|
||||
{
|
||||
$type = $type ? : "";
|
||||
$name = $name ? : "";
|
||||
return $type . "-" . $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResourceFor($type = null, $name = null)
|
||||
{
|
||||
$fullId = $this->getInternalID($type, $name);
|
||||
if (isset($this->container[$fullId])) {
|
||||
return $this->container[$fullId];
|
||||
}
|
||||
|
||||
$typeOnlyID = $this->getInternalID($type, null);
|
||||
if (isset($this->container[$typeOnlyID])) {
|
||||
return $this->container[$typeOnlyID];
|
||||
}
|
||||
|
||||
$nameOnlyID = $this->getInternalID(null, $name);
|
||||
if (isset($this->container[$nameOnlyID])) {
|
||||
return $this->container[$nameOnlyID];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionParameter $param
|
||||
* @return null|string
|
||||
*/
|
||||
private function getParamType(\ReflectionParameter $param)
|
||||
{
|
||||
$class = $param->getClass();
|
||||
if ($class) {
|
||||
return $class->getName();
|
||||
} elseif ($param->isArray()) {
|
||||
return self::TYPE_ARRAY;
|
||||
} elseif (is_callable($param)) {
|
||||
return self::TYPE_CALLABLE;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $existingArgs
|
||||
* @param \ReflectionParameter $param
|
||||
* @return array
|
||||
* @throws \DomainException
|
||||
*/
|
||||
private function addArgFromParam($existingArgs, \ReflectionParameter $param)
|
||||
{
|
||||
$name = $param->getName();
|
||||
$type = $this->getParamType($param);
|
||||
$arg = $this->getResourceFor($type, $name);
|
||||
|
||||
if ($arg !== null) {
|
||||
$existingArgs[] = $arg;
|
||||
} elseif ($arg === null && $param->isOptional()) {
|
||||
$existingArgs[] = $param->getDefaultValue();
|
||||
} else {
|
||||
throw new \DomainException(
|
||||
"Unsatisfied dependency: " . $param->getName()
|
||||
);
|
||||
}
|
||||
|
||||
return $existingArgs;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,23 +12,21 @@ use PHPCensor\Builder;
|
|||
*/
|
||||
class Codeception implements ParserInterface
|
||||
{
|
||||
protected $phpci;
|
||||
protected $builder;
|
||||
protected $resultsXml;
|
||||
|
||||
protected $results;
|
||||
|
||||
protected $totalTests;
|
||||
protected $totalTimeTaken;
|
||||
protected $totalFailures;
|
||||
protected $totalErrors;
|
||||
|
||||
/**
|
||||
* @param Builder $phpci
|
||||
* @param Builder $builder
|
||||
* @param $resultsXml
|
||||
*/
|
||||
public function __construct(Builder $phpci, $resultsXml)
|
||||
public function __construct(Builder $builder, $resultsXml)
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->builder = $builder;
|
||||
$this->resultsXml = $resultsXml;
|
||||
$this->totalTests = 0;
|
||||
}
|
||||
|
|
@ -51,7 +49,7 @@ class Codeception implements ParserInterface
|
|||
foreach ($test_suite->testcase as $test_case) {
|
||||
$test_result = [
|
||||
'suite' => (string)$test_suite['name'],
|
||||
'file' => str_replace($this->phpci->buildPath, '/', (string) $test_case['file']),
|
||||
'file' => str_replace($this->builder->buildPath, '/', (string) $test_case['file']),
|
||||
'name' => (string)$test_case['name'],
|
||||
'feature' => (string)$test_case['feature'],
|
||||
'assertions' => (int)$test_case['assertions'],
|
||||
|
|
|
|||
|
|
@ -19,34 +19,19 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Wipe implements Plugin
|
||||
class Wipe extends Plugin
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Builder
|
||||
*/
|
||||
protected $phpci;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Model\Build
|
||||
*/
|
||||
protected $build;
|
||||
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
* Set up the plugin, configure options, etc.
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$path = $phpci->buildPath;
|
||||
$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));
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$path = $this->builder->buildPath;
|
||||
$this->directory = isset($options['directory']) ? $this->builder->interpolate($options['directory']) : $path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +39,7 @@ class Wipe implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$build = $this->phpci->buildPath;
|
||||
$build = $this->builder->buildPath;
|
||||
|
||||
if ($this->directory == $build || empty($this->directory)) {
|
||||
return true;
|
||||
|
|
@ -64,7 +49,7 @@ class Wipe implements Plugin
|
|||
if (IS_WIN) {
|
||||
$cmd = 'rmdir /S /Q "%s"';
|
||||
}
|
||||
return $this->phpci->executeCommand($cmd, $this->directory);
|
||||
return $this->builder->executeCommand($cmd, $this->directory);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ use PHPCensor\Plugin;
|
|||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class XMPP implements Plugin
|
||||
class XMPP extends Plugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $phpci;
|
||||
protected $build;
|
||||
|
||||
/**
|
||||
* @var string, username of sender account xmpp
|
||||
|
|
@ -61,15 +59,11 @@ class XMPP implements Plugin
|
|||
protected $date_format;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Builder $phpci
|
||||
* @param Build $build
|
||||
* @param array $options
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(Builder $phpci, Build $build, array $options = [])
|
||||
public function __construct(Builder $builder, Build $build, array $options = [])
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
$this->build = $build;
|
||||
parent::__construct($builder, $build, $options);
|
||||
|
||||
$this->username = '';
|
||||
$this->password = '';
|
||||
|
|
@ -89,24 +83,6 @@ class XMPP implements Plugin
|
|||
$this->recipients = $options['recipients'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
|
||||
$this->phpci->logDebug('Plugin options: ' . json_encode($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options configuration for plugin
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
protected function setOptions($options)
|
||||
{
|
||||
foreach (['username', 'password', 'alias', 'tls', 'server', 'date_format'] as $key) {
|
||||
if (array_key_exists($key, $options)) {
|
||||
$this->{$key} = $options[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -135,8 +111,8 @@ class XMPP implements Plugin
|
|||
*/
|
||||
public function findConfigFile()
|
||||
{
|
||||
if (file_exists($this->phpci->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc')) {
|
||||
if (md5(file_get_contents($this->phpci->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc'))
|
||||
if (file_exists($this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc')) {
|
||||
if (md5(file_get_contents($this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc'))
|
||||
!== md5($this->getConfigFormat())) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -152,7 +128,7 @@ class XMPP implements Plugin
|
|||
*/
|
||||
public function execute()
|
||||
{
|
||||
$sendxmpp = $this->phpci->findBinary('sendxmpp');
|
||||
$sendxmpp = $this->builder->findBinary('sendxmpp');
|
||||
|
||||
/*
|
||||
* Without recipients we can't send notification
|
||||
|
|
@ -164,7 +140,7 @@ class XMPP implements Plugin
|
|||
/*
|
||||
* Try to build conf file
|
||||
*/
|
||||
$config_file = $this->phpci->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc';
|
||||
$config_file = $this->builder->buildPath . DIRECTORY_SEPARATOR . '.sendxmpprc';
|
||||
if (is_null($this->findConfigFile())) {
|
||||
file_put_contents($config_file, $this->getConfigFormat());
|
||||
chmod($config_file, 0600);
|
||||
|
|
@ -178,7 +154,7 @@ class XMPP implements Plugin
|
|||
$tls = ' -t';
|
||||
}
|
||||
|
||||
$message_file = $this->phpci->buildPath . DIRECTORY_SEPARATOR . uniqid('xmppmessage');
|
||||
$message_file = $this->builder->buildPath . DIRECTORY_SEPARATOR . uniqid('xmppmessage');
|
||||
if ($this->buildMessage($message_file) === false) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -189,14 +165,14 @@ class XMPP implements Plugin
|
|||
$cmd = $sendxmpp . "%s -f %s -m %s %s";
|
||||
$recipients = implode(' ', $this->recipients);
|
||||
|
||||
$success = $this->phpci->executeCommand($cmd, $tls, $config_file, $message_file, $recipients);
|
||||
$success = $this->builder->executeCommand($cmd, $tls, $config_file, $message_file, $recipients);
|
||||
|
||||
print $this->phpci->getLastOutput();
|
||||
print $this->builder->getLastOutput();
|
||||
|
||||
/*
|
||||
* Remove temp message file
|
||||
*/
|
||||
$this->phpci->executeCommand("rm -rf ".$message_file);
|
||||
$this->builder->executeCommand("rm -rf ".$message_file);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue