notes.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * The NotesTask is a source-annotations extractor task for bake2, that allows you to add FIXME, OPTIMIZE,
  4. * and TODO comments to your source code that can then be extracted in concert with this task
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * Licensed under The MIT License
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @filesource
  12. * @copyright Copyright 2006-2007, Joel Moss
  13. * @link http://joelmoss.info
  14. * @since CakePHP(tm) v 1.2
  15. * @version $Version: 1.0 $
  16. * @modifiedby $LastChangedBy: joelmoss $
  17. * @lastmodified $Date: 2007-02-27 (Tues, 27 Feb 2007) $
  18. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  19. *
  20. *
  21. * @Changelog
  22. *
  23. * v 1.0
  24. * [+] Initial code offering
  25. *
  26. *
  27. * LOTS OF PROBLEMS - until working...
  28. * 2009-05-07 ms
  29. */
  30. App::import('Core','Folder');
  31. App::import('Core','File');
  32. class NotesShell extends Shell {
  33. var $notes = array();
  34. var $type = null;
  35. var $dirs = array(
  36. 'config',
  37. 'controllers',
  38. 'models',
  39. 'plugins',
  40. );
  41. function main($params = null) {
  42. $this->welcome();
  43. if (isset($params[0])) {
  44. if ($params[0] == 'todo') {
  45. $this->type = 'TODO';
  46. } elseif ($params[0] == 'fixme') {
  47. $this->type = 'FIXME';
  48. } elseif ($params[0] == 'optimise' || $params[0] == 'optimize') {
  49. $this->type = 'OPTIMIZE';
  50. } elseif ($params[0] == 'help') {
  51. $this->help();
  52. }
  53. }
  54. $this->read();
  55. foreach ($this->dirs as $d) {
  56. $this->read($d, true);
  57. }
  58. foreach ($this->notes as $file => $types) {
  59. $this->out("$file:");
  60. $this->out('');
  61. foreach ($types as $type => $notes)
  62. {
  63. foreach ($notes as $ln => $note)
  64. {
  65. $this->out(" * [$ln] [$type] $note");
  66. }
  67. }
  68. $this->out('');
  69. }
  70. $this->hr();
  71. }
  72. function read($dir = null, $recursive = false) {
  73. $notes = array();
  74. $path = CORE_PATH.APP_PATH.$dir;
  75. $folder = new Folder(APP_PATH.$dir);
  76. $fold = $recursive ? $folder->findRecursive('.*\.php') : $folder->find('.*\.php');
  77. foreach ($fold as $file) {
  78. $file = $recursive ? $file : $path.$file;
  79. $file_path = r(CORE_PATH.APP_PATH, '', $file);
  80. $handle = new File($file_path);
  81. $content = $handle->read();
  82. $lines = explode(PHP_EOL, $content);
  83. //$lines = file($file);
  84. $ln = 1;
  85. if (!empty($lines)) {
  86. foreach ($lines as $line) {
  87. if ((is_null($this->type) || $this->type == 'TODO') &&
  88. preg_match("/[#\*\\/\\/]\s*TODO\s*(.*)/", $line, $match)) {
  89. $this->notes[$file_path]['TODO'][$ln] = $match[1];
  90. }
  91. if ((is_null($this->type) || $this->type == 'OPTIMIZE') &&
  92. preg_match("/[#\*\\/\\/]\s*OPTIMIZE|OPTIMISE\s*(.*)/", $line, $match)) {
  93. $this->notes[$file_path]['OPTIMIZE'][$ln] = $match[1];
  94. }
  95. if ((is_null($this->type) || $this->type == 'FIXME') &&
  96. preg_match("/[#\*\\/\\/]\s*FIXME|BUG\s*(.*)/", $line, $match)) {
  97. $this->notes[$file_path]['FIXME'][$ln] = $match[1];
  98. }
  99. $ln++;
  100. }
  101. }
  102. }
  103. return $this->notes;
  104. }
  105. function help() {
  106. $this->out("This task allows you to add");
  107. $this->out("FIXME/BUG, OPTIMIZE, and TODO comments to your source, e.g.:");
  108. $this->out("# FIXME: blablub");
  109. $this->out("");
  110. $this->out("code that can then be extracted in concert with bake2 notes (shows all), bake2");
  111. $this->out("notes fixme, bake2 notes optimize and bake2 notes todo.");
  112. $this->out("Usage: bake notes [todo|optimize|fixme]");
  113. $this->hr();
  114. exit;
  115. }
  116. /*
  117. function out($str='', $newline=true)
  118. {
  119. $nl = $newline ? "\n" : "";
  120. echo " $str$nl";
  121. }
  122. function hr()
  123. {
  124. echo "\n ----------------------------------------------------------------------------\n";
  125. }
  126. function err($str)
  127. {
  128. $this->out('');
  129. $this->out('');
  130. $this->out($str);
  131. $this->out('');
  132. $this->out('');
  133. exit;
  134. }
  135. */
  136. function welcome()
  137. {
  138. $this->out('');
  139. $this->hr();
  140. $this->out('-- Notes --');
  141. $this->hr();
  142. $this->out('');
  143. }
  144. }