Started wrapping/modifying the PackageFilemanager based content list generator to...
authorGunnar Wrobel <p@rdus.de>
Tue, 2 Nov 2010 07:16:02 +0000 (08:16 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 2 Nov 2010 19:39:04 +0000 (20:39 +0100)
components/lib/Components/Helper/Root.php
components/lib/Components/Pear/Factory.php
components/lib/Components/Pear/Package/Contents.php
components/lib/Components/Pear/Package/Contents/Factory.php [new file with mode: 0644]
components/lib/Components/Pear/Package/Contents/Ignore.php [new file with mode: 0644]
components/lib/Components/Pear/Package/Contents/List.php [new file with mode: 0644]

index 2f350b5..fc8312c 100644 (file)
@@ -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
index 6e13603..f6d2f8d 100644 (file)
@@ -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',
index 2bffb96..2c03805 100644 (file)
@@ -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 (file)
index 0000000..86c934a
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Components_Pear_Package_Contents_Factory:: handles the different contents
+ * list generators.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..5d1883b
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Components_Pear_Package_Contents_Ignore:: indicates which files in
+ * a content listing should be ignored.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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 (file)
index 0000000..6eb0a85
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Components_Pear_Package_Contents_List:: is the default content handler for
+ * packages.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Components
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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