123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <?php
- require_once 'phing/tasks/system/MatchingTask.php';
- include_once 'phing/types/FileSet.php';
- class PearPackageTask extends MatchingTask {
-
-
- protected $package;
-
- protected $dir;
-
-
- private $packageFile;
-
-
- private $filesets = array();
-
-
- protected $pkg;
-
- private $preparedOptions = array();
-
-
- protected $options = array();
-
-
- protected $mappings = array();
-
- public function init() {
- include_once 'PEAR/PackageFileManager.php';
- if (!class_exists('PEAR_PackageFileManager')) {
- throw new BuildException("You must have installed PEAR_PackageFileManager in order to create a PEAR package.xml file.");
- }
- }
-
-
- protected function setOptions() {
-
-
- $this->populateOptions();
-
-
-
- if (!isset($this->preparedOptions['baseinstalldir'])) {
- $this->preparedOptions['baseinstalldir'] = $this->package;
- }
-
-
- if (!isset($this->preparedOptions['filelistgenerator'])) {
- if (empty($this->filesets)) {
- throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
- }
- $this->preparedOptions['filelistgenerator'] = 'Fileset';
- $this->preparedOptions['usergeneratordir'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pearpackage';
-
- $this->preparedOptions['phing_project'] = $this->project;
- $this->preparedOptions['phing_filesets'] = $this->filesets;
- } elseif ($this->preparedOptions['filelistgeneragor'] != 'Fileset' && !empty($this->filesets)) {
- throw new BuildException("You cannot use <fileset> element if you have specified the \"filelistgenerator\" option.");
- }
-
-
-
-
-
- $e = $this->pkg->setOptions($this->preparedOptions);
-
- if (PEAR::isError($e)) {
- throw new BuildException("Unable to set options.", new Exception($e->getMessage()));
- }
- }
-
-
- private function fixDeps($deps)
- {
- foreach (array_keys($deps) as $dep)
- {
- if (isset($deps[$dep]['optional']) && $deps[$dep]['optional'])
- {
- $deps[$dep]['optional'] = "yes";
- }
- }
-
- return $deps;
- }
-
-
- private function populateOptions() {
-
-
- $this->preparedOptions['package'] = $this->package;
- $this->preparedOptions['packagedirectory'] = $this->dir->getAbsolutePath();
-
- if ($this->packageFile !== null) {
-
- $f = new PhingFile($this->packageFile->getAbsolutePath());
- $this->preparedOptions['packagefile'] = $f->getName();
-
- $this->preparedOptions['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
- $this->log("Creating package file: " . $f->__toString(), Project::MSG_INFO);
- } else {
- $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
- }
-
-
-
-
- foreach($this->options as $opt) {
- $this->preparedOptions[ $opt->getName() ] = $opt->getValue();
- }
-
- foreach($this->mappings as $map) {
- $value = $map->getValue();
-
- if ($map->getName() == 'deps')
- {
- $value = $this->fixDeps($value);
- }
-
- $this->preparedOptions[ $map->getName() ] = $value;
- }
- }
-
-
- public function main() {
-
- if ($this->dir === null) {
- throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
- }
-
- if ($this->package === null) {
- throw new BuildException("You must specify the \"name\" attribute for PEAR package task.");
- }
-
- $this->pkg = new PEAR_PackageFileManager();
-
- $this->setOptions();
-
- $e = $this->pkg->writePackageFile();
- if (PEAR::isError($e)) {
- throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
- }
-
- }
-
-
- public function getFileSets() {
- return $this->filesets;
- }
-
-
-
-
-
- function createFileSet() {
- $num = array_push($this->filesets, new FileSet());
- return $this->filesets[$num-1];
- }
-
-
- public function setPackage($v) {
- $this->package = $v;
- }
-
-
- public function setDir(PhingFile $f) {
- $this->dir = $f;
- }
-
- public function setName($v) {
- $this->package = $v;
- }
-
-
- public function setDestFile(PhingFile $f) {
- $this->packageFile = $f;
- }
-
-
- function createOption() {
- $o = new PearPkgOption();
- $this->options[] = $o;
- return $o;
- }
-
-
- function createMapping() {
- $o = new PearPkgMapping();
- $this->mappings[] = $o;
- return $o;
- }
- }
- class PearPkgOption {
-
- private $name;
- private $value;
-
- public function setName($v) { $this->name = $v; }
- public function getName() { return $this->name; }
-
- public function setValue($v) { $this->value = $v; }
- public function getValue() { return $this->value; }
- public function addText($txt) { $this->value = trim($txt); }
-
- }
- class PearPkgMapping {
- private $name;
- private $elements = array();
-
- public function setName($v) {
- $this->name = $v;
- }
-
- public function getName() {
- return $this->name;
- }
- public function createElement() {
- $e = new PearPkgMappingElement();
- $this->elements[] = $e;
- return $e;
- }
-
- public function getElements() {
- return $this->elements;
- }
-
-
- public function getValue() {
- $value = array();
- foreach($this->getElements() as $el) {
- if ($el->getKey() !== null) {
- $value[ $el->getKey() ] = $el->getValue();
- } else {
- $value[] = $el->getValue();
- }
- }
- return $value;
- }
- }
- class PearPkgMappingElement {
- private $key;
- private $value;
- private $elements = array();
-
- public function setKey($v) {
- $this->key = $v;
- }
-
- public function getKey() {
- return $this->key;
- }
-
- public function setValue($v) {
- $this->value = $v;
- }
-
-
- public function getValue() {
- if (!empty($this->elements)) {
- $value = array();
- foreach($this->elements as $el) {
- if ($el->getKey() !== null) {
- $value[ $el->getKey() ] = $el->getValue();
- } else {
- $value[] = $el->getValue();
- }
- }
- return $value;
- } else {
- return $this->value;
- }
- }
-
-
- public function createElement() {
- $e = new PearPkgMappingElement();
- $this->elements[] = $e;
- return $e;
- }
-
- }
|