Move snapshot packaging and package distribution into the Pear module of Components.
authorGunnar Wrobel <p@rdus.de>
Fri, 22 Oct 2010 21:51:21 +0000 (23:51 +0200)
committerGunnar Wrobel <p@rdus.de>
Fri, 22 Oct 2010 21:51:21 +0000 (23:51 +0200)
components/TODO
components/lib/Components/Dependencies.php
components/lib/Components/Dependencies/Injector.php
components/lib/Components/Module/DevPackage.php
components/lib/Components/Pear/Package.php
components/lib/Components/Runner/DevPackage.php [new file with mode: 0644]
components/lib/Components/Runner/Distribute.php
components/test/Components/StoryTestCase.php

index e8bdc8a..8bce255 100644 (file)
@@ -8,6 +8,9 @@
 
  - Add module for an initial empty PEAR template
 
+ - Allow filtering (see http://github.com/horde/horde/commit/404e8d1ea7c0bf99373aec2ce7f2534a442149b3)
+   Potentially check with git if the file is relevant or not.
+
  - Add a commit module that automatically adds a changelog entry in
    the notes section of the package.xml
 
index c926bc3..bddd35a 100644 (file)
@@ -53,6 +53,13 @@ interface Components_Dependencies
     public function getRunnerCiPrebuild();
 
     /**
+     * Returns the snapshot packaging handler for a package.
+     *
+     * @return Components_Runner_DevPackage The snapshot handler.
+     */
+    public function getRunnerDevPackage();
+
+    /**
      * Returns the distribution handler for a package.
      *
      * @return Components_Runner_Distribute The distribution handler.
index 8825cec..c31784e 100644 (file)
@@ -83,6 +83,16 @@ implements Components_Dependencies
     }
 
     /**
+     * Returns the snapshot packaging handler for a package.
+     *
+     * @return Components_Runner_DevPackage The snapshot handler.
+     */
+    public function getRunnerDevPackage()
+    {
+        return $this->getInstance('Components_Runner_DevPackage');
+    }
+
+    /**
      * Returns the dependency list handler for a package.
      *
      * @return Components_Runner_Dependencies The dependency handler.
index 09f406f..011645f 100644 (file)
@@ -28,7 +28,7 @@
  * @link     http://pear.horde.org/index.php?package=Components
  */
 class Components_Module_DevPackage
-implements Components_Module
+extends Components_Module_Base
 {
     public function getOptionGroupTitle()
     {
@@ -58,25 +58,7 @@ implements Components_Module
     {
         $options = $config->getOptions();
         if (!empty($options['devpackage'])) {
-            $this->run($config);
+            $this->_dependencies->getRunnerDevPackage()->run();
         }
     }
-
-    public function run(Components_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());
-    }
 }
index b978607..5766606 100644 (file)
@@ -199,6 +199,36 @@ class Components_Pear_Package
     }
 
     /**
+     * Return the version for this package.
+     *
+     * @return string The package version.
+     */
+    public function getVersion()
+    {
+        return $this->_getPackageFile()->getVersion();
+    }
+
+    /**
+     * Return the license for this package.
+     *
+     * @return string The package license.
+     */
+    public function getLicense()
+    {
+        return $this->_getPackageFile()->getLicense();
+    }
+
+    /**
+     * Return the summary for this package.
+     *
+     * @return string The package summary.
+     */
+    public function getSummary()
+    {
+        return $this->_getPackageFile()->getSummary();
+    }
+
+    /**
      * Update the content listing of the provided package.
      *
      * @param PEAR_PackageFileManager2 $package The package to update.
@@ -397,4 +427,28 @@ class Components_Pear_Package
         return $dependencies;
     }    
 
+    /**
+     * Generate a snapshot of the package using the provided version number.
+     *
+     * @param string $varsion The snapshot version.
+     *
+     * @return string The path to the snapshot.
+     */
+    public function generateSnapshot($version)
+    {
+        $pkg = $this->_getPackageFile();
+        $pkg->_packageInfo['version']['release'] = $version;
+        $pkg->setDate(date('Y-m-d'));
+        $pkg->setTime(date('H:i:s'));
+        ob_start();
+        $result = $pkg->getDefaultGenerator()
+            ->toTgz(new PEAR_Common());
+        $this->_output->pear(ob_get_clean());
+        if ($result instanceOf PEAR_Error) {
+            throw new Components_Exception($result->getMessage());
+        }
+        $this->_output->ok('Generated snapshot ' . $result);
+        return $result;
+    }
+
 }
diff --git a/components/lib/Components/Runner/DevPackage.php b/components/lib/Components/Runner/DevPackage.php
new file mode 100644 (file)
index 0000000..10fa861
--- /dev/null
@@ -0,0 +1,82 @@
+<?php
+/**
+ * Components_Runner_DevPackage:: packages a snapshot.
+ *
+ * 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_Runner_DevPackage:: packages a snapshot.
+ *
+ * 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_Runner_DevPackage
+{
+    /**
+     * The configuration for the current job.
+     *
+     * @var Components_Config
+     */
+    private $_config;
+
+    /**
+     * The factory for PEAR dependencies.
+     *
+     * @var Components_Pear_Factory
+     */
+    private $_factory;
+
+    /**
+     * The output handler.
+     *
+     * @param Component_Output
+     */
+    private $_output;
+
+    /**
+     * Constructor.
+     *
+     * @param Components_Config       $config  The configuration for the current
+     *                                         job.
+     * @param Components_Pear_Factory $factory The factory for PEAR
+     *                                         dependencies.
+     * @param Component_Output        $output  The output handler.
+     */
+    public function __construct(
+        Components_Config $config,
+        Components_Pear_Factory $factory,
+        Components_Output $output
+    ) {
+        $this->_config = $config;
+        $this->_factory = $factory;
+        $this->_output = $output;
+    }
+
+    public function run()
+    {
+        $options = $this->_config->getOptions();
+        $arguments = $this->_config->getArguments();
+
+        $package = $this->_factory->createPackageForDefaultLocation(
+            $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'
+        );
+        $package->generateSnapshot(
+            $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M')
+        );
+    }
+}
index e0f5976..ec6f5ad 100644 (file)
@@ -73,7 +73,6 @@ class Components_Runner_Distribute
     {
         $options = $this->_config->getOptions();
         $arguments = $this->_config->getArguments();
-        $location = realpath($options['distribute']);
 
         $template = null;
         foreach (
@@ -99,13 +98,18 @@ class Components_Runner_Distribute
             );
         }
 
+        $package = $this->_factory->createPackageForDefaultLocation(
+            $arguments[0] . DIRECTORY_SEPARATOR . 'package.xml'
+        );
+        $version = $package->getVersion() . 'dev' . strftime('%Y%m%d%H%M');
+        $package->generateSnapshot($version);
+
         ob_start();
         include $template->getPathname();
         $packaging = ob_get_clean();
 
         file_put_contents(
-            realpath($options['distribute']) . DIRECTORY_SEPARATOR
-            . substr($template->getBasename(), 11),
+            $options['distribute'],
             $packaging
         );
     }
index 2e66768..1d0c509 100644 (file)
@@ -211,7 +211,7 @@ extends PHPUnit_Extensions_Story_TestCase
         case 'calling the package with the distribute option and a path to a Horde framework component':
             $_SERVER['argv'] = array(
                 'horde-components',
-                '--distribute=' . $this->_getTemporaryDirectory(),
+                '--distribute=' . $this->_getTemporaryDirectory() . '/package.spec',
                 dirname(__FILE__) . '/fixture/framework/Install'
             );
             $world['output'] = $this->_callUnstrictComponents();