From 31227f0822145d55d1d278ec7176795585e2c9ff Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Tue, 2 Nov 2010 08:16:02 +0100 Subject: [PATCH] Started wrapping/modifying the PackageFilemanager based content list generator to allow injecting customized ignores. --- components/lib/Components/Helper/Root.php | 10 +++ components/lib/Components/Pear/Factory.php | 3 - .../lib/Components/Pear/Package/Contents.php | 35 ++++++---- .../Components/Pear/Package/Contents/Factory.php | 51 ++++++++++++++ .../Components/Pear/Package/Contents/Ignore.php | 67 ++++++++++++++++++ .../lib/Components/Pear/Package/Contents/List.php | 80 ++++++++++++++++++++++ 6 files changed, 228 insertions(+), 18 deletions(-) create mode 100644 components/lib/Components/Pear/Package/Contents/Factory.php create mode 100644 components/lib/Components/Pear/Package/Contents/Ignore.php create mode 100644 components/lib/Components/Pear/Package/Contents/List.php diff --git a/components/lib/Components/Helper/Root.php b/components/lib/Components/Helper/Root.php index 2f350b5cf..fc8312cf9 100644 --- a/components/lib/Components/Helper/Root.php +++ b/components/lib/Components/Helper/Root.php @@ -90,4 +90,14 @@ class Components_Helper_Root } return $package_file; } + + /** + * Return the contents of the gitignore file. + * + * @return string The information from the gitignore file. + */ + public function fetchGitIgnore() + { + return ''; + } } \ No newline at end of file diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php index 6e136032e..f6d2f8d08 100644 --- a/components/lib/Components/Pear/Factory.php +++ b/components/lib/Components/Pear/Factory.php @@ -297,12 +297,9 @@ class Components_Pear_Factory $package_xml_path, array( 'packagedirectory' => dirname($package_xml_path), - 'filelistgenerator' => 'file', 'clearcontents' => false, 'clearchangelog' => false, 'simpleoutput' => true, - 'ignore' => array('*~', 'conf.php', 'CVS/*'), - 'include' => '*', 'dir_roles' => array( 'bin' => 'script', diff --git a/components/lib/Components/Pear/Package/Contents.php b/components/lib/Components/Pear/Package/Contents.php index 2bffb9622..2c03805b8 100644 --- a/components/lib/Components/Pear/Package/Contents.php +++ b/components/lib/Components/Pear/Package/Contents.php @@ -49,17 +49,27 @@ class Components_Pear_Package_Contents private $_filelist_factory; /** + * Provides access to the contents handler. + * + * @var Components_Pear_Package_Contents_Factory + */ + private $_contents_factory; + + /** * Constructor. * - * @param Components_Pear_Package_Tasks $tasks A tasks helper. - * @param Components_Pear_Package_Filelist_Factory $factory Creates the filelist handler. + * @param Components_Pear_Package_Tasks $tasks A tasks helper. + * @param Components_Pear_Package_Filelist_Factory $filelist Creates the filelist handler. + * @param Components_Pear_Package_Contents_Factory $contents Creates the contents handler. */ public function __construct( Components_Pear_Package_Tasks $tasks, - Components_Pear_Package_Filelist_Factory $factory + Components_Pear_Package_Filelist_Factory $filelist, + Components_Pear_Package_Contents_Factory $contents ) { $this->_tasks = $tasks; - $this->_filelist_factory = $factory; + $this->_filelist_factory = $filelist; + $this->_contents_factory = $contents; } /** @@ -90,16 +100,6 @@ class Components_Pear_Package_Contents } /** - * Generate an updated contents listing. - * - * @return NULL - */ - private function _generateContents() - { - $this->getPackage()->generateContents(); - } - - /** * Return an updated package description. * * @return PEAR_PackageFileManager2 The updated package. @@ -107,7 +107,12 @@ class Components_Pear_Package_Contents public function update() { $taskfiles = $this->_tasks->denote($this->getPackage()); - $this->_generateContents(); + + $generator = $this->_contents_factory->create($this->getPackage()); + $this->getPackage()->clearContents('/'); + $this->getPackage()->_struc = $generator->getFileList(); + $this->getPackage()->_getSimpleDirTag($this->getPackage()->_struc); + $this->_tasks->annotate($this->getPackage(), $taskfiles); $this->_filelist_factory->create($this->getPackage())->update(); diff --git a/components/lib/Components/Pear/Package/Contents/Factory.php b/components/lib/Components/Pear/Package/Contents/Factory.php new file mode 100644 index 000000000..86c934a3a --- /dev/null +++ b/components/lib/Components/Pear/Package/Contents/Factory.php @@ -0,0 +1,51 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Components_Pear_Package_Contents_Factory:: handles the different content list + * generators. + * + * 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 Components + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Pear_Package_Contents_Factory +{ + /** + * Create the contents handler. + * + * @param PEAR_PackageFile_v2_rw $package The package. + * + * @return Components_Pear_Package_Contents_List The content handler. + */ + public function create(PEAR_PackageFile_v2_rw $package) + { + $root = new Components_Helper_Root( + $package->_options['packagedirectory'] + ); + return new Components_Pear_Package_Contents_List( + $package->_options['packagedirectory'], + new Components_Pear_Package_Contents_Ignore( + $root->fetchGitIgnore() + ) + ); + } +} \ No newline at end of file diff --git a/components/lib/Components/Pear/Package/Contents/Ignore.php b/components/lib/Components/Pear/Package/Contents/Ignore.php new file mode 100644 index 000000000..5d1883bba --- /dev/null +++ b/components/lib/Components/Pear/Package/Contents/Ignore.php @@ -0,0 +1,67 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Components_Pear_Package_Contents_Ignore:: indicates which files in + * a content listing should be ignored. + * + * 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 Components + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Pear_Package_Contents_Ignore +{ + /** + * The gitignore information. + * + * @var string + */ + private $_gitignore; + + /** + * Constructor. + * + * @param string $gitignore The gitignore information + */ + public function __construct($gitignore) + { + $this->_gitignore = $gitignore; + } + + /** + * Tell whether to ignore a file or a directory + * allows * and ? wildcards + * + * @param string $file just the file name of the file or directory, + * in the case of directories this is the last dir + * @param string $path the full path + * @param bool $return value to return if regexp matches. Set this to + * false to include only matches, true to exclude + * all matches + * + * @return bool true if $path should be ignored, false if it should not + * @access private + */ + public function checkIgnore($file, $path, $return = 1) + { + return !$return; + } +} \ No newline at end of file diff --git a/components/lib/Components/Pear/Package/Contents/List.php b/components/lib/Components/Pear/Package/Contents/List.php new file mode 100644 index 000000000..6eb0a858d --- /dev/null +++ b/components/lib/Components/Pear/Package/Contents/List.php @@ -0,0 +1,80 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Components_Pear_Package_Contents_List:: is the default content handler for + * packages. + * + * 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 Components + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Pear_Package_Contents_List +extends PEAR_PackageFileManager_File +{ + /** + * Determines if a file should be ignored. + * + * @var Components_Pear_Package_Contents_Ignore + */ + private $_ignore; + + /** + * Constructor. + * + * @param string $package_directory The directory of the package. + * @param Components_Pear_Package_Contents_Ignore $ignore Ignores files. + */ + public function __construct( + $package_directory, Components_Pear_Package_Contents_Ignore $ignore + ) { + $this->_ignore = $ignore; + $this->_options['packagedirectory'] = $package_directory; + $this->_options['include'] = '*'; + $this->_options['ignore'] = array('*~', 'conf.php', 'CVS/*'); + $this->_options['packagefile'] = 'package.xml'; + $this->_options['addhiddenfiles'] = false; + } + + /** + * Tell whether to ignore a file or a directory + * allows * and ? wildcards + * + * @param string $file just the file name of the file or directory, + * in the case of directories this is the last dir + * @param string $path the full path + * @param bool $return value to return if regexp matches. Set this to + * false to include only matches, true to exclude + * all matches + * + * @return bool true if $path should be ignored, false if it should not + * @access private + */ + function _checkIgnore($file, $path, $return = 1) + { + $result = parent::_checkIgnore($file, $path, $return); + if ($result == $return) { + return $result; + } else { + return $this->_ignore->checkIgnore($file, $path, $return); + } + } +} \ No newline at end of file -- 2.11.0