| 19 | | protected $package = null; // package name |
|---|
| 20 | | /** |
|---|
| 21 | | * The PEAR name of the package. |
|---|
| 22 | | */ |
|---|
| 23 | | protected $package_name; |
|---|
| 24 | | protected $channel = "pear.midcom-project.org"; |
|---|
| 25 | | |
|---|
| 26 | | function __construct() |
|---|
| 27 | | { |
|---|
| 28 | | |
|---|
| 29 | | } |
|---|
| 30 | | |
|---|
| 31 | | protected $returnProperty; // name of property to set to return value |
|---|
| 32 | | |
|---|
| 33 | | /** |
|---|
| 34 | | * The root path to where the module is stored. |
|---|
| 35 | | */ |
|---|
| 36 | | private $path = null; |
|---|
| 37 | | /** |
|---|
| 38 | | * The target directory where the packagefile should be saved. |
|---|
| 39 | | */ |
|---|
| 40 | | protected $target_dir = null; |
|---|
| 41 | | /** |
|---|
| 42 | | * The setter for the attribute "message" |
|---|
| 43 | | */ |
|---|
| 44 | | public function setTarget_dir($str) |
|---|
| 45 | | { |
|---|
| 46 | | $this->target_dir = $str; |
|---|
| 47 | | } |
|---|
| 48 | | public function setPath($str) |
|---|
| 49 | | { |
|---|
| 50 | | $this->path = $str; |
|---|
| 51 | | } |
|---|
| 52 | | public function setPackage($str) |
|---|
| 53 | | { |
|---|
| 54 | | $this->package = $str; |
|---|
| 55 | | } |
|---|
| 56 | | public function setChannel($str) |
|---|
| 57 | | { |
|---|
| 58 | | $this->channel = $str; |
|---|
| 59 | | } |
|---|
| 60 | | /** Sets property name to set with return value of function or expression.*/ |
|---|
| 61 | | public function setReturnProperty($r) |
|---|
| 62 | | { |
|---|
| 63 | | $this->returnProperty = $r; |
|---|
| 64 | | } |
|---|
| 65 | | |
|---|
| 66 | | protected $copyfiles = array (); |
|---|
| 67 | | |
|---|
| 68 | | /** |
|---|
| 69 | | * The init method: Do init steps. |
|---|
| 70 | | */ |
|---|
| 71 | | public function init() |
|---|
| 72 | | { |
|---|
| 73 | | // nothing to do here |
|---|
| 74 | | } |
|---|
| 75 | | |
|---|
| 76 | | /** |
|---|
| 77 | | * The main entry point method. |
|---|
| 78 | | */ |
|---|
| 79 | | public function main() |
|---|
| 80 | | { |
|---|
| 81 | | $this->package_name = str_replace('.', '_', $this->package); |
|---|
| 82 | | $this->package_name = str_replace('-', '_', $this->package); |
|---|
| 83 | | $this->package_name = str_replace('/', '', $this->package_name); |
|---|
| 84 | | |
|---|
| 85 | | echo "Using package name : {$this->package_name} \n"; |
|---|
| 86 | | // todo add more validation |
|---|
| 87 | | if ($this->target_dir === null |
|---|
| 88 | | || !is_dir($this->target_dir) |
|---|
| 89 | | ) { |
|---|
| 90 | | throw new Exception("You must set the target attribute to a writable directory (current: {$this->target_dir})!\n"); |
|---|
| 91 | | } |
|---|
| 92 | | // read the manifest |
|---|
| 93 | | //$this->readManifest(); |
|---|
| 94 | | $packageInfo = $this->getComponentInfo(); |
|---|
| 95 | | // build the filelist |
|---|
| 96 | | $filelist = $this->getFileList($packageInfo); |
|---|
| 97 | | // create the xml for package.xml |
|---|
| 98 | | $xml = $this->createXml($packageInfo, $filelist); |
|---|
| 99 | | // save package.xml. |
|---|
| 100 | | file_put_contents($this->path . "/" . $this->package . "/package.xml", $xml); |
|---|
| 101 | | |
|---|
| 102 | | $this->execPearPackage(); |
|---|
| 103 | | // I planned to use the tar task to create the package, then this would be needed |
|---|
| 104 | | $name = $this->package_name . "-" . $packageInfo['version']; |
|---|
| 105 | | $this->project->setProperty($this->returnProperty, $name); |
|---|
| 106 | | // should I delete package.xml? Hmm, todo I think. |
|---|
| 107 | | |
|---|
| 108 | | } |
|---|
| 109 | | |
|---|
| 110 | | protected function execPearPackage() |
|---|
| 111 | | { |
|---|
| 112 | | $curr_dir = getcwd(); |
|---|
| 113 | | chdir($this->target_dir); |
|---|
| 114 | | $pear = exec('which pear'); |
|---|
| 115 | | if (!is_executable($pear)) |
|---|
| 116 | | { |
|---|
| 117 | | die("Pear executable $pear is not executable!"); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | $ret = exec("$pear package-validate {$this->path}/{$this->package}/package.xml", $out, $status); |
|---|
| 121 | | $out = null; |
|---|
| 122 | | if ($status == 0) |
|---|
| 123 | | { |
|---|
| 124 | | $ret = exec("$pear package {$this->path}/{$this->package}/package.xml", $out, $status); |
|---|
| 125 | | foreach ($out as $line) { |
|---|
| 126 | | if (stripos($line, 'error')) { |
|---|
| 127 | | echo $line . "\n"; |
|---|
| 128 | | } |
|---|
| 129 | | if (stripos($line, 'warning')) { |
|---|
| 130 | | echo $line . "\n"; |
|---|
| 131 | | } |
|---|
| 132 | | |
|---|
| 133 | | } |
|---|
| 134 | | |
|---|
| 135 | | } |
|---|
| 136 | | else |
|---|
| 137 | | { |
|---|
| 138 | | chdir($curr_dir); |
|---|
| 139 | | echo implode($out); |
|---|
| 140 | | die ("Packagefile did not validate! Exiting."); |
|---|
| 141 | | } |
|---|
| 142 | | chdir($curr_dir); |
|---|
| 143 | | |
|---|
| 144 | | } |
|---|
| 145 | | |
|---|
| 146 | | protected function getFileList($packageInfo) |
|---|
| 147 | | { |
|---|
| 148 | | |
|---|
| 149 | | $filelist_config = array ( |
|---|
| 150 | | 'filelist' => '', |
|---|
| 151 | | 'package' => $packageInfo, |
|---|
| 152 | | 'component' => $this->package_name, |
|---|
| 153 | | 'path' => realpath($this->path . "/" . $this->package), |
|---|
| 154 | | 'prefix' => ' ', |
|---|
| 155 | | 'baseinstalldir' => "/{$this->package}", // |
|---|
| 156 | | 'static' => true, |
|---|
| 157 | | 'install-as-prefix' => '' |
|---|
| 158 | | |
|---|
| 159 | | ); |
|---|
| 160 | | $filelist = $this->directory_list_contents($filelist_config); |
|---|
| 161 | | return $filelist; |
|---|
| 162 | | } |
|---|
| 163 | | |
|---|
| 164 | | /** |
|---|
| 165 | | * Generate the filelist |
|---|
| 166 | | * @param array $config File listing configuration |
|---|
| 167 | | * @return string File XML list |
|---|
| 168 | | */ |
|---|
| 169 | | function directory_list_contents($config, $directory_name_override = null) |
|---|
| 170 | | { |
|---|
| 171 | | |
|---|
| 172 | | $directory = dir($config['path']); |
|---|
| 173 | | |
|---|
| 174 | | if ($directory_name_override) |
|---|
| 175 | | { |
|---|
| 176 | | $dir_name = $directory_name_override; |
|---|
| 177 | | } else |
|---|
| 178 | | { |
|---|
| 179 | | $dir_name = basename($config['path']); |
|---|
| 180 | | } |
|---|
| 181 | | |
|---|
| 182 | | // Add more to the prefix |
|---|
| 183 | | $config['prefix'] .= ' '; |
|---|
| 184 | | $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; |
|---|
| 185 | | |
|---|
| 186 | | |
|---|
| 187 | | // List contents |
|---|
| 188 | | while (false !== ($entry = $directory->read())) |
|---|
| 189 | | { |
|---|
| 190 | | if (substr($entry, 0, 1) == '.') |
|---|
| 191 | | { |
|---|
| 192 | | // Ignore dotfiles |
|---|
| 193 | | continue; |
|---|
| 194 | | } |
|---|
| 195 | | if ($entry == 'CVS' || $entry == '.svn') |
|---|
| 196 | | { |
|---|
| 197 | | // Ignore CVS directories |
|---|
| 198 | | continue; |
|---|
| 199 | | } |
|---|
| 200 | | if ($entry == 'package.xml') |
|---|
| 201 | | { |
|---|
| 202 | | // Ignore the package file itself |
|---|
| 203 | | continue; |
|---|
| 204 | | } |
|---|
| 205 | | |
|---|
| 206 | | // Handle packaging file roles |
|---|
| 207 | | elseif ($dir_name == 'config' && $entry == 'mgdschema.xml') |
|---|
| 208 | | { |
|---|
| 209 | | // MgdSchemas shipped by components are placed in config/mgdschema.xml |
|---|
| 210 | | $role = 'mgdschema'; |
|---|
| 211 | | } |
|---|
| 212 | | elseif ($dir_name == 'config' && $entry == 'mgdschema.sql') |
|---|
| 213 | | { |
|---|
| 214 | | // SQL files shipped by components are placed in config/mgdschema.xml |
|---|
| 215 | | // These will be installed via the Datagard database update command |
|---|
| 216 | | $role = 'midgardsql'; |
|---|
| 217 | | } else |
|---|
| 218 | | { |
|---|
| 219 | | // All files are by default PHP |
|---|
| 220 | | $role = 'php'; |
|---|
| 221 | | |
|---|
| 222 | | // Check for potential other file extensions |
|---|
| 223 | | $path_parts = pathinfo($entry); |
|---|
| 224 | | switch ($path_parts['extension']) |
|---|
| 225 | | { |
|---|
| 226 | | // binary formats |
|---|
| 227 | | case 'jpg' : |
|---|
| 228 | | case 'gif' : |
|---|
| 229 | | case 'png' : |
|---|
| 230 | | case 'zip' : |
|---|
| 231 | | case 'tgz' : |
|---|
| 232 | | $role = 'data'; |
|---|
| 233 | | break; |
|---|
| 234 | | // Web formats *not* in static directory |
|---|
| 235 | | case 'html' : |
|---|
| 236 | | case 'js' : |
|---|
| 237 | | case 'htc' : |
|---|
| 238 | | case 'css' : |
|---|
| 239 | | $role = 'data'; |
|---|
| 240 | | break; |
|---|
| 241 | | } |
|---|
| 242 | | } |
|---|
| 243 | | |
|---|
| 244 | | if (is_dir("{$config['path']}/{$entry}")) |
|---|
| 245 | | { |
|---|
| 246 | | |
|---|
| 247 | | // List the subdirectory |
|---|
| 248 | | $subconfig = $config; |
|---|
| 249 | | $subconfig['path'] = "{$config['path']}/{$entry}"; |
|---|
| 250 | | $subconfig['install-as-prefix'] .= "{$entry}/"; |
|---|
| 251 | | $config['filelist'] = $this->directory_list_contents($subconfig); |
|---|
| 252 | | } else |
|---|
| 253 | | { |
|---|
| 254 | | // List the files |
|---|
| 255 | | if ($config['static']) |
|---|
| 256 | | { |
|---|
| 257 | | $role = 'web'; |
|---|
| 258 | | $config['filelist'] .= "{$config['prefix']} <file name=\"{$entry}\" role=\"{$role}\" baseinstalldir=\"{$config['baseinstalldir']}\" " . |
|---|
| 259 | | " install-as=\"{$config['install-as-prefix']}{$entry}\" />\n"; |
|---|
| 260 | | } else |
|---|
| 261 | | { |
|---|
| 262 | | $config['filelist'] .= "{$config['prefix']} <file baseinstalldir=\"{$config['baseinstalldir']}\" name=\"{$entry}\" role=\"{$role}\" />\n"; |
|---|
| 263 | | } |
|---|
| 264 | | } |
|---|
| 265 | | //$this->copyfiles[] = $config['path'] . "/" . $entry; |
|---|
| 266 | | } |
|---|
| 267 | | |
|---|
| 268 | | $directory->close(); |
|---|
| 269 | | $config['filelist'] .= "{$config['prefix']}</dir>\n"; |
|---|
| 270 | | return $config['filelist']; |
|---|
| 271 | | } |
|---|
| 272 | | |
|---|
| 273 | | public function getComponentInfo() |
|---|
| 274 | | { |
|---|
| 275 | | $component = array (); |
|---|
| 276 | | $component['baseinstalldir'] = "/"; |
|---|
| 277 | | |
|---|
| 278 | | // PEAR packages can't have dots in their names |
|---|
| 279 | | $package['name'] = $this->package_name; |
|---|
| 280 | | |
|---|
| 281 | | |
|---|
| 282 | | $package['license'] = 'LGPL'; |
|---|
| 283 | | |
|---|
| 284 | | |
|---|
| 285 | | // Version string is a string |
|---|
| 286 | | $package['version'] = '1.0.0'; |
|---|
| 287 | | |
|---|
| 288 | | // Release date is today |
|---|
| 289 | | // TODO: Get latest modification date from CHANGES |
|---|
| 290 | | $package['date'] = date('Y-m-d'); |
|---|
| 291 | | $package['time'] = date('H:i:s'); |
|---|
| 292 | | |
|---|
| 293 | | $package['state'] = 'stable'; |
|---|
| 294 | | |
|---|
| 295 | | // Load the summary |
|---|
| 296 | | $package['summary'] = "Static icons"; |
|---|
| 297 | | |
|---|
| 298 | | $package['description'] = "MidCOM Icons."; |
|---|
| 299 | | |
|---|
| 300 | | |
|---|
| 301 | | // Generate the maintainer list |
|---|
| 302 | | $maintainers = array( |
|---|
| 303 | | 'tarjei' => array('role' => 'lead', 'name' => "Tarjei Huse" , 'active' => 'yes'), |
|---|
| 304 | | 'torben' => array('role' => 'lead', 'name' => "Torben Nehmer" , 'active' => 'no') |
|---|
| 305 | | ); |
|---|
| 306 | | $package['maintainers'] = ""; |
|---|
| 307 | | foreach ($maintainers as $username => $person) |
|---|
| 308 | | { |
|---|
| 309 | | if (!is_array($person)) |
|---|
| 310 | | { |
|---|
| 311 | | $person = Array (); |
|---|
| 312 | | } |
|---|
| 313 | | |
|---|
| 314 | | if (!array_key_exists('name', $person)) |
|---|
| 315 | | { |
|---|
| 316 | | // Maintainer must have a name |
|---|
| 317 | | continue; |
|---|
| 318 | | } |
|---|
| 319 | | |
|---|
| 320 | | if (!array_key_exists('role', $person)) |
|---|
| 321 | | { |
|---|
| 322 | | $person['role'] = 'developer'; |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | if (!array_key_exists('active', $person)) |
|---|
| 326 | | { |
|---|
| 327 | | $person['active'] = 'yes'; |
|---|
| 328 | | } |
|---|
| 329 | | |
|---|
| 330 | | $package['maintainers'] .= " |
|---|
| 331 | | <{$person['role']}> |
|---|
| 332 | | <name>{$person['name']}</name> |
|---|
| 333 | | <user>{$username}</user> |
|---|
| 334 | | <email>{$person['email']}</email> |
|---|
| 335 | | <active>{$person['active']}</active> |
|---|
| 336 | | </{$person['role']}> |
|---|
| 337 | | "; |
|---|
| 338 | | } |
|---|
| 339 | | |
|---|
| 340 | | |
|---|
| 341 | | // Generate dependencies, if any |
|---|
| 342 | | $package['dependencies'] = ''; |
|---|
| 343 | | return $package; |
|---|
| 344 | | } |
|---|
| 345 | | |
|---|
| 346 | | protected function createXml($package, $filelist) |
|---|
| 347 | | { |
|---|
| 348 | | |
|---|
| 349 | | // Create package XML |
|---|
| 350 | | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
|---|
| 351 | | <package packagerversion=\"1.4.5\" version=\"2.0\" xmlns=\"http://pear.php.net/dtd/package-2.0\" xmlns:tasks=\"http://pear.php.net/dtd/tasks-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://pear.php.net/dtd/tasks-1.0 |
|---|
| 352 | | http://pear.php.net/dtd/tasks-1.0.xsd |
|---|
| 353 | | http://pear.php.net/dtd/package-2.0 |
|---|
| 354 | | http://pear.php.net/dtd/package-2.0.xsd\"> |
|---|
| 355 | | <name>{$package['name']}</name> |
|---|
| 356 | | <channel>{$this->channel}</channel> |
|---|
| 357 | | <summary> |
|---|
| 358 | | {$package['summary']} |
|---|
| 359 | | </summary> |
|---|
| 360 | | <description> |
|---|
| 361 | | {$package['description']} |
|---|
| 362 | | </description> |
|---|
| 363 | | {$package['maintainers']} |
|---|
| 364 | | <date>{$package['date']}</date> |
|---|
| 365 | | <time>{$package['time']}</time> |
|---|
| 366 | | <version> |
|---|
| 367 | | <release>{$package['version']}</release> |
|---|
| 368 | | <api>{$package['version']}</api> |
|---|
| 369 | | </version> |
|---|
| 370 | | <stability> |
|---|
| 371 | | <release>{$package['state']}</release> |
|---|
| 372 | | <api>{$package['state']}</api> |
|---|
| 373 | | </stability> |
|---|
| 374 | | <license>{$package['license']}</license> |
|---|
| 375 | | <notes>{$package['version']} {$package['state']}</notes> |
|---|
| 376 | | <contents>\n{$filelist} </contents> |
|---|
| 377 | | <dependencies> |
|---|
| 378 | | <required> |
|---|
| 379 | | <php> |
|---|
| 380 | | <min>4.3.0</min> |
|---|
| 381 | | </php> |
|---|
| 382 | | <pearinstaller> |
|---|
| 383 | | <min>1.4.0</min> |
|---|
| 384 | | </pearinstaller> |
|---|
| 385 | | {$package['dependencies']} </required> |
|---|
| 386 | | </dependencies> |
|---|
| 387 | | <phprelease /> |
|---|
| 388 | | </package> |
|---|
| 389 | | "; |
|---|
| 390 | | |
|---|
| 391 | | } |
|---|
| | 19 | protected $package = null; // package name |
|---|
| | 20 | /** |
|---|
| | 21 | * The PEAR name of the package. |
|---|
| | 22 | */ |
|---|
| | 23 | protected $package_name; |
|---|
| | 24 | protected $channel = "pear.midcom-project.org"; |
|---|
| | 25 | |
|---|
| | 26 | function __construct() |
|---|
| | 27 | { |
|---|
| | 28 | |
|---|
| | 29 | } |
|---|
| | 30 | |
|---|
| | 31 | protected $returnProperty; // name of property to set to return value |
|---|
| | 32 | |
|---|
| | 33 | /** |
|---|
| | 34 | * The root path to where the module is stored. |
|---|
| | 35 | */ |
|---|
| | 36 | private $path = null; |
|---|
| | 37 | /** |
|---|
| | 38 | * The target directory where the packagefile should be saved. |
|---|
| | 39 | */ |
|---|
| | 40 | protected $target_dir = null; |
|---|
| | 41 | /** |
|---|
| | 42 | * The setter for the attribute "message" |
|---|
| | 43 | */ |
|---|
| | 44 | public function setTarget_dir($str) |
|---|
| | 45 | { |
|---|
| | 46 | $this->target_dir = $str; |
|---|
| | 47 | } |
|---|
| | 48 | public function setPath($str) |
|---|
| | 49 | { |
|---|
| | 50 | $this->path = $str; |
|---|
| | 51 | } |
|---|
| | 52 | public function setPackage($str) |
|---|
| | 53 | { |
|---|
| | 54 | $this->package = $str; |
|---|
| | 55 | } |
|---|
| | 56 | public function setChannel($str) |
|---|
| | 57 | { |
|---|
| | 58 | $this->channel = $str; |
|---|
| | 59 | } |
|---|
| | 60 | /** Sets property name to set with return value of function or expression.*/ |
|---|
| | 61 | public function setReturnProperty($r) |
|---|
| | 62 | { |
|---|
| | 63 | $this->returnProperty = $r; |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | protected $copyfiles = array (); |
|---|
| | 67 | |
|---|
| | 68 | /** |
|---|
| | 69 | * The init method: Do init steps. |
|---|
| | 70 | */ |
|---|
| | 71 | public function init() |
|---|
| | 72 | { |
|---|
| | 73 | // nothing to do here |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | /** |
|---|
| | 77 | * The main entry point method. |
|---|
| | 78 | */ |
|---|
| | 79 | public function main() |
|---|
| | 80 | { |
|---|
| | 81 | $this->package_name = str_replace('.', '_', $this->package); |
|---|
| | 82 | $this->package_name = str_replace('-', '_', $this->package); |
|---|
| | 83 | $this->package_name = str_replace('/', '', $this->package_name); |
|---|
| | 84 | |
|---|
| | 85 | echo "Using package name : {$this->package_name} \n"; |
|---|
| | 86 | // todo add more validation |
|---|
| | 87 | if ($this->target_dir === null |
|---|
| | 88 | || !is_dir($this->target_dir) |
|---|
| | 89 | ) { |
|---|
| | 90 | throw new Exception("You must set the target attribute to a writable directory (current: {$this->target_dir})!\n"); |
|---|
| | 91 | } |
|---|
| | 92 | // read the manifest |
|---|
| | 93 | //$this->readManifest(); |
|---|
| | 94 | $packageInfo = $this->getComponentInfo(); |
|---|
| | 95 | // build the filelist |
|---|
| | 96 | $filelist = $this->getFileList($packageInfo); |
|---|
| | 97 | // create the xml for package.xml |
|---|
| | 98 | $xml = $this->createXml($packageInfo, $filelist); |
|---|
| | 99 | // save package.xml. |
|---|
| | 100 | file_put_contents($this->path . "/" . $this->package . "/package.xml", $xml); |
|---|
| | 101 | |
|---|
| | 102 | $this->execPearPackage(); |
|---|
| | 103 | // I planned to use the tar task to create the package, then this would be needed |
|---|
| | 104 | $name = $this->package_name . "-" . $packageInfo['version']; |
|---|
| | 105 | $this->project->setProperty($this->returnProperty, $name); |
|---|
| | 106 | // should I delete package.xml? Hmm, todo I think. |
|---|
| | 107 | |
|---|
| | 108 | } |
|---|
| | 109 | |
|---|
| | 110 | protected function execPearPackage() |
|---|
| | 111 | { |
|---|
| | 112 | $curr_dir = getcwd(); |
|---|
| | 113 | chdir($this->target_dir); |
|---|
| | 114 | $pear = exec('which pear'); |
|---|
| | 115 | if (!is_executable($pear)) |
|---|
| | 116 | { |
|---|
| | 117 | die("Pear executable $pear is not executable!"); |
|---|
| | 118 | } |
|---|
| | 119 | |
|---|
| | 120 | $ret = exec("$pear package-validate {$this->path}/{$this->package}/package.xml", $out, $status); |
|---|
| | 121 | $out = null; |
|---|
| | 122 | if ($status == 0) |
|---|
| | 123 | { |
|---|
| | 124 | $ret = exec("$pear package {$this->path}/{$this->package}/package.xml", $out, $status); |
|---|
| | 125 | foreach ($out as $line) { |
|---|
| | 126 | if (stripos($line, 'error')) { |
|---|
| | 127 | echo $line . "\n"; |
|---|
| | 128 | } |
|---|
| | 129 | if (stripos($line, 'warning')) { |
|---|
| | 130 | echo $line . "\n"; |
|---|
| | 131 | } |
|---|
| | 132 | |
|---|
| | 133 | } |
|---|
| | 134 | |
|---|
| | 135 | } |
|---|
| | 136 | else |
|---|
| | 137 | { |
|---|
| | 138 | chdir($curr_dir); |
|---|
| | 139 | echo implode($out); |
|---|
| | 140 | die ("Packagefile did not validate! Exiting."); |
|---|
| | 141 | } |
|---|
| | 142 | chdir($curr_dir); |
|---|
| | 143 | |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | protected function getFileList($packageInfo) |
|---|
| | 147 | { |
|---|
| | 148 | |
|---|
| | 149 | $filelist_config = array ( |
|---|
| | 150 | 'filelist' => '', |
|---|
| | 151 | 'package' => $packageInfo, |
|---|
| | 152 | 'component' => $this->package_name, |
|---|
| | 153 | 'path' => realpath($this->path . "/" . $this->package), |
|---|
| | 154 | 'prefix' => ' ', |
|---|
| | 155 | 'baseinstalldir' => "/{$this->package}", // |
|---|
| | 156 | 'static' => true, |
|---|
| | 157 | 'install-as-prefix' => '' |
|---|
| | 158 | |
|---|
| | 159 | ); |
|---|
| | 160 | $filelist = $this->directory_list_contents($filelist_config); |
|---|
| | 161 | return $filelist; |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | /** |
|---|
| | 165 | * Generate the filelist |
|---|
| | 166 | * @param array $config File listing configuration |
|---|
| | 167 | * @return string File XML list |
|---|
| | 168 | */ |
|---|
| | 169 | function directory_list_contents($config, $directory_name_override = null) |
|---|
| | 170 | { |
|---|
| | 171 | |
|---|
| | 172 | $directory = dir($config['path']); |
|---|
| | 173 | |
|---|
| | 174 | if ($directory_name_override) |
|---|
| | 175 | { |
|---|
| | 176 | $dir_name = $directory_name_override; |
|---|
| | 177 | } else |
|---|
| | 178 | { |
|---|
| | 179 | $dir_name = basename($config['path']); |
|---|
| | 180 | } |
|---|
| | 181 | |
|---|
| | 182 | // Add more to the prefix |
|---|
| | 183 | $config['prefix'] .= ' '; |
|---|
| | 184 | $config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; |
|---|
| | 185 | |
|---|
| | 186 | |
|---|
| | 187 | // List contents |
|---|
| | 188 | while (false !== ($entry = $directory->read())) |
|---|
| | 189 | { |
|---|
| | 190 | if (substr($entry, 0, 1) == '.') |
|---|
| | 191 | { |
|---|
| | 192 | // Ignore dotfiles |
|---|
| | 193 | continue; |
|---|
| | 194 | } |
|---|
| | 195 | if ($entry == 'CVS' || $entry == '.svn') |
|---|
| | 196 | { |
|---|
| | 197 | // Ignore CVS directories |
|---|
| | 198 | continue; |
|---|
| | 199 | } |
|---|
| | 200 | if ($entry == 'package.xml') |
|---|
| | 201 | { |
|---|
| | 202 | // Ignore the package file itself |
|---|
| | 203 | continue; |
|---|
| | 204 | } |
|---|
| | 205 | |
|---|
| | 206 | // Handle packaging file roles |
|---|
| | 207 | elseif ($dir_name == 'config' && $entry == 'mgdschema.xml') |
|---|
| | 208 | { |
|---|
| | 209 | // MgdSchemas shipped by components are placed in config/mgdschema.xml |
|---|
| | 210 | $role = 'mgdschema'; |
|---|
| | 211 | } |
|---|
| | 212 | elseif ($dir_name == 'config' && $entry == 'mgdschema.sql') |
|---|
| | 213 | { |
|---|
| | 214 | // SQL files shipped by components are placed in config/mgdschema.xml |
|---|
| | 215 | // These will be installed via the Datagard database update command |
|---|
| | 216 | $role = 'midgardsql'; |
|---|
| | 217 | } else |
|---|
| | 218 | { |
|---|
| | 219 | // All files are by default PHP |
|---|
| | 220 | $role = 'php'; |
|---|
| | 221 | |
|---|
| | 222 | // Check for potential other file extensions |
|---|
| | 223 | $path_parts = pathinfo($entry); |
|---|
| | 224 | switch ($path_parts['extension']) |
|---|
| | 225 | { |
|---|
| | 226 | // binary formats |
|---|
| | 227 | case 'jpg' : |
|---|
| | 228 | case 'gif' : |
|---|
| | 229 | case 'png' : |
|---|
| | 230 | case 'zip' : |
|---|
| | 231 | case 'tgz' : |
|---|
| | 232 | $role = 'data'; |
|---|
| | 233 | break; |
|---|
| | 234 | // Web formats *not* in static directory |
|---|
| | 235 | case 'html' : |
|---|
| | 236 | case 'js' : |
|---|
| | 237 | case 'htc' : |
|---|
| | 238 | case 'css' : |
|---|
| | 239 | $role = 'data'; |
|---|
| | 240 | break; |
|---|
| | 241 | } |
|---|
| | 242 | } |
|---|
| | 243 | |
|---|
| | 244 | if (is_dir("{$config['path']}/{$entry}")) |
|---|
| | 245 | { |
|---|
| | 246 | |
|---|
| | 247 | // List the subdirectory |
|---|
| | 248 | $subconfig = $config; |
|---|
| | 249 | $subconfig['path'] = "{$config['path']}/{$entry}"; |
|---|
| | 250 | $subconfig['install-as-prefix'] .= "{$entry}/"; |
|---|
| | 251 | $config['filelist'] = $this->directory_list_contents($subconfig); |
|---|
| | 252 | } else |
|---|
| | 253 | { |
|---|
| | 254 | // List the files |
|---|
| | 255 | if ($config['static']) |
|---|
| | 256 | { |
|---|
| | 257 | $role = 'web'; |
|---|
| | 258 | $config['filelist'] .= "{$config['prefix']} <file name=\"{$entry}\" role=\"{$role}\" baseinstalldir=\"{$config['baseinstalldir']}\" " . |
|---|
| | 259 | " install-as=\"{$config['install-as-prefix']}{$entry}\" />\n"; |
|---|
| | 260 | } else |
|---|
| | 261 | { |
|---|
| | 262 | $config['filelist'] .= "{$config['prefix']} <file baseinstalldir=\"{$config['baseinstalldir']}\" name=\"{$entry}\" role=\"{$role}\" />\n"; |
|---|
| | 263 | } |
|---|
| | 264 | } |
|---|
| | 265 | //$this->copyfiles[] = $config['path'] . "/" . $entry; |
|---|
| | 266 | } |
|---|
| | 267 | |
|---|
| | 268 | $directory->close(); |
|---|
| | 269 | $config['filelist'] .= "{$config['prefix']}</dir>\n"; |
|---|
| | 270 | return $config['filelist']; |
|---|
| | 271 | } |
|---|
| | 272 | |
|---|
| | 273 | public function getComponentInfo() |
|---|
| | 274 | { |
|---|
| | 275 | $component = array (); |
|---|
| | 276 | $component['baseinstalldir'] = "/"; |
|---|
| | 277 | |
|---|
| | 278 | // PEAR packages can't have dots in their names |
|---|
| | 279 | $package['name'] = $this->package_name; |
|---|
| | 280 | |
|---|
| | 281 | |
|---|
| | 282 | $package['license'] = 'LGPL'; |
|---|
| | 283 | |
|---|
| | 284 | |
|---|
| | 285 | // Version string is a string |
|---|
| | 286 | $package['version'] = '1.0.0'; |
|---|
| | 287 | |
|---|
| | 288 | // Release date is today |
|---|
| | 289 | // TODO: Get latest modification date from CHANGES |
|---|
| | 290 | $package['date'] = date('Y-m-d'); |
|---|
| | 291 | $package['time'] = date('H:i:s'); |
|---|
| | 292 | |
|---|
| | 293 | $package['state'] = 'stable'; |
|---|
| | 294 | |
|---|
| | 295 | // Load the summary |
|---|
| | 296 | $package['summary'] = "Static icons"; |
|---|
| | 297 | |
|---|
| | 298 | $package['description'] = "MidCOM Icons."; |
|---|
| | 299 | |
|---|
| | 300 | |
|---|
| | 301 | // Generate the maintainer list |
|---|
| | 302 | $maintainers = array( |
|---|
| | 303 | 'tarjei' => array('role' => 'lead', 'name' => "Tarjei Huse" , 'active' => 'yes'), |
|---|
| | 304 | 'torben' => array('role' => 'lead', 'name' => "Torben Nehmer" , 'active' => 'no') |
|---|
| | 305 | ); |
|---|
| | 306 | $package['maintainers'] = ""; |
|---|
| | 307 | foreach ($maintainers as $username => $person) |
|---|
| | 308 | { |
|---|
| | 309 | if (!is_array($person)) |
|---|
| | 310 | { |
|---|
| | 311 | $person = Array (); |
|---|
| | 312 | } |
|---|
| | 313 | |
|---|
| | 314 | if (!array_key_exists('name', $person)) |
|---|
| | 315 | { |
|---|
| | 316 | // Maintainer must have a name |
|---|
| | 317 | continue; |
|---|
| | 318 | } |
|---|
| | 319 | |
|---|
| | 320 | if (!array_key_exists('role', $person)) |
|---|
| | 321 | { |
|---|
| | 322 | $person['role'] = 'developer'; |
|---|
| | 323 | } |
|---|
| | 324 | |
|---|
| | 325 | if (!array_key_exists('active', $person)) |
|---|
| | 326 | { |
|---|
| | 327 | $person['active'] = 'yes'; |
|---|
| | 328 | } |
|---|
| | 329 | |
|---|
| | 330 | $package['maintainers'] .= " |
|---|
| | 331 | <{$person['role']}> |
|---|
| | 332 | <name>{$person['name']}</name> |
|---|
| | 333 | <user>{$username}</user> |
|---|
| | 334 | <email>{$person['email']}</email> |
|---|
| | 335 | <active>{$person['active']}</active> |
|---|
| | 336 | </{$person['role']}> |
|---|
| | 337 | "; |
|---|
| | 338 | } |
|---|
| | 339 | |
|---|
| | 340 | |
|---|
| | 341 | // Generate dependencies, if any |
|---|
| | 342 | $package['dependencies'] = ''; |
|---|
| | 343 | return $package; |
|---|
| | 344 | } |
|---|
| | 345 | |
|---|
| | 346 | protected function createXml($package, $filelist) |
|---|
| | 347 | { |
|---|
| | 348 | |
|---|
| | 349 | // Create package XML |
|---|
| | 350 | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
|---|
| | 351 | <package packagerversion=\"1.4.5\" version=\"2.0\" xmlns=\"http://pear.php.net/dtd/package-2.0\" xmlns:tasks=\"http://pear.php.net/dtd/tasks-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://pear.php.net/dtd/tasks-1.0 |
|---|
| | 352 | http://pear.php.net/dtd/tasks-1.0.xsd |
|---|
| | 353 | http://pear.php.net/dtd/package-2.0 |
|---|
| | 354 | http://pear.php.net/dtd/package-2.0.xsd\"> |
|---|
| | 355 | <name>{$package['name']}</name> |
|---|
| | 356 | <channel>{$this->channel}</channel> |
|---|
| | 357 | <summary> |
|---|
| | 358 | {$package['summary']} |
|---|
| | 359 | </summary> |
|---|
| | 360 | <description> |
|---|
| | 361 | {$package['description']} |
|---|
| | 362 | </description> |
|---|
| | 363 | {$package['maintainers']} |
|---|
| | 364 | <date>{$package['date']}</date> |
|---|
| | 365 | <time>{$package['time']}</time> |
|---|
| | 366 | <version> |
|---|
| | 367 | <release>{$package['version']}</release> |
|---|
| | 368 | <api>{$package['version']}</api> |
|---|
| | 369 | </version> |
|---|
| | 370 | <stability> |
|---|
| | 371 | <release>{$package['state']}</release> |
|---|
| | 372 | <api>{$package['state']}</api> |
|---|
| | 373 | </stability> |
|---|
| | 374 | <license>{$package['license']}</license> |
|---|
| | 375 | <notes>{$package['version']} {$package['state']}</notes> |
|---|
| | 376 | <contents>\n{$filelist} </contents> |
|---|
| | 377 | <dependencies> |
|---|
| | 378 | <required> |
|---|
| | 379 | <php> |
|---|
| | 380 | <min>4.3.0</min> |
|---|
| | 381 | </php> |
|---|
| | 382 | <pearinstaller> |
|---|
| | 383 | <min>1.4.0</min> |
|---|
| | 384 | </pearinstaller> |
|---|
| | 385 | {$package['dependencies']} </required> |
|---|
| | 386 | </dependencies> |
|---|
| | 387 | <phprelease /> |
|---|
| | 388 | </package> |
|---|
| | 389 | "; |
|---|
| | 390 | |
|---|
| | 391 | } |
|---|