Big refactoring. Use of Namespaces and codestyles. PSR-0, PSR-1, PSR-2.

This commit is contained in:
Andrés Montañez
2013-11-06 12:44:05 -02:00
parent 8329b53f22
commit f961a51c37
57 changed files with 1801 additions and 978 deletions
@@ -8,30 +8,61 @@
* file that was distributed with this source code.
*/
class Mage_Task_BuiltIn_Scm_ChangeBranch
extends Mage_Task_TaskAbstract
{
protected static $startingBranch = 'master';
private $_name = 'SCM Changing branch [built-in]';
namespace Mage\Task\BuiltIn\Scm;
use Mage\Task\AbstractTask;
use Mage\Task\SkipException;
use Mage\Task\ErrorWithMessageException;
use Exception;
/**
* Task for Changing the Branch of the SCM
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class ChangeBranchTask extends AbstractTask
{
/**
* Branch the executiong began with
* @var string
*/
protected static $startingBranch = 'master';
/**
* Name of the Task
* @var string
*/
private $name = 'SCM Changing branch [built-in]';
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName()
{
return $this->_name;
return $this->name;
}
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::init()
*/
public function init()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$this->_name = 'SCM Changing branch (GIT) [built-in]';
break;
$scmType = $this->getConfig()->general('scm');
case 'svn':
$this->_name = 'SCM Changing branch (Subversion) [built-in]';
switch ($scmType) {
case 'git':
$this->name = 'SCM Changing branch (GIT) [built-in]';
break;
}
}
/**
* Changes the Branch of the SCM
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
$scmConfig = $this->getConfig()->general('scm', array());
@@ -39,41 +70,40 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
case 'git':
if ($this->getParameter('_changeBranchRevert', false)) {
$command = 'git checkout ' . self::$startingBranch;
$result = $this->_runLocalCommand($command);
$result = $this->runCommandLocal($command);
} else {
$command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
$currentBranch = 'master';
$result = $this->_runLocalCommand($command, $currentBranch);
$result = $this->runCommandLocal($command, $currentBranch);
$scmData = $this->getConfig()->deployment('scm', false);
if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
$command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
$isBranchTracked = '';
$result = $this->_runLocalCommand($command, $isBranchTracked);
$result = $this->runCommandLocal($command, $isBranchTracked);
if ($isBranchTracked == '') {
throw new Mage_Task_ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
throw new ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
}
$branch = $this->getParameter('branch', $scmData['branch']);
$command = 'git checkout ' . $branch;
$result = $this->_runLocalCommand($command);
$result = $this->runCommandLocal($command);
self::$startingBranch = $currentBranch;
} else {
throw new Mage_Task_SkipException;
throw new SkipException;
}
}
break;
default:
throw new Mage_Task_SkipException;
throw new SkipException;
break;
}
$this->getConfig()->reload();
return $result;
-61
View File
@@ -1,61 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Mage_Task_BuiltIn_Scm_Clone
extends Mage_Task_TaskAbstract
{
private $_name = 'SCM Clone [built-in]';
private $_source = null;
public function getName()
{
return $this->_name;
}
public function init()
{
$this->_source = $this->getConfig()->deployment('source');
switch ($this->_source['type']) {
case 'git':
$this->_name = 'SCM Clone (GIT) [built-in]';
break;
case 'svn':
$this->_name = 'SCM Clone (Subversion) [built-in]';
break;
}
}
public function run()
{
$this->_runLocalCommand('mkdir -p ' . $this->_source['temporal']);
switch ($this->_source['type']) {
case 'git':
// Clone Repo
$command = 'cd ' . $this->_source['temporal'] . ' ; '
. 'git clone ' . $this->_source['repository'] . ' . ';
$result = $this->_runLocalCommand($command);
// Checkout Branch
$command = 'cd ' . $this->_source['temporal'] . ' ; '
. 'git checkout ' . $this->_source['from'];
$result = $result && $this->_runLocalCommand($command);
$this->getConfig()->setFrom($this->_source['temporal']);
break;
case 'svn':
throw new Mage_Task_SkipException;
break;
}
return $result;
}
}
+89
View File
@@ -0,0 +1,89 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Scm;
use Mage\Task\AbstractTask;
use Mage\Task\SkipException;
use Exception;
/**
* Task for Clonning a Repository
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class CloneTask extends AbstractTask
{
/**
* Name of the Task
* @var string
*/
private $name = 'SCM Clone [built-in]';
/**
* Source of the Repo
* @var string
*/
private $source = null;
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName()
{
return $this->name;
}
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::init()
*/
public function init()
{
$this->source = $this->getConfig()->deployment('source');
switch ($this->source['type']) {
case 'git':
$this->name = 'SCM Clone (GIT) [built-in]';
break;
}
}
/**
* Clones a Repository
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
$this->runCommandLocal('mkdir -p ' . $this->source['temporal']);
switch ($this->source['type']) {
case 'git':
// Clone Repo
$command = 'cd ' . $this->source['temporal'] . ' ; '
. 'git clone ' . $this->source['repository'] . ' . ';
$result = $this->runCommandLocal($command);
// Checkout Branch
$command = 'cd ' . $this->source['temporal'] . ' ; '
. 'git checkout ' . $this->source['from'];
$result = $result && $this->runCommandLocal($command);
$this->getConfig()->setFrom($this->source['temporal']);
break;
default:
throw new SkipException;
break;
}
return $result;
}
}
-31
View File
@@ -1,31 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Mage_Task_BuiltIn_Scm_RemoveClone
extends Mage_Task_TaskAbstract
{
private $_name = 'SCM Remove Clone [built-in]';
private $_source = null;
public function getName()
{
return $this->_name;
}
public function init()
{
$this->_source = $this->getConfig()->deployment('source');
}
public function run()
{
return $this->_runLocalCommand('rm -rf ' . $this->_source['temporal']);
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Scm;
use Mage\Task\AbstractTask;
use Mage\Task\SkipException;
use Exception;
/**
* Task for Removing an used Cloned Repository
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class RemoveCloneTask extends AbstractTask
{
/**
* Name of the Task
* @var string
*/
private $name = 'SCM Remove Clone [built-in]';
/**
* Source of the Repo
* @var string
*/
private $source = null;
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName()
{
return $this->name;
}
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::init()
*/
public function init()
{
$this->source = $this->getConfig()->deployment('source');
switch ($this->source['type']) {
case 'git':
$this->name = 'SCM Remove Clone (GIT) [built-in]';
break;
}
}
public function run()
{
return $this->runCommandLocal('rm -rf ' . $this->source['temporal']);
}
}
-55
View File
@@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Mage_Task_BuiltIn_Scm_Update
extends Mage_Task_TaskAbstract
{
private $_name = 'SCM Update [built-in]';
public function getName()
{
return $this->_name;
}
public function init()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$this->_name = 'SCM Update (GIT) [built-in]';
break;
case 'svn':
$this->_name = 'SCM Update (Subversion) [built-in]';
break;
}
}
public function run()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$command = 'git pull';
break;
case 'svn':
$command = 'svn update';
break;
default:
throw new Mage_Task_SkipException;
break;
}
$result = $this->_runLocalCommand($command);
$this->getConfig()->reload();
return $result;
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Scm;
use Mage\Task\AbstractTask;
use Mage\Task\SkipException;
use Exception;
/**
* Task for Updating a Working Copy
*
* @author Andrés Montañez <andres@andresmontanez.com>
*/
class UpdateTask extends AbstractTask
{
/**
* Name of the Task
* @var string
*/
private $name = 'SCM Update [built-in]';
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::getName()
*/
public function getName()
{
return $this->name;
}
/**
* (non-PHPdoc)
* @see \Mage\Task\AbstractTask::init()
*/
public function init()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$this->name = 'SCM Update (GIT) [built-in]';
break;
}
}
/**
* Updates the Working Copy
* @see \Mage\Task\AbstractTask::run()
*/
public function run()
{
switch ($this->getConfig()->general('scm')) {
case 'git':
$command = 'git pull';
break;
default:
throw new SkipException;
break;
}
$result = $this->runCommandLocal($command);
$this->getConfig()->reload();
return $result;
}
}