From 77b18dd64b9249abc1dc8b012280bb0aceb71ca5 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 25 Jan 2011 10:10:07 +0100 Subject: [PATCH] Support generating package.xml files for our groupware applications. --- components/lib/Components/Pear/Factory.php | 11 ++-- .../Components/Pear/Package/Contents/Factory.php | 58 ++++++++++++++++++++-- .../Components/Pear/Package/Filelist/Default.php | 10 +++- components/lib/Components/Runner/Distribute.php | 2 +- .../Pear/Package/Filelist/DefaultTest.php | 24 ++++++++- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php index 4747e7c6e..fb143f4c0 100644 --- a/components/lib/Components/Pear/Factory.php +++ b/components/lib/Components/Pear/Factory.php @@ -192,8 +192,7 @@ class Components_Pear_Factory public function getPackageFile( $package_xml_path, Components_Pear_InstallLocation $environment - ) - { + ) { $pkg = new PEAR_PackageFile($environment->getPearConfig()); return Components_Exception_Pear::catchError( $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL) @@ -211,8 +210,7 @@ class Components_Pear_Factory public function getPackageFileFromTgz( $package_tgz_path, Components_Pear_InstallLocation $environment - ) - { + ) { $pkg = new PEAR_PackageFile($environment->getPearConfig()); return Components_Exception_Pear::catchError( $pkg->fromTgzFile($package_tgz_path, PEAR_VALIDATE_NORMAL) @@ -229,11 +227,10 @@ class Components_Pear_Factory */ public function createPackageFile( $package_xml_dir - ) - { + ) { $environment = $this->_dependencies->getInstance('Components_Pear_InstallLocation'); $pkg = new PEAR_PackageFile_v2_rw(); - $pkg->setPackage('REPLACE'); + $pkg->setPackage(basename($package_xml_dir)); $pkg->setDescription('REPLACE'); $pkg->setSummary('REPLACE'); $pkg->setReleaseVersion('0.0.1'); diff --git a/components/lib/Components/Pear/Package/Contents/Factory.php b/components/lib/Components/Pear/Package/Contents/Factory.php index caea08ca9..477328913 100644 --- a/components/lib/Components/Pear/Package/Contents/Factory.php +++ b/components/lib/Components/Pear/Package/Contents/Factory.php @@ -41,6 +41,7 @@ class Components_Pear_Package_Contents_Factory $root = new Components_Helper_Root( $package->_options['packagedirectory'] ); + $package->_options['roles'] = $this->_getRoles($root->getBase()); $package->_options['dir_roles'] = $this->_getMapping($root->getBase()); return new Components_Pear_Package_Contents_List( $package->_options['packagedirectory'], @@ -62,22 +63,25 @@ class Components_Pear_Package_Contents_Factory { switch ($path) { case 'horde/': + case 'imp/': + case 'ingo/': + case 'kronolith/': + case 'mnemo/': + case 'nag/': + case 'turba/': return array( - 'admin' => 'horde', 'bin' => 'script', 'config' => 'horde', 'script' => 'script', 'docs' => 'doc', 'js' => 'horde', - 'lib' => 'horde', + 'locale' => 'horde', 'scripts' => 'data', - 'services' => 'horde', 'test' => 'test', 'templates' => 'horde', 'themes' => 'horde', 'util' => 'horde', ); - break; default: return array( 'bin' => 'script', @@ -91,7 +95,51 @@ class Components_Pear_Package_Contents_Factory 'scripts' => 'data', 'test' => 'test', ); - break; + } + } + + /** + * Return the default role mapping for the specific package. + * + * @param string $path The package path. + * + * @return array The mapping. + */ + private function _getRoles($path) + { + switch ($path) { + case 'horde/': + case 'imp/': + case 'ingo/': + case 'kronolith/': + case 'mnemo/': + case 'nag/': + case 'turba/': + return array( + 'h' => 'src', + 'c' => 'src', + 'cpp' => 'src', + 'in' => 'src', + 'm4' => 'src', + 'w32' => 'src', + 'dll' => 'ext', + 'php' => 'horde', + 'html' => 'doc', + '*' => 'data', + ); + default: + return array( + 'h' => 'src', + 'c' => 'src', + 'cpp' => 'src', + 'in' => 'src', + 'm4' => 'src', + 'w32' => 'src', + 'dll' => 'ext', + 'php' => 'php', + 'html' => 'doc', + '*' => 'data', + ); } } } \ No newline at end of file diff --git a/components/lib/Components/Pear/Package/Filelist/Default.php b/components/lib/Components/Pear/Package/Filelist/Default.php index 1f9625094..d98965bba 100644 --- a/components/lib/Components/Pear/Package/Filelist/Default.php +++ b/components/lib/Components/Pear/Package/Filelist/Default.php @@ -74,8 +74,16 @@ class Components_Pear_Package_Filelist_Default switch ($role) { case 'horde': $horde_role = true; + if (in_array( + $this->_package->getName(), + array('imp', 'ingo', 'kronolith', 'mnemo', 'nag', 'turba') + )) { + $prefix = $this->_package->getName() . '/'; + } else { + $prefix = ''; + } $this->_package->addInstallAs( - $file['attribs']['name'], $file['attribs']['name'] + $file['attribs']['name'], $prefix . $file['attribs']['name'] ); break; case 'doc': diff --git a/components/lib/Components/Runner/Distribute.php b/components/lib/Components/Runner/Distribute.php index 96154fdde..2bf2d504e 100644 --- a/components/lib/Components/Runner/Distribute.php +++ b/components/lib/Components/Runner/Distribute.php @@ -86,7 +86,7 @@ class Components_Runner_Distribute } $version = $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M'); - $package->generateSnapshot($version, dirname($options['distribute'])); + $package->generateSnapshot($version, $options['distribute']); $build_template = new Components_Helper_Templates_Directory( $this->_config_application->getTemplateDirectory(), diff --git a/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php b/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php index 60a112bb5..fa0421ffb 100644 --- a/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php +++ b/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php @@ -17,8 +17,6 @@ */ require_once dirname(__FILE__) . '/../../../../../Autoload.php'; - //@require_once 'PEAR/Validate.php'; - /** * Test the handling of file lists. * @@ -39,12 +37,19 @@ extends PHPUnit_Framework_TestCase { public function setUp() { + $this->_old_errorreporting = error_reporting(E_ALL & ~(E_STRICT | E_DEPRECATED)); + error_reporting(E_ALL & ~(E_STRICT | E_DEPRECATED)); if (!defined('PEAR_VALIDATE_INSTALLING')) { define('PEAR_VALIDATE_INSTALLING', 1); define('PEAR_VALIDATE_NORMAL', 3); } } + public function tearDown() + { + error_reporting($this->_old_errorreporting); + } + /** * @dataProvider provideFiles */ @@ -89,6 +94,21 @@ extends PHPUnit_Framework_TestCase $this->_getFilelist($package)->update(); } + public function testApplication() + { + $package = $this->_getPackage(array('role' => 'horde', 'name' => 'a')); + $package->expects($this->once()) + ->method('getUsesRole') + ->will($this->returnValue(array('role' => 'horde'))); + $package->expects($this->any()) + ->method('getName') + ->will($this->returnValue('imp')); + $package->expects($this->once()) + ->method('addInstallAs') + ->with('a', 'imp/a'); + $this->_getFilelist($package)->update(); + } + private function _getPackage(array $contents) { $list = array('dir' => array('file' => array(array('attribs' => $contents)))); -- 2.11.0