PhergiePackageTask.php 4.2 KB

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