2013-05-18 00:19:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-18 00:19:38 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
2013-10-10 02:12:30 +02:00
|
|
|
|
2013-05-18 00:19:38 +02:00
|
|
|
/**
|
2013-05-20 15:06:53 +02:00
|
|
|
* Clean build removes Composer related files and allows PHPCI users to clean up their build directory.
|
|
|
|
* Useful as a precursor to copy_build.
|
2013-05-18 00:19:38 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class CleanBuild implements \PHPCI\Plugin
|
|
|
|
{
|
|
|
|
protected $remove;
|
|
|
|
protected $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
2013-05-18 00:19:38 +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:12:30 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-18 00:19:38 +02:00
|
|
|
{
|
|
|
|
$this->phpci = $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->build = $build;
|
2013-05-18 00:19:38 +02:00
|
|
|
$this->remove = isset($options['remove']) && is_array($options['remove']) ? $options['remove'] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes Composer and runs a specified command (e.g. install / update)
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$cmd = 'rm -Rf "%s"';
|
2014-05-09 09:57:22 +02:00
|
|
|
if (IS_WIN) {
|
|
|
|
$cmd = 'rmdir /S /Q "%s"';
|
|
|
|
}
|
2013-05-18 00:19:38 +02:00
|
|
|
$this->phpci->executeCommand($cmd, $this->phpci->buildPath . 'composer.phar');
|
|
|
|
$this->phpci->executeCommand($cmd, $this->phpci->buildPath . 'composer.lock');
|
|
|
|
|
|
|
|
$success = true;
|
|
|
|
|
|
|
|
foreach ($this->remove as $file) {
|
|
|
|
$ok = $this->phpci->executeCommand($cmd, $this->phpci->buildPath . $file);
|
|
|
|
|
|
|
|
if (!$ok) {
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|