2013-05-17 18:50:27 +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-17 18:50:27 +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-17 18:50:27 +02:00
|
|
|
/**
|
2013-05-20 15:06:53 +02:00
|
|
|
* Copy Build Plugin - Copies the entire build to another directory.
|
2013-05-17 18:50:27 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class CopyBuild implements \PHPCI\Plugin
|
|
|
|
{
|
|
|
|
protected $directory;
|
2014-04-12 13:50:10 +02:00
|
|
|
protected $ignore;
|
2014-04-12 13:48:26 +02:00
|
|
|
protected $wipe;
|
2013-05-17 18:50:27 +02:00
|
|
|
protected $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $build;
|
2013-05-17 18:50:27 +02:00
|
|
|
|
2013-10-10 02:12:30 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-17 18:50:27 +02:00
|
|
|
{
|
|
|
|
$path = $phpci->buildPath;
|
|
|
|
$this->phpci = $phpci;
|
2014-05-02 15:48:40 +02:00
|
|
|
$this->build = $build;
|
2013-05-17 18:50:27 +02:00
|
|
|
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
|
2014-04-12 13:48:26 +02:00
|
|
|
$this->wipe = isset($options['wipe']) ? (bool)$options['wipe'] : false;
|
2013-05-17 18:50:27 +02:00
|
|
|
$this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-12 02:44:27 +02:00
|
|
|
* Copies files from the root of the build directory into the target folder
|
2013-05-17 18:50:27 +02:00
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
$build = $this->phpci->buildPath;
|
|
|
|
|
|
|
|
if ($this->directory == $build) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-15 14:39:54 +02:00
|
|
|
$this->wipeExistingDirectory();
|
2014-04-12 13:48:26 +02:00
|
|
|
|
2014-04-12 13:52:26 +02:00
|
|
|
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
|
2014-05-09 09:57:22 +02:00
|
|
|
if (IS_WIN) {
|
|
|
|
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
|
|
|
|
}
|
2014-04-12 13:48:26 +02:00
|
|
|
|
2013-05-17 18:50:27 +02:00
|
|
|
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);
|
|
|
|
|
2014-05-15 14:39:54 +02:00
|
|
|
$this->deleteIgnoredFiles();
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function wipeExistingDirectory()
|
|
|
|
{
|
|
|
|
if ($this->wipe == true && $this->directory != '/' && is_dir($this->directory)) {
|
|
|
|
$cmd = 'rm -Rf "%s*"';
|
|
|
|
$success = $this->phpci->executeCommand($cmd, $this->directory);
|
|
|
|
if (!$success) {
|
|
|
|
throw new \Exception('Failed to wipe existing directory ' . $this->directory . ' before copy');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function deleteIgnoredFiles()
|
|
|
|
{
|
2013-05-17 18:50:27 +02:00
|
|
|
if ($this->ignore) {
|
|
|
|
foreach ($this->phpci->ignore as $file) {
|
|
|
|
$cmd = 'rm -Rf "%s/%s"';
|
2014-05-09 09:57:22 +02:00
|
|
|
if (IS_WIN) {
|
|
|
|
$cmd = 'rmdir /S /Q "%s\%s"';
|
|
|
|
}
|
2013-05-17 18:50:27 +02:00
|
|
|
$this->phpci->executeCommand($cmd, $this->directory, $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|