/** * Main entry point for d51pearpkg2 task */ public function main() { $package = new PEAR_PackageFileManager2(); $this->_initOptions(); $package->setOptions($this->_options); $package->setPackage($this->_name->__toString()); $package->setSummary($this->_summary->__toString()); $desc = preg_replace("/^({$this->_description->indention_type}{{$this->_description->indentions_to_remove}}|\t)+/m", '', $this->_description->__toString()); $package->setDescription($desc); $package->setChannel($this->_channel->__toString()); $package->setAPIVersion($this->_version->api); $package->setReleaseVersion($this->_version->release); $package->setAPIStability($this->_stability->api); $package->setReleaseStability($this->_stability->release); // TODO: allow different types $package->setPackageType('php'); $package->addRelease(); if ($this->_dependencies->php !== false) { $package->setPhpDep($this->_dependencies->php->minimum_version); } else { $package->setPhpDep(phpversion()); } if ($this->_dependencies->pear !== false) { $package->setPearinstallerDep($this->_dependencies->pear->minimum_version, $this->_dependencies->pear->maximum_version, $this->_dependencies->pear->recommended_version, $this->_dependencies->pear->exclude_version); } else { $package->setPearinstallerDep(PEAR_Config::singleton()->getRegistry()->packageInfo('PEAR', 'version')); } foreach ($this->_maintainers as $maintainer) { $package->addMaintainer($maintainer->role, $maintainer->user, $maintainer->name, $maintainer->email, $maintainer->active); } // handle dependencies if (!empty($this->_dependencies)) { $this->log('adding dependencies'); if (count($this->_dependencies->groups) > 0) { $this->log('found dependency groups'); foreach ($this->_dependencies->groups as $group) { $this->log("adding [{$group->name}] :: [{$group->hint}]"); $package->addDependencyGroup($group->name, $group->hint); foreach ($group->packages as $sub_package) { $package->addGroupPackageDepWithChannel('subpackage', $group->name, $sub_package->name, $sub_package->channel, '0.0.1'); } } } if (count($this->_dependencies->packages) > 0) { $this->log('found dependencies'); foreach ($this->_dependencies->packages as $dependency) { $this->log("adding following dependency: {$dependency->channel}/{$dependency->name}"); $package->addPackageDepWithChannel($dependency->type, $dependency->name, $dependency->channel, $dependency->minimum_version, $dependency->maximum_version, $dependency->recommended_version, $dependency->exclude_version, $dependency->providesextension, $dependency->nodefault); } } if (count($this->_dependencies->extensions) > 0) { $this->log('adding extension dependencies'); foreach ($this->_dependencies->extensions as $extension) { $this->log("adding ext dependency for: {$extension->name}"); $package->addExtensionDep($extension->type, $extension->name, $extension->minimum_version, $extension->maximum_version, $extension->recommended_version, $extension->extension); } } } foreach ($this->_changelogs as $changelog) { $this->log("adding changelog for prior release [{$changelog->version}]"); $changelog->package = $package; $package->setChangelogEntry($changelog->version, $changelog->toArray()); if (is_null($this->_notes) && $package->getVersion() == $changelog->version) { $this->log("no package notes specified, using changelog entry"); $this->_notes = $changelog->contents; } } foreach ($this->_replacements as $replacement) { $replacement->isValid(); $package->addReplacement($replacement->path, $replacement->type, $replacement->from, $replacement->to); } foreach ($this->_globalreplacements as $replacement) { $replacement->isValid(); $this->log("adding global repalcement: {$replacement->from}"); $package->addGlobalReplacement($replacement->type, $replacement->from, $replacement->to); } foreach ($this->_releases as $release) { $this->log('adding new release'); $package->addRelease(); foreach ($release->install as $install) { $this->log("installing [{$install->name}] as [{$install->as}]"); $package->addInstallAs($install->name, $install->as); } } $notes = preg_replace("/^( {4}|\t)+/m", '', $this->_notes->__toString()); $package->setNotes($notes); $package->setLicense($this->_license->license, $this->_license->uri); // handle PostInstallation if (!empty($this->_postinstalls)) { foreach ($this->_postinstalls as $postInstall) { $postInstallScript = $package->initPostinstallScript($postInstall->script); $this->log('adding post installation for script : ' . $postInstall->script); foreach ($postInstall->paramgroups as $paramGroup) { $this->log('adding parameter group' . $paramGroup->name); $instructions = $paramGroup->instructions; if (empty($instructions)) { $instructions = false; } $params = array(); foreach ($paramGroup->params as $param) { $this->log('adding parameter ' . $param->name); $params[] = $postInstallScript->getParam($param->name, $param->prompt, $param->type, $param->default); } if (empty($params)) { $params = false; } $postInstallScript->addParamGroup($paramGroup->name, $params, $instructions); } $e = $package->addPostInstallTask($postInstallScript, $postInstall->script); if (PEAR::isError($e)) { throw new d51PearPkg2Task_Exception('unable to add post install task: ' . $e->getMessage()); } $this->log('Added POSTINSTALL for ' . $postInstall->script); } } $package->generateContents(); $e = $package->writePackageFile(); if (PEAR::isError($e)) { throw new d51PearPkg2Task_Exception('unable to write package.xml file: ' . $e->getMessage()); } }