Modifying the PHPCI CopyBuild plugin to add an extra option, which indicates whether the root folder of a build should be included when copying it to a destination. The original (and now default) behaviour was that the build folder would always be copied - it is now possible to copy only the build's contents by setting the include_build_dir flag to false.

This commit is contained in:
Greg J Preece 2015-11-11 18:44:58 -08:00
parent 4b8d25c0f7
commit c771b189b6

View file

@ -26,6 +26,7 @@ class CopyBuild implements \PHPCI\Plugin
protected $wipe;
protected $phpci;
protected $build;
protected $includeDir;
/**
* Set up the plugin, configure options, etc.
@ -35,12 +36,13 @@ class CopyBuild implements \PHPCI\Plugin
*/
public function __construct(Builder $phpci, Build $build, array $options = array())
{
$path = $phpci->buildPath;
$this->phpci = $phpci;
$this->build = $build;
$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;
$path = $phpci->buildPath;
$this->phpci = $phpci;
$this->build = $build;
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
$this->includeDir = isset($options['include_build_dir']) ? $options['include_build_dir'] : true;
$this->wipe = isset($options['wipe']) ? (bool)$options['wipe'] : false;
$this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false;
}
/**
@ -48,6 +50,7 @@ class CopyBuild implements \PHPCI\Plugin
*/
public function execute()
{
$build = $this->phpci->buildPath;
if ($this->directory == $build) {
@ -56,9 +59,20 @@ class CopyBuild implements \PHPCI\Plugin
$this->wipeExistingDirectory();
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
$suffix = '';
if ($this->includeDir == false) {
if (substr($build, -1) != DIRECTORY_SEPARATOR) {
$build .= DIRECTORY_SEPARATOR;
}
$suffix = "*";
}
$cmd = 'mkdir -p "%s" && cp -R "%s"' . $suffix . ' "%s"';
if (IS_WIN) {
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
$cmd = 'mkdir -p "%s" && xcopy /E "%s"' . $suffix . ' "%s"';
}
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);