Add the continous integration setup module.
authorGunnar Wrobel <p@rdus.de>
Wed, 25 Aug 2010 08:26:42 +0000 (10:26 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 25 Aug 2010 08:26:42 +0000 (10:26 +0200)
framework/Element/lib/Horde/Element/Module/CiSetup.php [new file with mode: 0644]
framework/Element/package.xml

diff --git a/framework/Element/lib/Horde/Element/Module/CiSetup.php b/framework/Element/lib/Horde/Element/Module/CiSetup.php
new file mode 100644 (file)
index 0000000..7860466
--- /dev/null
@@ -0,0 +1,139 @@
+<?php
+/**
+ * Horde_Element_Module_CiSetup:: generates the configuration for Hudson based
+ * continuous integration of a Horde PEAR package.
+ *
+ * PHP version 5
+ *
+ * @category Horde
+ * @package  Element
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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)
+            );
+        }
+    }
+}
index 50b3f02..6d1afd8 100644 (file)
@@ -52,6 +52,7 @@
        <file name="Cli.php" role="php" />
       </dir> <!-- /lib/Horde/Element/Config -->
       <dir name="Module">
+       <file name="CiSetup.php" role="php" />
        <file name="DevPackage.php" role="php" />
        <file name="Installer.php" role="php" />
        <file name="PearPackageXml.php" role="php" />
    <install as="Horde/Element/Module.php" name="lib/Horde/Element/Module.php" />
    <install as="Horde/Element/Modules.php" name="lib/Horde/Element/Modules.php" />
    <install as="Horde/Element/Config/Cli.php" name="lib/Horde/Element/Config/Cli.php" />
+   <install as="Horde/Element/Module/CiSetup.php" name="lib/Horde/Element/Module/CiSetup.php" />
    <install as="Horde/Element/Module/DevPackage.php" name="lib/Horde/Element/Module/DevPackage.php" />
    <install as="Horde/Element/Module/Installer.php" name="lib/Horde/Element/Module/Installer.php" />
    <install as="Horde/Element/Module/PearPackageXml.php" name="lib/Horde/Element/Module/PearPackageXml.php" />