]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Irc/extlib/phergie/PhergiePackageTask.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / Irc / extlib / phergie / PhergiePackageTask.php
1 <?php
2
3 require_once 'phing/tasks/ext/PearPackage2Task.php';
4
5 class PhergiePackageTask extends PearPackage2Task
6 {
7     protected function setOptions()
8     {
9         $this->pkg->addMaintainer('lead', 'team', 'Phergie Development Team', 'team@phergie.org');
10
11         $path = str_replace('_', '/', $this->package) . '.php'; 
12         if (file_exists($path)) {
13             $contents = file_get_contents($path);
14             preg_match_all('#/\*\*(.*)\*/#Ums', $contents, $matches, PREG_SET_ORDER);
15             $doc = $matches[1][1];
16
17             $have_summary = false;
18             $have_description = false;
19             foreach ($this->options as $option) {
20                 switch ($option->getName()) {
21                     case 'summary':
22                         $have_summary = true;
23                         break;
24                     case 'description':
25                         $have_descripion = true;
26                         break;
27                 }
28             }
29
30             if (!$have_summary || !$have_description) {
31                 $description = substr($doc, 0, strpos($doc, '@'));
32                 $description = trim(preg_replace(array('#^[\h*]*|[\h*]*$#m', '#[\h]+#m'), array('', ' '), $description));
33                 $split = preg_split('/\v\v+/', $description);
34                 $summary = trim(array_shift($split));
35                 if (!$have_summary) {
36                     $this->pkg->setSummary(htmlentities($summary, ENT_QUOTES));
37                 }
38                 if (!$have_description) {
39                     $this->pkg->setDescription(htmlentities($description, ENT_QUOTES));
40                 }
41             }
42
43             $doc = preg_split('/\v+/', $doc);
44             $doc = preg_grep('/@uses/', $doc);
45             $doc = preg_replace('/\s*\* @uses\s+|\s+$/', '', $doc);
46             foreach ($doc as $line) {
47                 if (strpos($line, 'extension') === 0) {
48                     $line = explode(' ', $line);
49                     $name = $line[1];
50                     $optional = 'required';
51                     if (isset($line[2])) {
52                         $optional = $line[2];
53                     }
54                     $this->pkg->addExtensionDep(
55                         $optional,
56                         $name
57                     );
58                 } else {
59                     $line = explode(' ', $line);
60                     $name = $line[0];
61                     $channel = $line[1];
62                     $optional = 'required';
63                     if (isset($line[2])) {
64                         $optional = $line[2];
65                     }
66                     $this->pkg->addPackageDepWithChannel(
67                         $optional,
68                         $name,
69                         $channel
70                     );
71                 }
72             }
73         }
74
75         $newmap = array();
76         foreach ($this->mappings as $key => $map) {
77             switch ($map->getName()) {
78                 case 'releases':
79                     $releases = $map->getValue();
80                     foreach ($releases as $release) {
81                         $this->pkg->addRelease();
82                         if (isset($release['installconditions'])) {
83                             if (isset($release['installconditions']['os'])) {
84                                 $this->pkg->setOsInstallCondition($release['installconditions']['os']);
85                             }
86                         }
87                         if (isset($release['filelist'])) {
88                             if (isset($release['filelist']['install'])) {
89                                 foreach ($release['filelist']['install'] as $file => $as) {
90                                     $this->pkg->addInstallAs($file, $as);
91                                 }
92                             }
93                             if (isset($release['filelist']['ignore'])) {
94                                 foreach ($release['filelist']['ignore'] as $file) {
95                                     $this->pkg->addIgnoreToRelease($file);
96                                 }
97                             }
98                         }
99                     }
100                     break;
101
102                 default:
103                     $newmap[] = $map;
104             }
105         }
106         $this->mappings = $newmap;
107
108         parent::setOptions();
109     }
110 }