From bd1983c8c303d1f9a0b27d3c83360ca03c3643c0 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Tue, 26 Oct 2010 10:12:49 +0200
Subject: [PATCH] Use the improved PEAR Error handling.
---
components/lib/Components/Exception.php | 2 +-
components/lib/Components/Exception/Pear.php | 45 +++++++++++++++
components/lib/Components/Pear/Factory.php | 66 ++++++++++------------
components/lib/Components/Pear/InstallLocation.php | 16 +++---
components/lib/Components/Pear/Package.php | 14 ++---
components/package.xml | 10 +++-
6 files changed, 98 insertions(+), 55 deletions(-)
create mode 100644 components/lib/Components/Exception/Pear.php
diff --git a/components/lib/Components/Exception.php b/components/lib/Components/Exception.php
index f0a1043a2..9fa466cfa 100644
--- a/components/lib/Components/Exception.php
+++ b/components/lib/Components/Exception.php
@@ -28,6 +28,6 @@
* @link http://pear.horde.org/index.php?package=Components
*/
class Components_Exception
-extends Exception
+extends Horde_Exception
{
}
diff --git a/components/lib/Components/Exception/Pear.php b/components/lib/Components/Exception/Pear.php
new file mode 100644
index 000000000..800d39a77
--- /dev/null
+++ b/components/lib/Components/Exception/Pear.php
@@ -0,0 +1,45 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+
+/**
+ * This class converts PEAR errors into exceptions for the Components 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 Components
+ * @author Gunnar Wrobel
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Components
+ */
+class Components_Exception_Pear
+extends Horde_Exception_Pear
+{
+ /**
+ * Exception handling.
+ *
+ * @param mixed $result The result to be checked for a PEAR_Error.
+ *
+ * @return mixed Returns the original result if it was no PEAR_Error.
+ *
+ * @throws Horde_Exception_Pear In case the result was a PEAR_Error.
+ */
+ static public function catchError($result)
+ {
+ self::$_class = __CLASS__;
+ return parent::catchError($result);
+ }
+}
diff --git a/components/lib/Components/Pear/Factory.php b/components/lib/Components/Pear/Factory.php
index f0c7e11ea..36cbcca2f 100644
--- a/components/lib/Components/Pear/Factory.php
+++ b/components/lib/Components/Pear/Factory.php
@@ -165,11 +165,9 @@ class Components_Pear_Factory
)
{
$pkg = new PEAR_PackageFile($environment->getPearConfig());
- $package_file = $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL);
- if ($package_file instanceOf PEAR_Error) {
- throw new Components_Exception($package_file->getMessage());
- }
- return $package_file;
+ return Components_Exception_Pear::catchError(
+ $pkg->fromPackageFile($package_xml_path, PEAR_VALIDATE_NORMAL)
+ );
}
/**
@@ -214,12 +212,10 @@ class Components_Pear_Factory
$pkg->setPearinstallerDep('1.9.0');
$pkg->setPackageType('php');
new PEAR_Validate();
- $package_file = $pkg->getDefaultGenerator()
- ->toPackageFile($package_xml_dir, 0);
- if ($package_file instanceOf PEAR_Error) {
- throw new Components_Exception($package_file->getMessage());
- };
- return $package_file;
+ return Components_Exception_Pear::catchError(
+ $pkg->getDefaultGenerator()
+ ->toPackageFile($package_xml_dir, 0)
+ );
}
/**
@@ -246,32 +242,32 @@ class Components_Pear_Factory
);
}
- $package_rw_file = PEAR_PackageFileManager2::importOptions(
- $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' =>
+ return Components_Exception_Pear::catchError(
+ PEAR_PackageFileManager2::importOptions(
+ $package_xml_path,
array(
- 'doc' => 'doc',
- 'example' => 'doc',
- 'js' => 'horde',
- 'lib' => 'php',
- 'migration' => 'data',
- 'script' => 'script',
- 'test' => 'test',
- ),
+ 'packagedirectory' => dirname($package_xml_path),
+ 'filelistgenerator' => 'file',
+ 'clearcontents' => false,
+ 'clearchangelog' => false,
+ 'simpleoutput' => true,
+ 'ignore' => array('*~', 'conf.php', 'CVS/*'),
+ 'include' => '*',
+ 'dir_roles' =>
+ array(
+ 'bin' => 'script',
+ 'script' => 'script',
+ 'doc' => 'doc',
+ 'example' => 'doc',
+ 'js' => 'horde',
+ 'horde' => 'horde',
+ 'lib' => 'php',
+ 'migration' => 'data',
+ 'scripts' => 'data',
+ 'test' => 'test',
+ ),
+ )
)
);
-
- if ($package_rw_file instanceOf PEAR_Error) {
- throw new Components_Exception($package_rw_file->getMessage());
- }
- return $package_rw_file;
}
}
\ No newline at end of file
diff --git a/components/lib/Components/Pear/InstallLocation.php b/components/lib/Components/Pear/InstallLocation.php
index a2e0fe70d..eb7f2fbcf 100644
--- a/components/lib/Components/Pear/InstallLocation.php
+++ b/components/lib/Components/Pear/InstallLocation.php
@@ -201,11 +201,9 @@ class Components_Pear_InstallLocation
if (!file_exists($this->_config_file)) {
$this->createPearConfig();
}
- $config = PEAR_Config::singleton($this->_config_file);
- if ($config instanceOf PEAR_Error) {
- throw new Components_Exception($config->getMessage());
- }
- return $config;
+ return Components_Exception_Pear::catchError(
+ PEAR_Config::singleton($this->_config_file)
+ );
}
/**
@@ -245,7 +243,9 @@ class Components_Pear_InstallLocation
. $channel . '.channel.xml';
if (file_exists($static)) {
ob_start();
- $channel_handler->doAdd('channel-add', array(), array($static));
+ Components_Exception_Pear::catchError(
+ $channel_handler->doAdd('channel-add', array(), array($static))
+ );
$this->_output->pear(ob_get_clean());
} else {
$this->_output->warn(
@@ -255,7 +255,9 @@ class Components_Pear_InstallLocation
)
);
ob_start();
- $channel_handler->doDiscover('channel-discover', array(), array($channel));
+ Components_Exception_Pear::catchError(
+ $channel_handler->doDiscover('channel-discover', array(), array($channel))
+ );
$this->_output->pear(ob_get_clean());
}
$this->_output->ok(
diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php
index 6de68a62d..0eb12c710 100644
--- a/components/lib/Components/Pear/Package.php
+++ b/components/lib/Components/Pear/Package.php
@@ -251,10 +251,6 @@ class Components_Pear_Package
}
}
- /**
- * @todo: Looks like this throws away any tags we have in
- * the content list. Needs to be fixed.
- */
$package->generateContents();
$updated = $package->getContents();
@@ -332,6 +328,7 @@ class Components_Pear_Package
);
break;
case 'js':
+ case 'horde':
$horde_role = true;
case 'locale':
$package->addInstallAs(
@@ -465,12 +462,11 @@ class Components_Pear_Package
$pkg->setDate(date('Y-m-d'));
$pkg->setTime(date('H:i:s'));
ob_start();
- $result = $pkg->getDefaultGenerator()
- ->toTgz(new PEAR_Common());
+ $result = Components_Exception_Pear::catchError(
+ $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/package.xml b/components/package.xml
index 459ec001d..18e9ef553 100644
--- a/components/package.xml
+++ b/components/package.xml
@@ -24,8 +24,8 @@
jan@horde.org
yes
- 2010-10-23
-
+ 2010-10-26
+
0.0.1
0.0.1
@@ -60,6 +60,9 @@
+
+
+
@@ -249,6 +252,7 @@
+
@@ -314,7 +318,7 @@
alpha
alpha
- 2010-10-23
+ 2010-10-26
LGPL
* Initial release
--
2.11.0