| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
require_once "phing/Task.php"; |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class packageStatic extends Task |
|---|
| 17 |
{ |
|---|
| 18 |
|
|---|
| 19 |
protected $package = null; |
|---|
| 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; |
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 93 |
//$this->readManifest(); |
|---|
| 94 |
$packageInfo = $this->getComponentInfo(); |
|---|
| 95 |
|
|---|
| 96 |
$filelist = $this->getFileList($packageInfo); |
|---|
| 97 |
|
|---|
| 98 |
$xml = $this->createXml($packageInfo, $filelist); |
|---|
| 99 |
|
|---|
| 100 |
file_put_contents($this->path . "/" . $this->package . "/package.xml", $xml); |
|---|
| 101 |
|
|---|
| 102 |
$this->execPearPackage(); |
|---|
| 103 |
|
|---|
| 104 |
$name = $this->package_name . "-" . $packageInfo['version']; |
|---|
| 105 |
$this->project->setProperty($this->returnProperty, $name); |
|---|
| 106 |
|
|---|
| 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 |
|
|---|
| 183 |
$config['prefix'] .= ' '; |
|---|
| 184 |
$config['filelist'] .= "{$config['prefix']}<dir name=\"{$dir_name}\">\n"; |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
while (false !== ($entry = $directory->read())) |
|---|
| 189 |
{ |
|---|
| 190 |
if (substr($entry, 0, 1) == '.') |
|---|
| 191 |
{ |
|---|
| 192 |
|
|---|
| 193 |
continue; |
|---|
| 194 |
} |
|---|
| 195 |
if ($entry == 'CVS' || $entry == '.svn') |
|---|
| 196 |
{ |
|---|
| 197 |
|
|---|
| 198 |
continue; |
|---|
| 199 |
} |
|---|
| 200 |
if ($entry == 'package.xml') |
|---|
| 201 |
{ |
|---|
| 202 |
|
|---|
| 203 |
continue; |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
elseif ($dir_name == 'config' && $entry == 'mgdschema.xml') |
|---|
| 208 |
{ |
|---|
| 209 |
|
|---|
| 210 |
$role = 'mgdschema'; |
|---|
| 211 |
} |
|---|
| 212 |
elseif ($dir_name == 'config' && $entry == 'mgdschema.sql') |
|---|
| 213 |
{ |
|---|
| 214 |
|
|---|
| 215 |
// These will be installed via the Datagard database update command |
|---|
| 216 |
$role = 'midgardsql'; |
|---|
| 217 |
} else |
|---|
| 218 |
{ |
|---|
| 219 |
|
|---|
| 220 |
$role = 'php'; |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
$path_parts = pathinfo($entry); |
|---|
| 224 |
switch ($path_parts['extension']) |
|---|
| 225 |
{ |
|---|
| 226 |
|
|---|
| 227 |
case 'jpg' : |
|---|
| 228 |
case 'gif' : |
|---|
| 229 |
case 'png' : |
|---|
| 230 |
case 'zip' : |
|---|
| 231 |
case 'tgz' : |
|---|
| 232 |
$role = 'data'; |
|---|
| 233 |
break; |
|---|
| 234 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 279 |
$package['name'] = $this->package_name; |
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
$package['license'] = 'LGPL'; |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
$package['version'] = '1.0.0'; |
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 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 |
|
|---|
| 296 |
$package['summary'] = "Static icons"; |
|---|
| 297 |
|
|---|
| 298 |
$package['description'] = "MidCOM Icons."; |
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 342 |
$package['dependencies'] = ''; |
|---|
| 343 |
return $package; |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
protected function createXml($package, $filelist) |
|---|
| 347 |
{ |
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 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 |
} |
|---|
| 392 |
|
|---|
| 393 |
} |
|---|
| 394 |
?> |
|---|