2013-05-17 16:10:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-12-09 17:12:54 +01:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
2014-05-12 18:26:17 +02:00
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
2013-12-09 17:12:54 +01:00
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
2014-05-12 18:26:17 +02:00
|
|
|
* @link https://www.phptesting.org/
|
2013-12-09 17:12:54 +01:00
|
|
|
*/
|
2013-05-17 16:10:48 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
2014-12-04 16:48:52 +01:00
|
|
|
use PHPCI\Helper\Lang;
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Model\Build;
|
|
|
|
|
2013-05-17 16:10:48 +02:00
|
|
|
/**
|
2013-12-09 17:12:54 +01:00
|
|
|
* Shell Plugin - Allows execute shell commands.
|
|
|
|
* @author Kinn Coelho Julião <kinncj@gmail.com>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
2013-05-17 16:10:48 +02:00
|
|
|
class Shell implements \PHPCI\Plugin
|
|
|
|
{
|
2014-05-02 15:48:40 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Builder
|
|
|
|
*/
|
2013-05-17 16:10:48 +02:00
|
|
|
protected $phpci;
|
|
|
|
|
2014-05-02 15:48:40 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Model\Build
|
|
|
|
*/
|
|
|
|
protected $build;
|
|
|
|
|
|
|
|
protected $args;
|
|
|
|
|
2013-05-17 16:10:48 +02:00
|
|
|
/**
|
2013-12-09 17:12:54 +01:00
|
|
|
* @var string[] $commands The commands to be executed
|
2013-05-17 16:10:48 +02:00
|
|
|
*/
|
2013-12-09 17:12:54 +01:00
|
|
|
protected $commands = array();
|
2013-05-17 16:10:48 +02:00
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-10-10 02:01:06 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-17 16:10:48 +02:00
|
|
|
{
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->phpci = $phpci;
|
|
|
|
$this->build = $build;
|
2013-05-17 16:10:48 +02:00
|
|
|
|
|
|
|
if (isset($options['command'])) {
|
2013-12-09 17:12:54 +01:00
|
|
|
// Keeping this for backwards compatibility, new projects should use interpolation vars.
|
|
|
|
$options['command'] = str_replace("%buildpath%", $this->phpci->buildPath, $options['command']);
|
|
|
|
$this->commands = array($options['command']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support the new syntax:
|
|
|
|
*
|
|
|
|
* shell:
|
|
|
|
* - "cd /www"
|
|
|
|
* - "rm -f file.txt"
|
|
|
|
*/
|
|
|
|
if (is_array($options)) {
|
|
|
|
$this->commands = $options;
|
2013-05-17 16:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-12-09 17:12:54 +01:00
|
|
|
* Runs the shell command.
|
|
|
|
*/
|
2013-05-17 16:10:48 +02:00
|
|
|
public function execute()
|
|
|
|
{
|
2013-05-22 18:23:35 +02:00
|
|
|
if (!defined('ENABLE_SHELL_PLUGIN') || !ENABLE_SHELL_PLUGIN) {
|
2014-12-04 16:48:52 +01:00
|
|
|
throw new \Exception(Lang::get('shell_not_enabled'));
|
2013-05-22 18:23:35 +02:00
|
|
|
}
|
2013-12-09 17:12:54 +01:00
|
|
|
|
|
|
|
$success = true;
|
|
|
|
|
|
|
|
foreach ($this->commands as $command) {
|
|
|
|
$command = $this->phpci->interpolate($command);
|
|
|
|
|
|
|
|
if (!$this->phpci->executeCommand($command)) {
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-17 16:10:48 +02:00
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|