Skip to content

Commit

Permalink
Merge branch 'release/1.6.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
andkirby committed Jan 19, 2015
2 parents 8069fc6 + 088a10d commit b530499
Show file tree
Hide file tree
Showing 41 changed files with 343 additions and 225 deletions.
1 change: 1 addition & 0 deletions .cache/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Do not remove this directory
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ atlassian-ide-plugin.xml
commithook-local.xml
commithook-self.xml
.cache/*
ca.pem
2 changes: 1 addition & 1 deletion LibHooks/config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config>
<version>1.6.3</version>
<version>1.6.4</version>
<supported_hooks>
<hook>pre-commit</hook>
<hook>commit-msg</hook>
Expand Down
2 changes: 1 addition & 1 deletion LibHooks/lib/PreCommit/Composer/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Application extends BaseApplication
*
* @see LibHooks/config.xml
*/
const VERSION = '1.6.3';
const VERSION = '1.6.4';

/**
* Logo
Expand Down
32 changes: 32 additions & 0 deletions LibHooks/lib/PreCommit/Composer/Command/CommandAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Composer\Command\Helper\DialogHelper;
use PreCommit\Composer\Exception;
use PreCommit\Config;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -22,6 +23,24 @@
*/
abstract class CommandAbstract extends Command
{
/**
* Base commithook directory
*
* @var null|string
*/
protected $commithookDir;

/**
* Construct
*
* @param string $commithookDir
*/
public function __construct($commithookDir)
{
$this->commithookDir = $commithookDir;
parent::__construct();
}

/**
* Configure command
*/
Expand Down Expand Up @@ -251,4 +270,17 @@ protected function isVerbose(OutputInterface $output)
{
return $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
}

/**
* Get config
*
* @param OutputInterface $output
* @param bool $cached
* @return Config
*/
public function getConfig(OutputInterface $output, $cached = true)
{
return Config::getInstance(array('file' => $this->commithookDir
. DIRECTORY_SEPARATOR . 'LibHooks' . DIRECTORY_SEPARATOR . 'config.xml'));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace PreCommit\Composer;
namespace PreCommit\Composer\Command;

use Composer\Command\Helper\DialogHelper;
use PreCommit\Composer\Command\CommandAbstract;
use PreCommit\Composer\Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -14,24 +14,6 @@
*/
class Install extends CommandAbstract
{
/**
* Base commithook directory
*
* @var null|string
*/
protected $commithookDir;

/**
* Construct
*
* @param string $commithookDir
*/
public function __construct($commithookDir)
{
$this->commithookDir = $commithookDir;
parent::__construct();
}

/**
* Init default helpers
*
Expand Down Expand Up @@ -236,7 +218,7 @@ protected function getHookBody($phpPath, $runnerPhpPath)
*/
protected function getRunnerFile()
{
return $this->commithookDir . '/LibHooks/runner.php';
return $this->commithookDir . '/bin/runner.php';
}

/**
Expand All @@ -246,13 +228,9 @@ protected function getRunnerFile()
*/
protected function getSystemPhpPath()
{
if (defined('PHP_BIN_DIR') && (is_file(PHP_BIN_DIR . '/php'))) {
if (defined('PHP_BIN_DIR') && is_file(PHP_BIN_DIR . '/php')) {
return PHP_BIN_DIR . '/php';
} elseif (defined('PHP_BIN_DIR')
&& (is_file(
PHP_BIN_DIR . '/php.exe'
))
) {
} elseif (defined('PHP_BIN_DIR') && is_file(PHP_BIN_DIR . '/php.exe')) {
return PHP_BIN_DIR . '/php.exe';
} elseif (defined('PHP_BINARY') && is_file(PHP_BINARY)) {
return PHP_BINARY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace PreCommit\Composer;
namespace PreCommit\Composer\Command;

use PreCommit\Composer\Command\CommandAbstract;
use PreCommit\Composer\Exception;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -34,7 +34,7 @@ protected function configureCommand()
*
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
* @return int
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output)
Expand Down
55 changes: 39 additions & 16 deletions LibHooks/lib/PreCommit/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
class Config extends \SimpleXMLElement
{
/**
* Root node XPATH
*/
const XPATH_START = '/config/';

/**
Expand Down Expand Up @@ -53,27 +56,29 @@ public static function loadInstance(array $options)
* Get config cache file
*
* @param string $rootPath
* @param string $hookFile
* @param string $projectDir
* @return string
*/
public static function getCacheFile($rootPath, $hookFile)
public static function getCacheFile($rootPath, $projectDir)
{
return $rootPath . DIRECTORY_SEPARATOR . Config::getInstance()->getNode('cache_dir')
return $rootPath . DIRECTORY_SEPARATOR
. Config::getInstance()->getNode('cache_dir')
. DIRECTORY_SEPARATOR
. md5(self::getInstance()->getNode('version') . pathinfo($hookFile, PATHINFO_DIRNAME)) . '.xml';
. md5(self::getInstance()->getNode('version') . $projectDir)
. '.xml';
}

/**
* Load cached config
*
* @param string $rootPath
* @param string $hookFile
* @param string $projectDir
* @return bool Returns FALSE in case it couldn't load cached config
*/
public static function loadCache($rootPath, $hookFile)
public static function loadCache($rootPath, $projectDir)
{
//load config from cache
$configCacheFile = self::getCacheFile($rootPath, $hookFile);
$configCacheFile = self::getCacheFile($rootPath, $projectDir);
if (is_file($configCacheFile)) {
$configCached = self::loadInstance(array('file' => $configCacheFile));
if (version_compare(
Expand All @@ -92,16 +97,11 @@ public static function loadCache($rootPath, $hookFile)
* Merge additional config files
*
* @param string $rootPath
* @param string $hookFile
* @param string $projectDir
* @return void
*/
public static function mergeExtraConfig($rootPath, $hookFile)
public static function mergeExtraConfig($rootPath, $projectDir)
{
/**
* Merge extra config files
*/
$projectDir = realpath(pathinfo($hookFile, PATHINFO_DIRNAME) . '/../..');

$merger = new XmlMerger();
$merger->addCollectionNode('validators/FileFilter/filter/skip/files/file');
$merger->addCollectionNode('validators/FileFilter/filter/skip/paths/path');
Expand All @@ -117,7 +117,7 @@ public static function mergeExtraConfig($rootPath, $hookFile)
continue;
}
try {
$xml = simplexml_load_file($file);
$xml = self::loadXmlFileToMerge($file);
$merger->merge(self::getInstance(), $xml);
} catch (\Exception $e) {
echo 'XML ERROR: Could not load additional config file ' . $file;
Expand All @@ -126,12 +126,35 @@ public static function mergeExtraConfig($rootPath, $hookFile)
}

//write cached config file
$cacheFile = self::getCacheFile($rootPath, $hookFile);
$cacheFile = self::getCacheFile($rootPath, $projectDir);
if (is_writeable(pathinfo($cacheFile, PATHINFO_DIRNAME))) {
self::getInstance()->asXML($cacheFile);
}
}

/**
* Load file to merge
*
* @param string $file
* @return \SimpleXMLElement
*/
protected static function loadXmlFileToMerge($file)
{
return simplexml_load_file($file);
}

/**
* Get project dir from hook file
*
* @todo It should be removed from Config
* @param string $hookFile
* @return string
*/
public static function getProjectDir($hookFile)
{
return $projectDir = realpath(pathinfo($hookFile, PATHINFO_DIRNAME) . '/../..');
}

/**
* Replace instance
*
Expand Down
4 changes: 2 additions & 2 deletions LibHooks/lib/PreCommit/XmlMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function addCollectionNode($xpath)
/**
* Merge two XML
*
* @param \SimpleXMLElement $xmlSource
* @param \SimpleXMLElement $xmlUpdate
* @param \SimpleXMLElement|string $xmlSource
* @param \SimpleXMLElement|string $xmlUpdate
* @return \SimpleXMLElement
*/
public function merge($xmlSource, $xmlUpdate)
Expand Down
12 changes: 10 additions & 2 deletions LibHooks/runner.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
/**
* End point file to run CommitHooks
*
* @deprecated Deprecated to direct using since v1.6.4.
* All code will be pushed to use /bin/runner.php
* @see /bin/runner.php
*/
$rootPath = __DIR__;
set_include_path(
implode(
Expand Down Expand Up @@ -49,8 +56,9 @@
exit(1);
}

if (!PreCommit\Config::loadCache($rootPath, $hookFile)) {
PreCommit\Config::mergeExtraConfig($rootPath, $hookFile);
$projectDir = PreCommit\Config::getProjectDir($hookFile);
if (!PreCommit\Config::loadCache($rootPath, $projectDir)) {
PreCommit\Config::mergeExtraConfig($rootPath, $projectDir);
}

/** @var \PreCommit\Processor\AbstractAdapter $processor */
Expand Down
16 changes: 6 additions & 10 deletions LibHooks/tests/framework/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php
@include_once 'func.php';
$includePaths = array(
get_include_path(),
'./testsuite',
'../lib',
);
define('PROJECT_ROOT', realpath(__DIR__ . '/../..'));
set_include_path(implode(PATH_SEPARATOR, $includePaths));
require_once 'Autoloader.php';
\Autoloader::register();
//set default PHPUnit error handler

/** @var Composer\Autoload\ClassLoader $autoloader */
$autoloader = require_once 'autoload.php';
$autoloader->addPsr4('PreCommit\\', array(realpath(PROJECT_ROOT . '/lib/PreCommit/')));
$autoloader->addPsr4('PreCommit\\Test\\', array(realpath(PROJECT_ROOT . '/tests/testsuite/PreCommit/Test/')));

set_error_handler('\PHPUnit_Util_ErrorHandler::handleError');
2 changes: 1 addition & 1 deletion LibHooks/tests/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./framework/bootstrap.php" clors="true">
<testsuite name="Php Hooks Unit Tests">
<file>testsuite/AllTests.php</file>
<directory>testsuite/</directory>
</testsuite>
<php>
<ini name="date.timezone" value="America/Los_Angeles"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace PreCommit\Test;

/**
* Class test for PreCommit_Processor
* Class test for Processor
*/
class PreCommit_ConfigTest extends PHPUnit_Framework_TestCase
class ConfigTest extends \PHPUnit_Framework_TestCase
{
/**
* Test model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?php
namespace PreCommit\Test\Processor;

use PreCommit\Config;

/**
* Class test for PreCommit_Processor
* Class test for Processor
*/
class PreCommit_Processor_PreCommitTest extends PHPUnit_Framework_TestCase
class PreCommitTest extends \PHPUnit_Framework_TestCase
{
/**
* Set up test model
*/
static public function setUpBeforeClass()
{
//init config
\PreCommit\Config::getInstance(array('file' => PROJECT_ROOT . '/config.xml'));
\PreCommit\Config::mergeExtraConfig(PROJECT_ROOT, 'd:/hook');
Config::getInstance(array('file' => PROJECT_ROOT . '/config.xml'));
Config::mergeExtraConfig(PROJECT_ROOT, 'd:/hook');
}

/**
Expand Down
Loading

0 comments on commit b530499

Please sign in to comment.