From: Gunnar Wrobel Date: Mon, 6 Sep 2010 03:38:50 +0000 (+0200) Subject: Renamed Element to Components within the package. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fdb1af93f3735d7be1f437a7566ff6b17c8cc122;p=horde.git Renamed Element to Components within the package. --- diff --git a/components/data/hudson-component-build.xml.template b/components/data/hudson-component-build.xml.template new file mode 100644 index 000000000..6e711f235 --- /dev/null +++ b/components/data/hudson-component-build.xml.template @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/data/hudson-component-config.xml.template b/components/data/hudson-component-config.xml.template new file mode 100644 index 000000000..5ab789d2a --- /dev/null +++ b/components/data/hudson-component-config.xml.template @@ -0,0 +1,264 @@ + + + + %4$s + + 5 + 10 + -1 + -1 + + false + + + true + false + false + + false + + + cp -r ${WORKSPACE}/../../%2$s/workspace/%1$s/* ${WORKSPACE}/ +echo "include_path = \".:${WORKSPACE}/../../%3$s/php\"" > ${WORKSPACE}/php.ini +rm -rf ${WORKSPACE}/deps +mkdir ${WORKSPACE}/deps +php -c php.ini ${WORKSPACE}/../../%3$s/horde-element --install=${WORKSPACE}/deps ${WORKSPACE}/../../%2$s/workspace/%1$s +php -c php.ini ${WORKSPACE}/../../%3$s/horde-element --ciprebuild=${WORKSPACE} ${WORKSPACE}/../../%2$s/workspace/%1$s +echo "include_path = \".:${WORKSPACE}/lib:${WORKSPACE}/deps/pear/php:${WORKSPACE}/../../%3$s/php\"" > ${WORKSPACE}/php.ini + + + + + + + + + + + + + + + [PMD] + low + + false + false + build/logs/pmd.xml + + + + + + + + + [CHECKSTYLE] + low + + false + false + build/logs/checkstyle.xml + + + + + + + + + [DRY] + low + + false + false + build/logs/pmd-cpd.xml + 50 + 25 + + + build/logs/jdepend.xml + + + build/logs + clover.xml + + 70 + 80 + 80 + + + + + + + + + + + + + checkstyle + + checkstyle + 10 + 999 + 999 + false + build/logs/checkstyle.xml + + + + cpd + + cpd + 10 + 999 + 999 + false + build/logs/pmd-cpd.xml + + + + findbugs + + findbugs + 10 + 999 + 999 + false + + + + + fxcop + + fxcop + 10 + 999 + 999 + false + + + + + gendarme + + gendarme + 10 + 999 + 999 + false + + + + + jcreport + + jcreport + 10 + 999 + 999 + false + + + + + jslint + + jslint + 10 + 999 + 999 + false + + + + + pmd + + pmd + 10 + 999 + 999 + false + build/logs/pmd.xml + + + + pylint + + pylint + 10 + 999 + 999 + false + + + + + simian + + simian + 10 + 999 + 999 + false + + + + + stylecop + + stylecop + 10 + 999 + 999 + false + + + + + 100 + + + default + + + + + + API Documentation + build/api + index.html + false + htmlpublisher-wrapper.html + + + Code Browser + build/code-browser + index.html + false + htmlpublisher-wrapper.html + + + Code Coverage + build/coverage + index.html + false + htmlpublisher-wrapper.html + + + + + + + build/logs/junit.xml + true + true + + + + + + diff --git a/components/data/hudson-component-phpunit.xml.template b/components/data/hudson-component-phpunit.xml.template new file mode 100644 index 000000000..5a7fa0655 --- /dev/null +++ b/components/data/hudson-component-phpunit.xml.template @@ -0,0 +1,25 @@ + + + + + + test/Horde/%2$s + + + + + + + + + + + + lib + + + diff --git a/components/data/hudson-element-build.xml.template b/components/data/hudson-element-build.xml.template deleted file mode 100644 index 6e711f235..000000000 --- a/components/data/hudson-element-build.xml.template +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/data/hudson-element-config.xml.template b/components/data/hudson-element-config.xml.template deleted file mode 100644 index 5ab789d2a..000000000 --- a/components/data/hudson-element-config.xml.template +++ /dev/null @@ -1,264 +0,0 @@ - - - - %4$s - - 5 - 10 - -1 - -1 - - false - - - true - false - false - - false - - - cp -r ${WORKSPACE}/../../%2$s/workspace/%1$s/* ${WORKSPACE}/ -echo "include_path = \".:${WORKSPACE}/../../%3$s/php\"" > ${WORKSPACE}/php.ini -rm -rf ${WORKSPACE}/deps -mkdir ${WORKSPACE}/deps -php -c php.ini ${WORKSPACE}/../../%3$s/horde-element --install=${WORKSPACE}/deps ${WORKSPACE}/../../%2$s/workspace/%1$s -php -c php.ini ${WORKSPACE}/../../%3$s/horde-element --ciprebuild=${WORKSPACE} ${WORKSPACE}/../../%2$s/workspace/%1$s -echo "include_path = \".:${WORKSPACE}/lib:${WORKSPACE}/deps/pear/php:${WORKSPACE}/../../%3$s/php\"" > ${WORKSPACE}/php.ini - - - - - - - - - - - - - - - [PMD] - low - - false - false - build/logs/pmd.xml - - - - - - - - - [CHECKSTYLE] - low - - false - false - build/logs/checkstyle.xml - - - - - - - - - [DRY] - low - - false - false - build/logs/pmd-cpd.xml - 50 - 25 - - - build/logs/jdepend.xml - - - build/logs - clover.xml - - 70 - 80 - 80 - - - - - - - - - - - - - checkstyle - - checkstyle - 10 - 999 - 999 - false - build/logs/checkstyle.xml - - - - cpd - - cpd - 10 - 999 - 999 - false - build/logs/pmd-cpd.xml - - - - findbugs - - findbugs - 10 - 999 - 999 - false - - - - - fxcop - - fxcop - 10 - 999 - 999 - false - - - - - gendarme - - gendarme - 10 - 999 - 999 - false - - - - - jcreport - - jcreport - 10 - 999 - 999 - false - - - - - jslint - - jslint - 10 - 999 - 999 - false - - - - - pmd - - pmd - 10 - 999 - 999 - false - build/logs/pmd.xml - - - - pylint - - pylint - 10 - 999 - 999 - false - - - - - simian - - simian - 10 - 999 - 999 - false - - - - - stylecop - - stylecop - 10 - 999 - 999 - false - - - - - 100 - - - default - - - - - - API Documentation - build/api - index.html - false - htmlpublisher-wrapper.html - - - Code Browser - build/code-browser - index.html - false - htmlpublisher-wrapper.html - - - Code Coverage - build/coverage - index.html - false - htmlpublisher-wrapper.html - - - - - - - build/logs/junit.xml - true - true - - - - - - diff --git a/components/data/hudson-element-phpunit.xml.template b/components/data/hudson-element-phpunit.xml.template deleted file mode 100644 index 5a7fa0655..000000000 --- a/components/data/hudson-element-phpunit.xml.template +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - test/Horde/%2$s - - - - - - - - - - - - lib - - - diff --git a/components/lib/Components.php b/components/lib/Components.php new file mode 100644 index 000000000..70816d7d1 --- /dev/null +++ b/components/lib/Components.php @@ -0,0 +1,106 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * The Horde_Element:: class is the entry point for the various Horde + * element actions provided by the package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element +{ + /** + * The main entry point for the application. + * + * @param array $parameters A list of named configuration parameters. + *
+     * 'cli'        - (array)  CLI configuration parameters.
+     *   'parser'   - (array)  Parser configuration parameters.
+     *     'class'  - (string) The class name of the parser to use.
+     * 
+ */ + static public function main(array $parameters = array()) + { + $parser = self::_prepareParser($parameters); + $config = self::_prepareConfig($parser); + $modules = self::_prepareModules(); + $config->handleModules($modules); + try { + self::_validateArguments($config); + } catch (Horde_Element_Exception $e) { + $parser->parserError($e->getMessage()); + return; + } + foreach ($modules as $module) { + $module->handle($config); + } + } + + static private function _prepareParser(array $parameters = array()) + { + if (empty($parameters['cli']['parser']['class'])) { + $parser_class = 'Horde_Argv_Parser'; + } else { + $parser_class = $parameters['cli']['parser']['class']; + } + return new $parser_class( + array( + 'usage' => '%prog ' . _("[options] PACKAGE_PATH") + ) + ); + } + + static private function _prepareConfig(Horde_Argv_Parser $parser) + { + $config = new Horde_Element_Configs(); + $config->addConfigurationType( + new Horde_Element_Config_Cli( + $parser + ) + ); + return $config; + } + + static private function _prepareModules() + { + $modules = new Horde_Element_Modules(); + $modules->addModulesFromDirectory(dirname(__FILE__) . '/Element/Module'); + return $modules; + } + + static private function _validateArguments(Horde_Element_Config $config) + { + $arguments = $config->getArguments(); + if (empty($arguments[0])) { + throw new Horde_Element_Exception('Please specify the path of the PEAR package!'); + } + + if (!is_dir($arguments[0])) { + throw new Horde_Element_Exception(sprintf('%s specifies no directory!', $arguments[0])); + } + + if (!file_exists($arguments[0] . '/package.xml')) { + throw new Horde_Element_Exception(sprintf('There is no package.xml at %s!', $arguments[0])); + } + } +} \ No newline at end of file diff --git a/components/lib/Components/Config.php b/components/lib/Components/Config.php new file mode 100644 index 000000000..da22e4680 --- /dev/null +++ b/components/lib/Components/Config.php @@ -0,0 +1,53 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Config:: interface represents a configuration type for the Horde + * element tool. + * + * Copyright 2009-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +interface Horde_Element_Config +{ + /** + * Provide each configuration handler with the list of supported modules. + * + * @param Horde_Element_Modules $modules A list of modules. + * @return NULL + */ + public function handleModules(Horde_Element_Modules $modules); + + /** + * Return the options provided by the configuration handlers. + * + * @return array An array of options. + */ + public function getOptions(); + + /** + * Return the arguments provided by the configuration handlers. + * + * @return array An array of arguments. + */ + public function getArguments(); +} \ No newline at end of file diff --git a/components/lib/Components/Config/Cli.php b/components/lib/Components/Config/Cli.php new file mode 100644 index 000000000..6f63f94a4 --- /dev/null +++ b/components/lib/Components/Config/Cli.php @@ -0,0 +1,119 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Config_Cli:: class provides the command line interface for the Horde + * element tool. + * + * Copyright 2009-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Config_Cli +implements Horde_Element_Config +{ + /** + * The command line argument parser. + * + * @var Horde_Argv_Parser + */ + private $_parser; + + /** + * The options parsed from the command line. + * + * @var array + */ + private $_options; + + /** + * Any additional arguments parsed from the command line. + * + * @var array + */ + private $_arguments; + + /** + * Constructor. + * + */ + public function __construct( + Horde_Argv_Parser $parser + ) { + $this->_parser = $parser; + } + + /** + * Load the options for the list of supported modules. + * + * @param Horde_Element_Modules $modules A list of modules. + * @return NULL + */ + public function handleModules(Horde_Element_Modules $modules) + { + foreach ($modules as $module) { + $this->_addOptionsFromModule($this->_parser, $module); + } + + list($this->_options, $this->_arguments) = $this->_parser->parseArgs(); + } + + /** + * Return the options parsed from the command line. + * + * @return Horde_Argv_Values The option values. + */ + public function getOptions() + { + return $this->_options; + } + + /** + * Return the arguments parsed from the command line. + * + * @return array An array of arguments. + */ + public function getArguments() + { + return $this->_arguments; + } + + /** + * Add an option group from the provided module to the parser. + * + * @param Horde_Argv_Parser $parser The parser. + * @param Horde_Element_Module $module The module providing the option group. + * + * @return NULL + */ + private function _addOptionsFromModule($parser, $module) + { + $group = new Horde_Argv_OptionGroup( + $parser, + $module->getOptionGroupTitle(), + $module->getOptionGroupDescription() + ); + foreach ($module->getOptionGroupOptions() as $option) { + $group->addOption($option); + } + $parser->addOptionGroup($group); + } +} diff --git a/components/lib/Components/Configs.php b/components/lib/Components/Configs.php new file mode 100644 index 000000000..ee5a07203 --- /dev/null +++ b/components/lib/Components/Configs.php @@ -0,0 +1,108 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Configs:: class represents configuration for the + * Horde element tool. + * + * Copyright 2009-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Configs +implements Horde_Element_Config +{ + + /** + * The different configuration handlers. + * + * @var array + */ + private $_configs; + + /** + * Constructor. + */ + public function __construct() { + $this->_configs = array(); + } + + /** + * Add a configuration type to the configuration handler. + * + * @param Horde_Element_Config $type The configuration type. + * + * @return NULL + */ + public function addConfigurationType(Horde_Element_Config $type) { + $this->_configs[] = $type; + } + + /** + * Provide each configuration handler with the list of supported modules. + * + * @param Horde_Element_Modules $modules A list of modules. + * @return NULL + */ + public function handleModules(Horde_Element_Modules $modules) + { + foreach ($this->_configs as $config) { + $config->handleModules($modules); + } + } + + /** + * Return the options provided by the configuration handlers. + * + * @return array An array of options. + */ + public function getOptions() + { + $options = array(); + foreach ($this->_configs as $config) { + if (count($config->getOptions()) !== 0) { + $config_options = array(); + foreach ($config->getOptions() as $name => $option) { + $config_options[$name] = $option; + } + $options = array_merge($options, $config_options); + } + } + return $options; + } + + /** + * Return the arguments provided by the configuration handlers. + * + * @return array An array of arguments. + */ + public function getArguments() + { + $arguments = array(); + foreach ($this->_configs as $config) { + $config_arguments = $config->getArguments(); + if (!empty($config_arguments)) { + $arguments = array_merge($arguments, $config_arguments); + } + } + return $arguments; + } +} \ No newline at end of file diff --git a/components/lib/Components/Constants.php b/components/lib/Components/Constants.php new file mode 100644 index 000000000..42f8e9fa5 --- /dev/null +++ b/components/lib/Components/Constants.php @@ -0,0 +1,42 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Constants:: provides the constants for this package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Constants +{ + const DATA_DIR = '@data_dir@'; + + static public function getDataDirectory() + { + if (strpos(self::DATA_DIR, '@data_dir') === 0) { + return join( + DIRECTORY_SEPARATOR, + array(dirname(__FILE__), '..', '..', '..', 'data') + ); + } + return self::DATA_DIR . DIRECTORY_SEPARATOR . 'Element'; + } +} diff --git a/components/lib/Components/Exception.php b/components/lib/Components/Exception.php new file mode 100644 index 000000000..115b70a88 --- /dev/null +++ b/components/lib/Components/Exception.php @@ -0,0 +1,31 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * This class provides the standard error class for the Element package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Exception +extends Exception +{ +} diff --git a/components/lib/Components/Module.php b/components/lib/Components/Module.php new file mode 100644 index 000000000..43a98627d --- /dev/null +++ b/components/lib/Components/Module.php @@ -0,0 +1,39 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Module:: represents a task for a Horde element. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +interface Horde_Element_Module +{ + public function getOptionGroupTitle(); + + public function getOptionGroupDescription(); + + public function getOptionGroupOptions(); + + public function handle(Horde_Element_Config $config); + + public function run(Horde_Element_Config $config); +} \ No newline at end of file diff --git a/components/lib/Components/Module/CiSetup.php b/components/lib/Components/Module/CiSetup.php new file mode 100644 index 000000000..786046675 --- /dev/null +++ b/components/lib/Components/Module/CiSetup.php @@ -0,0 +1,139 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Module_CiSetup:: generates the configuration for Hudson based + * continuous integration of a Horde PEAR package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Module_CiSetup +implements Horde_Element_Module +{ + public function getOptionGroupTitle() + { + return 'Continuous Integration Setup'; + } + + public function getOptionGroupDescription() + { + return 'This module generates the configuration for Hudson based continuous integration of a Horde PEAR package.'; + } + + public function getOptionGroupOptions() + { + return array( + new Horde_Argv_Option( + '-c', + '--cisetup', + array( + 'action' => 'store', + 'help' => 'generate the basic Hudson project configuration for a Horde PEAR package in CISETUP' + ) + ), + new Horde_Argv_Option( + '-C', + '--ciprebuild', + array( + 'action' => 'store', + 'help' => 'generate the Hudson build configuration for a Horde PEAR package in CIPREBUILD' + ) + ), + new Horde_Argv_Option( + '-T', + '--toolsdir', + array( + 'action' => 'store', + 'help' => 'the path to the PEAR installation holding the required analysis tools' + ) + ), + ); + } + + public function handle(Horde_Element_Config $config) + { + $options = $config->getOptions(); + if (!empty($options['cisetup']) | !empty($options['ciprebuild'])) { + $this->run($config); + } + } + + public function run(Horde_Element_Config $config) + { + $options = $config->getOptions(); + + $pear = new PEAR(); + $pear->setErrorHandling(PEAR_ERROR_DIE); + + $arguments = $config->getArguments(); + $pkgfile = $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'; + $name = basename($arguments[0]); + if (basename(dirname($arguments[0])) == 'framework') { + $origin = 'framework' . DIRECTORY_SEPARATOR . $name; + } else { + $origin = $name; + } + $test_path = strtr($name, '_', '/'); + + $pkg = new PEAR_PackageFile(new PEAR_Config()); + $pf = $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); + $description = $pf->getDescription(); + + if (!isset($options['toolsdir'])) { + $options['toolsdir'] = 'php-hudson-tools/workspace/pear/pear'; + } + + if (!empty($options['cisetup'])) { + $in = file_get_contents( + Horde_Element_Constants::getDataDirectory() + . DIRECTORY_SEPARATOR . 'hudson-element-config.xml.template', + 'r' + ); + file_put_contents( + $options['cisetup'] . DIRECTORY_SEPARATOR . 'config.xml', + sprintf($in, $origin, 'horde', $options['toolsdir'], $description) + ); + } + + if (!empty($options['ciprebuild'])) { + $in = file_get_contents( + Horde_Element_Constants::getDataDirectory() + . DIRECTORY_SEPARATOR . 'hudson-element-build.xml.template', + 'r' + ); + file_put_contents( + $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'build.xml', + sprintf($in, $options['toolsdir']) + ); + $in = file_get_contents( + Horde_Element_Constants::getDataDirectory() + . DIRECTORY_SEPARATOR . 'hudson-element-phpunit.xml.template', + 'r' + ); + file_put_contents( + $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'phpunit.xml', + sprintf($in, $name, $test_path) + ); + } + } +} diff --git a/components/lib/Components/Module/DevPackage.php b/components/lib/Components/Module/DevPackage.php new file mode 100644 index 000000000..259d5ea67 --- /dev/null +++ b/components/lib/Components/Module/DevPackage.php @@ -0,0 +1,82 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Module_DevPackage:: generates a development snapshot for the + * specified package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Module_DevPackage +implements Horde_Element_Module +{ + public function getOptionGroupTitle() + { + return 'Development Packages'; + } + + public function getOptionGroupDescription() + { + return 'This module generates a development snapshot for the specified package'; + } + + public function getOptionGroupOptions() + { + return array( + new Horde_Argv_Option( + '-d', + '--devpackage', + array( + 'action' => 'store_true', + 'help' => 'generate a development snapshot' + ) + ), + ); + } + + public function handle(Horde_Element_Config $config) + { + $options = $config->getOptions(); + if (!empty($options['devpackage'])) { + $this->run($config); + } + } + + public function run(Horde_Element_Config $config) + { + $options = $config->getOptions(); + + $pear = new PEAR(); + $pear->setErrorHandling(PEAR_ERROR_DIE); + + $arguments = $config->getArguments(); + $pkgfile = $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'; + + $pkg = new PEAR_PackageFile(new PEAR_Config()); + $pf = $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); + $pf->_packageInfo['version']['release'] = $pf->getVersion() + . 'dev' . strftime('%Y%m%d%H%M'); + $gen = $pf->getDefaultGenerator(); + $tgzfile = $gen->toTgz(new PEAR_Common()); + } +} diff --git a/components/lib/Components/Module/Installer.php b/components/lib/Components/Module/Installer.php new file mode 100644 index 000000000..2a425bcdd --- /dev/null +++ b/components/lib/Components/Module/Installer.php @@ -0,0 +1,172 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Module_Installer:: installs a Horde element including + * its dependencies. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Module_Installer +implements Horde_Element_Module +{ + private $_run; + + public function getOptionGroupTitle() + { + return 'Installer'; + } + + public function getOptionGroupDescription() + { + return 'This module installs a Horde element including its dependencies.'; + } + + public function getOptionGroupOptions() + { + return array( + new Horde_Argv_Option( + '-i', + '--install', + array( + 'action' => 'store', + 'help' => 'install the element into the specified absolute INSTALL location' + ) + ), + ); + } + + public function handle(Horde_Element_Config $config) + { + $options = $config->getOptions(); + if (!empty($options['install'])) { + $this->run($config); + } + } + + public function run(Horde_Element_Config $config) + { + $options = $config->getOptions(); + + $pear = new PEAR(); + $pear->setErrorHandling(PEAR_ERROR_DIE); + + $pearrc = $options['install'] . DIRECTORY_SEPARATOR . '.pearrc'; + $command_config = new PEAR_Command_Config(new PEAR_Frontend_CLI(), new stdClass); + $command_config->doConfigCreate( + 'config-create', array(), array($options['install'], $pearrc) + ); + + $pear_config = new PEAR_Config($pearrc); + $GLOBALS['_PEAR_Config_instance'] = $pear_config; + + $channel = new PEAR_Command_Channels( + new PEAR_Frontend_CLI(), + $pear_config + ); + $channel->doDiscover('channel-discover', array(), array('pear.horde.org')); + $channel->doDiscover('channel-discover', array(), array('pear.phpunit.de')); + + $installer = new PEAR_Command_Install( + new PEAR_Frontend_CLI(), + $pear_config + ); + + $arguments = $config->getArguments(); + $element = basename(realpath($arguments[0])); + $root_path = dirname(realpath($arguments[0])); + + $this->_run = array(); + + $this->_installHordeDependency( + $installer, + $pear_config, + $root_path, + $element + ); + } + + /** + * Install a Horde dependency from the current tree (the framework). + * + * @param PEAR_Command_Install $installer Installs the dependency. + * @param PEAR_Config $pear_config The configuration of the PEAR + * environment in which the + * dependency will be installed. + * @param string $root_path Root path to the Horde framework. + * @param string $dependency Package name of the dependency. + */ + private function _installHordeDependency( + PEAR_Command_Install $installer, + PEAR_Config $pear_config, + $root_path, + $dependency + ) { + $package_file = $root_path . DIRECTORY_SEPARATOR + . $dependency . DIRECTORY_SEPARATOR . 'package.xml'; + + $parser = new PEAR_PackageFile_Parser_v2(); + $parser->setConfig($pear_config); + $pkg = $parser->parse(file_get_contents($package_file), $package_file); + + $dependencies = $pkg->getDeps(); + foreach ($dependencies as $dependency) { + if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') { + $key = $dependency['channel'] . '/' . $dependency['name']; + if (in_array($key, $this->_run)) { + continue; + } + $installer->doInstall( + 'install', + array( + 'force' => true, + 'channel' => $dependency['channel'], + ), + array($dependency['name']) + ); + $this->_run[] = $key; + } else if (isset($dependency['channel'])) { + $key = $dependency['channel'] . '/' . $dependency['name']; + if (in_array($key, $this->_run)) { + continue; + } + $this->_run[] = $key; + $this->_installHordeDependency( + $installer, + $pear_config, + $root_path, + $dependency['name'] + ); + } + } + if (in_array($package_file, $this->_run)) { + return; + } + $installer->doInstall( + 'install', + array('nodeps' => true), + array($package_file) + ); + $this->_run[] = $package_file; + } +} diff --git a/components/lib/Components/Module/PearPackageXml.php b/components/lib/Components/Module/PearPackageXml.php new file mode 100644 index 000000000..44395276a --- /dev/null +++ b/components/lib/Components/Module/PearPackageXml.php @@ -0,0 +1,163 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Horde_Element_Module_PearPackageXml:: can update the package.xml of + * a Horde element. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Module_PearPackageXml +implements Horde_Element_Module +{ + public function getOptionGroupTitle() + { + return 'Pear Package Xml'; + } + + public function getOptionGroupDescription() + { + return 'This module allows manipulation of the package.xml.'; + } + + public function getOptionGroupOptions() + { + return array( + new Horde_Argv_Option( + '-u', + '--updatexml', + array( + 'action' => 'store_true', + 'help' => 'update the package.xml for the package' + ) + ), + new Horde_Argv_Option( + '-p', + '--packagexml', + array( + 'action' => 'store_true', + 'help' => 'display an up-to-date package.xml for the package' + ) + ) + + ); + } + + public function handle(Horde_Element_Config $config) + { + $options = $config->getOptions(); + if (!empty($options['packagexml']) || + !empty($options['updatexml'])) { + $this->run($config); + } + } + + public function run(Horde_Element_Config $config) + { + $arguments = $config->getArguments(); + $package_file = $arguments[0] . '/package.xml'; + + $pear = new PEAR(); + $pear->setErrorHandling(PEAR_ERROR_DIE); + + $package = PEAR_PackageFileManager2::importOptions( + $package_file, + array( + 'packagedirectory' => $arguments[0], + 'filelistgenerator' => 'file', + 'clearcontents' => false, + 'clearchangelog' => false, + 'simpleoutput' => true, + 'ignore' => array('*~', 'conf.php', 'CVS/*'), + 'include' => '*', + 'dir_roles' => + array( + 'lib' => 'php', + 'doc' => 'doc', + 'example' => 'doc', + 'script' => 'script', + 'test' => 'test', + 'migration' => 'data', + ), + ) + ); + + if ($package instanceOf PEAR_Error) { + throw new Horde_Element_Exception($package->getMessage()); + } + /** + * @todo: Looks like this throws away any tags we have in + * the content list. Needs to be fixed. + */ + $package->generateContents(); + + /** + * This is required to clear the + * section. + */ + $package->setPackageType('php'); + + $contents = $package->getContents(); + $files = $contents['dir']['file']; + + foreach ($files as $file) { + $components = explode('/', $file['attribs']['name'], 2); + switch ($components[0]) { + case 'doc': + case 'example': + case 'lib': + case 'test': + case 'data': + $package->addInstallAs( + $file['attribs']['name'], $components[1] + ); + break; + case 'migration': + $components = explode('/', $components[1]); + array_splice($components, count($components) - 1, 0, 'migration'); + $package->addInstallAs( + $file['attribs']['name'], implode('/', $components) + ); + break; + case 'script': + $filename = basename($file['attribs']['name']); + if (substr($filename, strlen($filename) - 4)) { + $filename = substr($filename, 0, strlen($filename) - 4); + } + $package->addInstallAs( + $file['attribs']['name'], $filename + ); + break; + } + } + + $options = $config->getOptions(); + if (!empty($options['packagexml'])) { + $package->debugPackageFile(); + } + if (!empty($options['updatexml'])) { + $package->writePackageFile(); + } + + } +} diff --git a/components/lib/Components/Modules.php b/components/lib/Components/Modules.php new file mode 100644 index 000000000..9c188f4bb --- /dev/null +++ b/components/lib/Components/Modules.php @@ -0,0 +1,125 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * The Horde_Element_Modules:: class handles a set of Element modules. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Modules +implements Iterator, Countable +{ + /** + * The available modules. + * + * @var array + */ + private $_modules; + + /** + * Constructor. + */ + public function __construct() + { + $this->_modules = array(); + } + + /** + * Add all modules found in the specified directory. + * + * @param string $module_directory Load the modules from this dirrectory. + * + * @return NULL + */ + public function addModulesFromDirectory( + $module_directory, + $base = 'Horde_Element_Module_' + ) { + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($module_directory)) as $file) { + if ($file->isFile() && preg_match('/.php$/', $file->getFilename())) { + $class = $base . preg_replace("/^(.*)\.php/", '\\1', $file->getFilename()); + $this->_modules[$class] = new $class(); + } + } + } + + /** + * Implementation of the Iterator rewind() method. Rewinds the module list. + * + * return NULL + */ + public function rewind() + { + reset($this->_modules); + } + + /** + * Implementation of the Iterator current(). Returns the current module. + * + * @return mixed The current module. + */ + public function current() + { + return current($this->_modules); + } + + /** + * Implementation of the Iterator key() method. Returns the key of the current module. + * + * @return mixed The class name of the current module. + */ + public function key() + { + return key($this->_modules); + } + + /** + * Implementation of the Iterator next() method. Returns the next module. + * + * @return Horde_Element_Module|null The next module or null if there are no more + * modules. + */ + public function next() + { + return next($this->_modules); + } + + /** + * Implementation of the Iterator valid() method. Indicates if the current element is a valid element. + * + * @return boolean Whether the current element is valid + */ + public function valid() + { + return key($this->_modules) !== null; + } + + /** + * Implementation of Countable count() method. Returns the number of modules. + * + * @return integer Number of modules. + */ + public function count() + { + return count($this->_modules); + } +} \ No newline at end of file diff --git a/components/lib/Horde/Element.php b/components/lib/Horde/Element.php deleted file mode 100644 index 70816d7d1..000000000 --- a/components/lib/Horde/Element.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * The Horde_Element:: class is the entry point for the various Horde - * element actions provided by the package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element -{ - /** - * The main entry point for the application. - * - * @param array $parameters A list of named configuration parameters. - *
-     * 'cli'        - (array)  CLI configuration parameters.
-     *   'parser'   - (array)  Parser configuration parameters.
-     *     'class'  - (string) The class name of the parser to use.
-     * 
- */ - static public function main(array $parameters = array()) - { - $parser = self::_prepareParser($parameters); - $config = self::_prepareConfig($parser); - $modules = self::_prepareModules(); - $config->handleModules($modules); - try { - self::_validateArguments($config); - } catch (Horde_Element_Exception $e) { - $parser->parserError($e->getMessage()); - return; - } - foreach ($modules as $module) { - $module->handle($config); - } - } - - static private function _prepareParser(array $parameters = array()) - { - if (empty($parameters['cli']['parser']['class'])) { - $parser_class = 'Horde_Argv_Parser'; - } else { - $parser_class = $parameters['cli']['parser']['class']; - } - return new $parser_class( - array( - 'usage' => '%prog ' . _("[options] PACKAGE_PATH") - ) - ); - } - - static private function _prepareConfig(Horde_Argv_Parser $parser) - { - $config = new Horde_Element_Configs(); - $config->addConfigurationType( - new Horde_Element_Config_Cli( - $parser - ) - ); - return $config; - } - - static private function _prepareModules() - { - $modules = new Horde_Element_Modules(); - $modules->addModulesFromDirectory(dirname(__FILE__) . '/Element/Module'); - return $modules; - } - - static private function _validateArguments(Horde_Element_Config $config) - { - $arguments = $config->getArguments(); - if (empty($arguments[0])) { - throw new Horde_Element_Exception('Please specify the path of the PEAR package!'); - } - - if (!is_dir($arguments[0])) { - throw new Horde_Element_Exception(sprintf('%s specifies no directory!', $arguments[0])); - } - - if (!file_exists($arguments[0] . '/package.xml')) { - throw new Horde_Element_Exception(sprintf('There is no package.xml at %s!', $arguments[0])); - } - } -} \ No newline at end of file diff --git a/components/lib/Horde/Element/Config.php b/components/lib/Horde/Element/Config.php deleted file mode 100644 index da22e4680..000000000 --- a/components/lib/Horde/Element/Config.php +++ /dev/null @@ -1,53 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Config:: interface represents a configuration type for the Horde - * element tool. - * - * Copyright 2009-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -interface Horde_Element_Config -{ - /** - * Provide each configuration handler with the list of supported modules. - * - * @param Horde_Element_Modules $modules A list of modules. - * @return NULL - */ - public function handleModules(Horde_Element_Modules $modules); - - /** - * Return the options provided by the configuration handlers. - * - * @return array An array of options. - */ - public function getOptions(); - - /** - * Return the arguments provided by the configuration handlers. - * - * @return array An array of arguments. - */ - public function getArguments(); -} \ No newline at end of file diff --git a/components/lib/Horde/Element/Config/Cli.php b/components/lib/Horde/Element/Config/Cli.php deleted file mode 100644 index 6f63f94a4..000000000 --- a/components/lib/Horde/Element/Config/Cli.php +++ /dev/null @@ -1,119 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Config_Cli:: class provides the command line interface for the Horde - * element tool. - * - * Copyright 2009-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Config_Cli -implements Horde_Element_Config -{ - /** - * The command line argument parser. - * - * @var Horde_Argv_Parser - */ - private $_parser; - - /** - * The options parsed from the command line. - * - * @var array - */ - private $_options; - - /** - * Any additional arguments parsed from the command line. - * - * @var array - */ - private $_arguments; - - /** - * Constructor. - * - */ - public function __construct( - Horde_Argv_Parser $parser - ) { - $this->_parser = $parser; - } - - /** - * Load the options for the list of supported modules. - * - * @param Horde_Element_Modules $modules A list of modules. - * @return NULL - */ - public function handleModules(Horde_Element_Modules $modules) - { - foreach ($modules as $module) { - $this->_addOptionsFromModule($this->_parser, $module); - } - - list($this->_options, $this->_arguments) = $this->_parser->parseArgs(); - } - - /** - * Return the options parsed from the command line. - * - * @return Horde_Argv_Values The option values. - */ - public function getOptions() - { - return $this->_options; - } - - /** - * Return the arguments parsed from the command line. - * - * @return array An array of arguments. - */ - public function getArguments() - { - return $this->_arguments; - } - - /** - * Add an option group from the provided module to the parser. - * - * @param Horde_Argv_Parser $parser The parser. - * @param Horde_Element_Module $module The module providing the option group. - * - * @return NULL - */ - private function _addOptionsFromModule($parser, $module) - { - $group = new Horde_Argv_OptionGroup( - $parser, - $module->getOptionGroupTitle(), - $module->getOptionGroupDescription() - ); - foreach ($module->getOptionGroupOptions() as $option) { - $group->addOption($option); - } - $parser->addOptionGroup($group); - } -} diff --git a/components/lib/Horde/Element/Configs.php b/components/lib/Horde/Element/Configs.php deleted file mode 100644 index ee5a07203..000000000 --- a/components/lib/Horde/Element/Configs.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Configs:: class represents configuration for the - * Horde element tool. - * - * Copyright 2009-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Configs -implements Horde_Element_Config -{ - - /** - * The different configuration handlers. - * - * @var array - */ - private $_configs; - - /** - * Constructor. - */ - public function __construct() { - $this->_configs = array(); - } - - /** - * Add a configuration type to the configuration handler. - * - * @param Horde_Element_Config $type The configuration type. - * - * @return NULL - */ - public function addConfigurationType(Horde_Element_Config $type) { - $this->_configs[] = $type; - } - - /** - * Provide each configuration handler with the list of supported modules. - * - * @param Horde_Element_Modules $modules A list of modules. - * @return NULL - */ - public function handleModules(Horde_Element_Modules $modules) - { - foreach ($this->_configs as $config) { - $config->handleModules($modules); - } - } - - /** - * Return the options provided by the configuration handlers. - * - * @return array An array of options. - */ - public function getOptions() - { - $options = array(); - foreach ($this->_configs as $config) { - if (count($config->getOptions()) !== 0) { - $config_options = array(); - foreach ($config->getOptions() as $name => $option) { - $config_options[$name] = $option; - } - $options = array_merge($options, $config_options); - } - } - return $options; - } - - /** - * Return the arguments provided by the configuration handlers. - * - * @return array An array of arguments. - */ - public function getArguments() - { - $arguments = array(); - foreach ($this->_configs as $config) { - $config_arguments = $config->getArguments(); - if (!empty($config_arguments)) { - $arguments = array_merge($arguments, $config_arguments); - } - } - return $arguments; - } -} \ No newline at end of file diff --git a/components/lib/Horde/Element/Constants.php b/components/lib/Horde/Element/Constants.php deleted file mode 100644 index 42f8e9fa5..000000000 --- a/components/lib/Horde/Element/Constants.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Constants:: provides the constants for this package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Constants -{ - const DATA_DIR = '@data_dir@'; - - static public function getDataDirectory() - { - if (strpos(self::DATA_DIR, '@data_dir') === 0) { - return join( - DIRECTORY_SEPARATOR, - array(dirname(__FILE__), '..', '..', '..', 'data') - ); - } - return self::DATA_DIR . DIRECTORY_SEPARATOR . 'Element'; - } -} diff --git a/components/lib/Horde/Element/Exception.php b/components/lib/Horde/Element/Exception.php deleted file mode 100644 index 115b70a88..000000000 --- a/components/lib/Horde/Element/Exception.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * This class provides the standard error class for the Element package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Exception -extends Exception -{ -} diff --git a/components/lib/Horde/Element/Module.php b/components/lib/Horde/Element/Module.php deleted file mode 100644 index 43a98627d..000000000 --- a/components/lib/Horde/Element/Module.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Module:: represents a task for a Horde element. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -interface Horde_Element_Module -{ - public function getOptionGroupTitle(); - - public function getOptionGroupDescription(); - - public function getOptionGroupOptions(); - - public function handle(Horde_Element_Config $config); - - public function run(Horde_Element_Config $config); -} \ No newline at end of file diff --git a/components/lib/Horde/Element/Module/CiSetup.php b/components/lib/Horde/Element/Module/CiSetup.php deleted file mode 100644 index 786046675..000000000 --- a/components/lib/Horde/Element/Module/CiSetup.php +++ /dev/null @@ -1,139 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Module_CiSetup:: generates the configuration for Hudson based - * continuous integration of a Horde PEAR package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Module_CiSetup -implements Horde_Element_Module -{ - public function getOptionGroupTitle() - { - return 'Continuous Integration Setup'; - } - - public function getOptionGroupDescription() - { - return 'This module generates the configuration for Hudson based continuous integration of a Horde PEAR package.'; - } - - public function getOptionGroupOptions() - { - return array( - new Horde_Argv_Option( - '-c', - '--cisetup', - array( - 'action' => 'store', - 'help' => 'generate the basic Hudson project configuration for a Horde PEAR package in CISETUP' - ) - ), - new Horde_Argv_Option( - '-C', - '--ciprebuild', - array( - 'action' => 'store', - 'help' => 'generate the Hudson build configuration for a Horde PEAR package in CIPREBUILD' - ) - ), - new Horde_Argv_Option( - '-T', - '--toolsdir', - array( - 'action' => 'store', - 'help' => 'the path to the PEAR installation holding the required analysis tools' - ) - ), - ); - } - - public function handle(Horde_Element_Config $config) - { - $options = $config->getOptions(); - if (!empty($options['cisetup']) | !empty($options['ciprebuild'])) { - $this->run($config); - } - } - - public function run(Horde_Element_Config $config) - { - $options = $config->getOptions(); - - $pear = new PEAR(); - $pear->setErrorHandling(PEAR_ERROR_DIE); - - $arguments = $config->getArguments(); - $pkgfile = $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'; - $name = basename($arguments[0]); - if (basename(dirname($arguments[0])) == 'framework') { - $origin = 'framework' . DIRECTORY_SEPARATOR . $name; - } else { - $origin = $name; - } - $test_path = strtr($name, '_', '/'); - - $pkg = new PEAR_PackageFile(new PEAR_Config()); - $pf = $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); - $description = $pf->getDescription(); - - if (!isset($options['toolsdir'])) { - $options['toolsdir'] = 'php-hudson-tools/workspace/pear/pear'; - } - - if (!empty($options['cisetup'])) { - $in = file_get_contents( - Horde_Element_Constants::getDataDirectory() - . DIRECTORY_SEPARATOR . 'hudson-element-config.xml.template', - 'r' - ); - file_put_contents( - $options['cisetup'] . DIRECTORY_SEPARATOR . 'config.xml', - sprintf($in, $origin, 'horde', $options['toolsdir'], $description) - ); - } - - if (!empty($options['ciprebuild'])) { - $in = file_get_contents( - Horde_Element_Constants::getDataDirectory() - . DIRECTORY_SEPARATOR . 'hudson-element-build.xml.template', - 'r' - ); - file_put_contents( - $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'build.xml', - sprintf($in, $options['toolsdir']) - ); - $in = file_get_contents( - Horde_Element_Constants::getDataDirectory() - . DIRECTORY_SEPARATOR . 'hudson-element-phpunit.xml.template', - 'r' - ); - file_put_contents( - $options['ciprebuild'] . DIRECTORY_SEPARATOR . 'phpunit.xml', - sprintf($in, $name, $test_path) - ); - } - } -} diff --git a/components/lib/Horde/Element/Module/DevPackage.php b/components/lib/Horde/Element/Module/DevPackage.php deleted file mode 100644 index 259d5ea67..000000000 --- a/components/lib/Horde/Element/Module/DevPackage.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Module_DevPackage:: generates a development snapshot for the - * specified package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Module_DevPackage -implements Horde_Element_Module -{ - public function getOptionGroupTitle() - { - return 'Development Packages'; - } - - public function getOptionGroupDescription() - { - return 'This module generates a development snapshot for the specified package'; - } - - public function getOptionGroupOptions() - { - return array( - new Horde_Argv_Option( - '-d', - '--devpackage', - array( - 'action' => 'store_true', - 'help' => 'generate a development snapshot' - ) - ), - ); - } - - public function handle(Horde_Element_Config $config) - { - $options = $config->getOptions(); - if (!empty($options['devpackage'])) { - $this->run($config); - } - } - - public function run(Horde_Element_Config $config) - { - $options = $config->getOptions(); - - $pear = new PEAR(); - $pear->setErrorHandling(PEAR_ERROR_DIE); - - $arguments = $config->getArguments(); - $pkgfile = $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'; - - $pkg = new PEAR_PackageFile(new PEAR_Config()); - $pf = $pkg->fromPackageFile($pkgfile, PEAR_VALIDATE_NORMAL); - $pf->_packageInfo['version']['release'] = $pf->getVersion() - . 'dev' . strftime('%Y%m%d%H%M'); - $gen = $pf->getDefaultGenerator(); - $tgzfile = $gen->toTgz(new PEAR_Common()); - } -} diff --git a/components/lib/Horde/Element/Module/Installer.php b/components/lib/Horde/Element/Module/Installer.php deleted file mode 100644 index 2a425bcdd..000000000 --- a/components/lib/Horde/Element/Module/Installer.php +++ /dev/null @@ -1,172 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Module_Installer:: installs a Horde element including - * its dependencies. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Module_Installer -implements Horde_Element_Module -{ - private $_run; - - public function getOptionGroupTitle() - { - return 'Installer'; - } - - public function getOptionGroupDescription() - { - return 'This module installs a Horde element including its dependencies.'; - } - - public function getOptionGroupOptions() - { - return array( - new Horde_Argv_Option( - '-i', - '--install', - array( - 'action' => 'store', - 'help' => 'install the element into the specified absolute INSTALL location' - ) - ), - ); - } - - public function handle(Horde_Element_Config $config) - { - $options = $config->getOptions(); - if (!empty($options['install'])) { - $this->run($config); - } - } - - public function run(Horde_Element_Config $config) - { - $options = $config->getOptions(); - - $pear = new PEAR(); - $pear->setErrorHandling(PEAR_ERROR_DIE); - - $pearrc = $options['install'] . DIRECTORY_SEPARATOR . '.pearrc'; - $command_config = new PEAR_Command_Config(new PEAR_Frontend_CLI(), new stdClass); - $command_config->doConfigCreate( - 'config-create', array(), array($options['install'], $pearrc) - ); - - $pear_config = new PEAR_Config($pearrc); - $GLOBALS['_PEAR_Config_instance'] = $pear_config; - - $channel = new PEAR_Command_Channels( - new PEAR_Frontend_CLI(), - $pear_config - ); - $channel->doDiscover('channel-discover', array(), array('pear.horde.org')); - $channel->doDiscover('channel-discover', array(), array('pear.phpunit.de')); - - $installer = new PEAR_Command_Install( - new PEAR_Frontend_CLI(), - $pear_config - ); - - $arguments = $config->getArguments(); - $element = basename(realpath($arguments[0])); - $root_path = dirname(realpath($arguments[0])); - - $this->_run = array(); - - $this->_installHordeDependency( - $installer, - $pear_config, - $root_path, - $element - ); - } - - /** - * Install a Horde dependency from the current tree (the framework). - * - * @param PEAR_Command_Install $installer Installs the dependency. - * @param PEAR_Config $pear_config The configuration of the PEAR - * environment in which the - * dependency will be installed. - * @param string $root_path Root path to the Horde framework. - * @param string $dependency Package name of the dependency. - */ - private function _installHordeDependency( - PEAR_Command_Install $installer, - PEAR_Config $pear_config, - $root_path, - $dependency - ) { - $package_file = $root_path . DIRECTORY_SEPARATOR - . $dependency . DIRECTORY_SEPARATOR . 'package.xml'; - - $parser = new PEAR_PackageFile_Parser_v2(); - $parser->setConfig($pear_config); - $pkg = $parser->parse(file_get_contents($package_file), $package_file); - - $dependencies = $pkg->getDeps(); - foreach ($dependencies as $dependency) { - if (isset($dependency['channel']) && $dependency['channel'] != 'pear.horde.org') { - $key = $dependency['channel'] . '/' . $dependency['name']; - if (in_array($key, $this->_run)) { - continue; - } - $installer->doInstall( - 'install', - array( - 'force' => true, - 'channel' => $dependency['channel'], - ), - array($dependency['name']) - ); - $this->_run[] = $key; - } else if (isset($dependency['channel'])) { - $key = $dependency['channel'] . '/' . $dependency['name']; - if (in_array($key, $this->_run)) { - continue; - } - $this->_run[] = $key; - $this->_installHordeDependency( - $installer, - $pear_config, - $root_path, - $dependency['name'] - ); - } - } - if (in_array($package_file, $this->_run)) { - return; - } - $installer->doInstall( - 'install', - array('nodeps' => true), - array($package_file) - ); - $this->_run[] = $package_file; - } -} diff --git a/components/lib/Horde/Element/Module/PearPackageXml.php b/components/lib/Horde/Element/Module/PearPackageXml.php deleted file mode 100644 index 44395276a..000000000 --- a/components/lib/Horde/Element/Module/PearPackageXml.php +++ /dev/null @@ -1,163 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Horde_Element_Module_PearPackageXml:: can update the package.xml of - * a Horde element. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Module_PearPackageXml -implements Horde_Element_Module -{ - public function getOptionGroupTitle() - { - return 'Pear Package Xml'; - } - - public function getOptionGroupDescription() - { - return 'This module allows manipulation of the package.xml.'; - } - - public function getOptionGroupOptions() - { - return array( - new Horde_Argv_Option( - '-u', - '--updatexml', - array( - 'action' => 'store_true', - 'help' => 'update the package.xml for the package' - ) - ), - new Horde_Argv_Option( - '-p', - '--packagexml', - array( - 'action' => 'store_true', - 'help' => 'display an up-to-date package.xml for the package' - ) - ) - - ); - } - - public function handle(Horde_Element_Config $config) - { - $options = $config->getOptions(); - if (!empty($options['packagexml']) || - !empty($options['updatexml'])) { - $this->run($config); - } - } - - public function run(Horde_Element_Config $config) - { - $arguments = $config->getArguments(); - $package_file = $arguments[0] . '/package.xml'; - - $pear = new PEAR(); - $pear->setErrorHandling(PEAR_ERROR_DIE); - - $package = PEAR_PackageFileManager2::importOptions( - $package_file, - array( - 'packagedirectory' => $arguments[0], - 'filelistgenerator' => 'file', - 'clearcontents' => false, - 'clearchangelog' => false, - 'simpleoutput' => true, - 'ignore' => array('*~', 'conf.php', 'CVS/*'), - 'include' => '*', - 'dir_roles' => - array( - 'lib' => 'php', - 'doc' => 'doc', - 'example' => 'doc', - 'script' => 'script', - 'test' => 'test', - 'migration' => 'data', - ), - ) - ); - - if ($package instanceOf PEAR_Error) { - throw new Horde_Element_Exception($package->getMessage()); - } - /** - * @todo: Looks like this throws away any tags we have in - * the content list. Needs to be fixed. - */ - $package->generateContents(); - - /** - * This is required to clear the - * section. - */ - $package->setPackageType('php'); - - $contents = $package->getContents(); - $files = $contents['dir']['file']; - - foreach ($files as $file) { - $components = explode('/', $file['attribs']['name'], 2); - switch ($components[0]) { - case 'doc': - case 'example': - case 'lib': - case 'test': - case 'data': - $package->addInstallAs( - $file['attribs']['name'], $components[1] - ); - break; - case 'migration': - $components = explode('/', $components[1]); - array_splice($components, count($components) - 1, 0, 'migration'); - $package->addInstallAs( - $file['attribs']['name'], implode('/', $components) - ); - break; - case 'script': - $filename = basename($file['attribs']['name']); - if (substr($filename, strlen($filename) - 4)) { - $filename = substr($filename, 0, strlen($filename) - 4); - } - $package->addInstallAs( - $file['attribs']['name'], $filename - ); - break; - } - } - - $options = $config->getOptions(); - if (!empty($options['packagexml'])) { - $package->debugPackageFile(); - } - if (!empty($options['updatexml'])) { - $package->writePackageFile(); - } - - } -} diff --git a/components/lib/Horde/Element/Modules.php b/components/lib/Horde/Element/Modules.php deleted file mode 100644 index 9c188f4bb..000000000 --- a/components/lib/Horde/Element/Modules.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * The Horde_Element_Modules:: class handles a set of Element modules. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Modules -implements Iterator, Countable -{ - /** - * The available modules. - * - * @var array - */ - private $_modules; - - /** - * Constructor. - */ - public function __construct() - { - $this->_modules = array(); - } - - /** - * Add all modules found in the specified directory. - * - * @param string $module_directory Load the modules from this dirrectory. - * - * @return NULL - */ - public function addModulesFromDirectory( - $module_directory, - $base = 'Horde_Element_Module_' - ) { - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($module_directory)) as $file) { - if ($file->isFile() && preg_match('/.php$/', $file->getFilename())) { - $class = $base . preg_replace("/^(.*)\.php/", '\\1', $file->getFilename()); - $this->_modules[$class] = new $class(); - } - } - } - - /** - * Implementation of the Iterator rewind() method. Rewinds the module list. - * - * return NULL - */ - public function rewind() - { - reset($this->_modules); - } - - /** - * Implementation of the Iterator current(). Returns the current module. - * - * @return mixed The current module. - */ - public function current() - { - return current($this->_modules); - } - - /** - * Implementation of the Iterator key() method. Returns the key of the current module. - * - * @return mixed The class name of the current module. - */ - public function key() - { - return key($this->_modules); - } - - /** - * Implementation of the Iterator next() method. Returns the next module. - * - * @return Horde_Element_Module|null The next module or null if there are no more - * modules. - */ - public function next() - { - return next($this->_modules); - } - - /** - * Implementation of the Iterator valid() method. Indicates if the current element is a valid element. - * - * @return boolean Whether the current element is valid - */ - public function valid() - { - return key($this->_modules) !== null; - } - - /** - * Implementation of Countable count() method. Returns the number of modules. - * - * @return integer Number of modules. - */ - public function count() - { - return count($this->_modules); - } -} \ No newline at end of file diff --git a/components/script/horde-components.php b/components/script/horde-components.php new file mode 100755 index 000000000..f0ae98f0f --- /dev/null +++ b/components/script/horde-components.php @@ -0,0 +1,4 @@ +#!/usr/bin/env php + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Define the main method + */ +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Horde_Element_AllTests::main'); +} + +/** + * Prepare the test setup. + */ +require_once 'Horde/Test/AllTests.php'; + +/** + * Combine the tests for this package. + * + * Copyright 2007-2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_AllTests extends Horde_Test_AllTests +{ +} + +Horde_Element_AllTests::init('Horde_Element', __FILE__); + +if (PHPUnit_MAIN_METHOD == 'Horde_Element_AllTests::main') { + Horde_Element_AllTests::main(); +} diff --git a/components/test/Components/Autoload.php b/components/test/Components/Autoload.php new file mode 100644 index 000000000..b0b1fb6ca --- /dev/null +++ b/components/test/Components/Autoload.php @@ -0,0 +1,41 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +if (!spl_autoload_functions()) { + spl_autoload_register( + create_function( + '$class', + '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);' + . '$err_mask = E_ALL ^ E_WARNING;' + . '$oldErrorReporting = error_reporting($err_mask);' + . 'include "$filename.php";' + . 'error_reporting($oldErrorReporting);' + ) + ); +} + +/** Catch strict standards */ +error_reporting(E_ALL | E_STRICT); + + +/** Load the basic test definition */ +require_once dirname(__FILE__) . '/StoryTestCase.php'; + +/** Load stubs */ +require_once dirname(__FILE__) . '/Stub/Parser.php'; diff --git a/components/test/Components/Integration/ElementTest.php b/components/test/Components/Integration/ElementTest.php new file mode 100644 index 000000000..9d461db63 --- /dev/null +++ b/components/test/Components/Integration/ElementTest.php @@ -0,0 +1,121 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../Autoload.php'; + +/** + * Test the Element package. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_Integration_ElementTest +extends Horde_Element_StoryTestCase +{ + /** + * @scenario + */ + public function theHelpOptionResultsInHelpOutput() + { + $this->given('the default Element setup') + ->when('calling the package with the help option') + ->then('the help will be displayed'); + } + + /** + * @scenario + */ + public function thePearpackagexmlModuleAddsThePOptionInTheHelpOutput() + { + $this->given('the default Element setup') + ->when('calling the package with the help option') + ->then('the help will contain the "p" option.'); + } + + /** + * @scenario + */ + public function thePearpackagexmlModuleAddsTheUOptionInTheHelpOutput() + { + $this->given('the default Element setup') + ->when('calling the package with the help option') + ->then('the help will contain the "u" option.'); + } + + /** + * @scenario + */ + public function theDevpackageModuleAddsTheDOptionInTheHelpOutput() + { + $this->given('the default Element setup') + ->when('calling the package with the help option') + ->then('the help will contain the "d" option.'); + } + + /** + * @scenario + */ + public function theThePOptionProvidesAnUpdatedPackageXml() + { + $this->given('the default Element setup') + ->when('calling the package with the packagexml option and a Horde element') + ->then('the new package.xml of the Horde element will be printed.'); + } + + /** + * @todo Test (and fix) the reactions to three more scenarios: + * - invalid XML in the package.xml (e.g. tag missing) + * - empty file list + * - file list with just one entry. + * + * All three scenarios yield errors which are still hard to + * understand. + */ + + /** + * @scenario + */ + public function theInstallerModuleAddsTheIOptionInTheHelpOutput() + { + $this->given('the default Element setup') + ->when('calling the package with the help option') + ->then('the help will contain the "i" option.'); + } + + /** + * @scenario + */ + public function theTheIOptionInstallsThePackageFromTheCurrentTree() + { + $this->given('the default Element setup') + ->when('calling the package with the install option and a Horde element') + ->then('a new PEAR configuration file will be installed') + ->and('the PEAR package will be installed') + ->and('the non-Horde dependencies of the Horde element will get installed from the network.') + ->and('the Horde dependencies of the Horde element will get installed from the current tree.') + ->and('the Horde element will be installed'); + } +} \ No newline at end of file diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php new file mode 100644 index 000000000..4d05428ab --- /dev/null +++ b/components/test/Components/StoryTestCase.php @@ -0,0 +1,246 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ + +/** + * Base for story based package testing. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Element + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Element + */ +class Horde_Element_StoryTestCase +extends PHPUnit_Extensions_Story_TestCase +{ + public function tearDown() + { + if (!empty($this->_temp_dir)) { + $this->_rrmdir($this->_temp_dir); + } + } + + /** + * Handle a "given" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runGiven(&$world, $action, $arguments) + { + switch($action) { + case 'the default Element setup': + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "when" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runWhen(&$world, $action, $arguments) + { + switch($action) { + case 'calling the package with the help option': + $_SERVER['argv'] = array( + 'horde-element', + '--help', + dirname(__FILE__) . '/fixture/empty' + ); + ob_start(); + $parameters = array(); + $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; + Horde_Element::main($parameters); + $world['output'] = ob_get_contents(); + ob_end_clean(); + break; + case 'calling the package with the packagexml option and a Horde element': + $_SERVER['argv'] = array( + 'horde-element', + '--packagexml', + dirname(__FILE__) . '/fixture/simple' + ); + ob_start(); + $parameters = array(); + $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; + $old_errorreporting = error_reporting(E_ALL & ~E_STRICT); + Horde_Element::main($parameters); + error_reporting($old_errorreporting); + $world['output'] = ob_get_contents(); + ob_end_clean(); + break; + case 'calling the package with the install option and a Horde element': + $_SERVER['argv'] = array( + 'horde-element', + '--install=' . $this->_getTemporaryDirectory(), + dirname(__FILE__) . '/../../../' + ); + ob_start(); + $parameters = array(); + $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; + $old_errorreporting = error_reporting(E_ALL & ~E_STRICT); + Horde_Element::main($parameters); + error_reporting($old_errorreporting); + $world['output'] = ob_get_contents(); + ob_end_clean(); + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "then" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runThen(&$world, $action, $arguments) + { + switch($action) { + case 'the help will be displayed': + $this->assertRegExp( + '/-h,[ ]*--help[ ]*show this help message and exit/', + $world['output'] + ); + break; + case 'the help will contain the "p" option.': + $this->assertRegExp( + '/-p,\s*--packagexml/m', + $world['output'] + ); + break; + case 'the help will contain the "u" option.': + $this->assertRegExp( + '/-u,\s*--updatexml/', + $world['output'] + ); + break; + case 'the help will contain the "d" option.': + $this->assertRegExp( + '/-d,\s*--devpackage/', + $world['output'] + ); + break; + case 'the help will contain the "i" option.': + $this->assertRegExp( + '/-i\s*INSTALL,\s*--install=INSTALL/', + $world['output'] + ); + break; + case 'the new package.xml of the Horde element will be printed.': + $this->assertRegExp( + '//', + $world['output'] + ); + break; + case 'a new PEAR configuration file will be installed': + $this->assertTrue( + file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . '.pearrc') + ); + break; + case 'the PEAR package will be installed': + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'pear' . DIRECTORY_SEPARATOR + . 'php' . DIRECTORY_SEPARATOR + . 'PEAR.php' + ) + ); + break; + case 'the non-Horde dependencies of the Horde element will get installed from the network.': + var_dump($world['output']); + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'pear' . DIRECTORY_SEPARATOR + . 'php' . DIRECTORY_SEPARATOR + . 'PEAR' . DIRECTORY_SEPARATOR + . 'PackageFileManager2.php' + ) + ); + break; + case 'the Horde dependencies of the Horde element will get installed from the current tree.': + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'pear' . DIRECTORY_SEPARATOR + . 'php' . DIRECTORY_SEPARATOR + . 'Horde' . DIRECTORY_SEPARATOR + . 'Autoloader.php' + ) + ); + break; + case 'the Horde element will be installed': + $this->assertTrue( + file_exists( + $this->_temp_dir . DIRECTORY_SEPARATOR + . 'pear' . DIRECTORY_SEPARATOR + . 'php' . DIRECTORY_SEPARATOR + . 'Horde' . DIRECTORY_SEPARATOR + . 'Element.php' + ) + ); + break; + default: + return $this->notImplemented($action); + } + } + + private function _getTemporaryDirectory() + { + $this->_temp_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR + . 'Horde_Element_' . mt_rand(); + mkdir($this->_temp_dir); + return $this->_temp_dir; + } + + private function _rrmdir($dir) + { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != '.' && $object != '..') { + if (filetype($dir . DIRECTORY_SEPARATOR . $object) == 'dir') { + $this->_rrmdir($dir . DIRECTORY_SEPARATOR . $object); + } else { + unlink($dir . DIRECTORY_SEPARATOR . $object); + } + } + } + reset($objects); + rmdir($dir); + } + } +} \ No newline at end of file diff --git a/components/test/Components/Stub/Parser.php b/components/test/Components/Stub/Parser.php new file mode 100644 index 000000000..e704661fa --- /dev/null +++ b/components/test/Components/Stub/Parser.php @@ -0,0 +1,10 @@ + + + Fixture + pear.horde.org + Test fixture. + A dummy package.xml used for testing the Horde_Element package. + + Gunnar Wrobel + wrobel + p@rdus.de + yes + + 2010-08-22 + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + LGPL + +* Initial release + + + + + + + + + + + + 5.0.0 + + + 1.7.0 + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2010-08-22 + LGPL + +* Initial release + + + + diff --git a/components/test/Components/phpunit.xml b/components/test/Components/phpunit.xml new file mode 100644 index 000000000..502d3c9b8 --- /dev/null +++ b/components/test/Components/phpunit.xml @@ -0,0 +1,8 @@ + + + + + ../../../lib + + + diff --git a/components/test/Horde/Element/AllTests.php b/components/test/Horde/Element/AllTests.php deleted file mode 100644 index deb0ed89a..000000000 --- a/components/test/Horde/Element/AllTests.php +++ /dev/null @@ -1,50 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Define the main method - */ -if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Horde_Element_AllTests::main'); -} - -/** - * Prepare the test setup. - */ -require_once 'Horde/Test/AllTests.php'; - -/** - * Combine the tests for this package. - * - * Copyright 2007-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @subpackage UnitTests - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_AllTests extends Horde_Test_AllTests -{ -} - -Horde_Element_AllTests::init('Horde_Element', __FILE__); - -if (PHPUnit_MAIN_METHOD == 'Horde_Element_AllTests::main') { - Horde_Element_AllTests::main(); -} diff --git a/components/test/Horde/Element/Autoload.php b/components/test/Horde/Element/Autoload.php deleted file mode 100644 index b0b1fb6ca..000000000 --- a/components/test/Horde/Element/Autoload.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -if (!spl_autoload_functions()) { - spl_autoload_register( - create_function( - '$class', - '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);' - . '$err_mask = E_ALL ^ E_WARNING;' - . '$oldErrorReporting = error_reporting($err_mask);' - . 'include "$filename.php";' - . 'error_reporting($oldErrorReporting);' - ) - ); -} - -/** Catch strict standards */ -error_reporting(E_ALL | E_STRICT); - - -/** Load the basic test definition */ -require_once dirname(__FILE__) . '/StoryTestCase.php'; - -/** Load stubs */ -require_once dirname(__FILE__) . '/Stub/Parser.php'; diff --git a/components/test/Horde/Element/Integration/ElementTest.php b/components/test/Horde/Element/Integration/ElementTest.php deleted file mode 100644 index 9d461db63..000000000 --- a/components/test/Horde/Element/Integration/ElementTest.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the Element package. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @subpackage UnitTests - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_Integration_ElementTest -extends Horde_Element_StoryTestCase -{ - /** - * @scenario - */ - public function theHelpOptionResultsInHelpOutput() - { - $this->given('the default Element setup') - ->when('calling the package with the help option') - ->then('the help will be displayed'); - } - - /** - * @scenario - */ - public function thePearpackagexmlModuleAddsThePOptionInTheHelpOutput() - { - $this->given('the default Element setup') - ->when('calling the package with the help option') - ->then('the help will contain the "p" option.'); - } - - /** - * @scenario - */ - public function thePearpackagexmlModuleAddsTheUOptionInTheHelpOutput() - { - $this->given('the default Element setup') - ->when('calling the package with the help option') - ->then('the help will contain the "u" option.'); - } - - /** - * @scenario - */ - public function theDevpackageModuleAddsTheDOptionInTheHelpOutput() - { - $this->given('the default Element setup') - ->when('calling the package with the help option') - ->then('the help will contain the "d" option.'); - } - - /** - * @scenario - */ - public function theThePOptionProvidesAnUpdatedPackageXml() - { - $this->given('the default Element setup') - ->when('calling the package with the packagexml option and a Horde element') - ->then('the new package.xml of the Horde element will be printed.'); - } - - /** - * @todo Test (and fix) the reactions to three more scenarios: - * - invalid XML in the package.xml (e.g. tag missing) - * - empty file list - * - file list with just one entry. - * - * All three scenarios yield errors which are still hard to - * understand. - */ - - /** - * @scenario - */ - public function theInstallerModuleAddsTheIOptionInTheHelpOutput() - { - $this->given('the default Element setup') - ->when('calling the package with the help option') - ->then('the help will contain the "i" option.'); - } - - /** - * @scenario - */ - public function theTheIOptionInstallsThePackageFromTheCurrentTree() - { - $this->given('the default Element setup') - ->when('calling the package with the install option and a Horde element') - ->then('a new PEAR configuration file will be installed') - ->and('the PEAR package will be installed') - ->and('the non-Horde dependencies of the Horde element will get installed from the network.') - ->and('the Horde dependencies of the Horde element will get installed from the current tree.') - ->and('the Horde element will be installed'); - } -} \ No newline at end of file diff --git a/components/test/Horde/Element/StoryTestCase.php b/components/test/Horde/Element/StoryTestCase.php deleted file mode 100644 index 4d05428ab..000000000 --- a/components/test/Horde/Element/StoryTestCase.php +++ /dev/null @@ -1,246 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ - -/** - * Base for story based package testing. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Element - * @subpackage UnitTests - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Element - */ -class Horde_Element_StoryTestCase -extends PHPUnit_Extensions_Story_TestCase -{ - public function tearDown() - { - if (!empty($this->_temp_dir)) { - $this->_rrmdir($this->_temp_dir); - } - } - - /** - * Handle a "given" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runGiven(&$world, $action, $arguments) - { - switch($action) { - case 'the default Element setup': - break; - default: - return $this->notImplemented($action); - } - } - - /** - * Handle a "when" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runWhen(&$world, $action, $arguments) - { - switch($action) { - case 'calling the package with the help option': - $_SERVER['argv'] = array( - 'horde-element', - '--help', - dirname(__FILE__) . '/fixture/empty' - ); - ob_start(); - $parameters = array(); - $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; - Horde_Element::main($parameters); - $world['output'] = ob_get_contents(); - ob_end_clean(); - break; - case 'calling the package with the packagexml option and a Horde element': - $_SERVER['argv'] = array( - 'horde-element', - '--packagexml', - dirname(__FILE__) . '/fixture/simple' - ); - ob_start(); - $parameters = array(); - $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; - $old_errorreporting = error_reporting(E_ALL & ~E_STRICT); - Horde_Element::main($parameters); - error_reporting($old_errorreporting); - $world['output'] = ob_get_contents(); - ob_end_clean(); - break; - case 'calling the package with the install option and a Horde element': - $_SERVER['argv'] = array( - 'horde-element', - '--install=' . $this->_getTemporaryDirectory(), - dirname(__FILE__) . '/../../../' - ); - ob_start(); - $parameters = array(); - $parameters['cli']['parser']['class'] = 'Horde_Element_Stub_Parser'; - $old_errorreporting = error_reporting(E_ALL & ~E_STRICT); - Horde_Element::main($parameters); - error_reporting($old_errorreporting); - $world['output'] = ob_get_contents(); - ob_end_clean(); - break; - default: - return $this->notImplemented($action); - } - } - - /** - * Handle a "then" step. - * - * @param array &$world Joined "world" of variables. - * @param string $action The description of the step. - * @param array $arguments Additional arguments to the step. - * - * @return mixed The outcome of the step. - */ - public function runThen(&$world, $action, $arguments) - { - switch($action) { - case 'the help will be displayed': - $this->assertRegExp( - '/-h,[ ]*--help[ ]*show this help message and exit/', - $world['output'] - ); - break; - case 'the help will contain the "p" option.': - $this->assertRegExp( - '/-p,\s*--packagexml/m', - $world['output'] - ); - break; - case 'the help will contain the "u" option.': - $this->assertRegExp( - '/-u,\s*--updatexml/', - $world['output'] - ); - break; - case 'the help will contain the "d" option.': - $this->assertRegExp( - '/-d,\s*--devpackage/', - $world['output'] - ); - break; - case 'the help will contain the "i" option.': - $this->assertRegExp( - '/-i\s*INSTALL,\s*--install=INSTALL/', - $world['output'] - ); - break; - case 'the new package.xml of the Horde element will be printed.': - $this->assertRegExp( - '//', - $world['output'] - ); - break; - case 'a new PEAR configuration file will be installed': - $this->assertTrue( - file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . '.pearrc') - ); - break; - case 'the PEAR package will be installed': - $this->assertTrue( - file_exists( - $this->_temp_dir . DIRECTORY_SEPARATOR - . 'pear' . DIRECTORY_SEPARATOR - . 'php' . DIRECTORY_SEPARATOR - . 'PEAR.php' - ) - ); - break; - case 'the non-Horde dependencies of the Horde element will get installed from the network.': - var_dump($world['output']); - $this->assertTrue( - file_exists( - $this->_temp_dir . DIRECTORY_SEPARATOR - . 'pear' . DIRECTORY_SEPARATOR - . 'php' . DIRECTORY_SEPARATOR - . 'PEAR' . DIRECTORY_SEPARATOR - . 'PackageFileManager2.php' - ) - ); - break; - case 'the Horde dependencies of the Horde element will get installed from the current tree.': - $this->assertTrue( - file_exists( - $this->_temp_dir . DIRECTORY_SEPARATOR - . 'pear' . DIRECTORY_SEPARATOR - . 'php' . DIRECTORY_SEPARATOR - . 'Horde' . DIRECTORY_SEPARATOR - . 'Autoloader.php' - ) - ); - break; - case 'the Horde element will be installed': - $this->assertTrue( - file_exists( - $this->_temp_dir . DIRECTORY_SEPARATOR - . 'pear' . DIRECTORY_SEPARATOR - . 'php' . DIRECTORY_SEPARATOR - . 'Horde' . DIRECTORY_SEPARATOR - . 'Element.php' - ) - ); - break; - default: - return $this->notImplemented($action); - } - } - - private function _getTemporaryDirectory() - { - $this->_temp_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR - . 'Horde_Element_' . mt_rand(); - mkdir($this->_temp_dir); - return $this->_temp_dir; - } - - private function _rrmdir($dir) - { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != '.' && $object != '..') { - if (filetype($dir . DIRECTORY_SEPARATOR . $object) == 'dir') { - $this->_rrmdir($dir . DIRECTORY_SEPARATOR . $object); - } else { - unlink($dir . DIRECTORY_SEPARATOR . $object); - } - } - } - reset($objects); - rmdir($dir); - } - } -} \ No newline at end of file diff --git a/components/test/Horde/Element/Stub/Parser.php b/components/test/Horde/Element/Stub/Parser.php deleted file mode 100644 index e704661fa..000000000 --- a/components/test/Horde/Element/Stub/Parser.php +++ /dev/null @@ -1,10 +0,0 @@ - - - Fixture - pear.horde.org - Test fixture. - A dummy package.xml used for testing the Horde_Element package. - - Gunnar Wrobel - wrobel - p@rdus.de - yes - - 2010-08-22 - - - 0.0.1 - 0.0.1 - - - alpha - alpha - - LGPL - -* Initial release - - - - - - - - - - - - 5.0.0 - - - 1.7.0 - - - - - - - - - - - - 0.0.1 - 0.0.1 - - - alpha - alpha - - 2010-08-22 - LGPL - -* Initial release - - - - diff --git a/components/test/Horde/Element/phpunit.xml b/components/test/Horde/Element/phpunit.xml deleted file mode 100644 index 502d3c9b8..000000000 --- a/components/test/Horde/Element/phpunit.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - ../../../lib - - -