CoverageMergerTask.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * $Id: CoverageMergerTask.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. require_once 'phing/system/io/PhingFile.php';
  23. require_once 'phing/system/io/Writer.php';
  24. require_once 'phing/system/util/Properties.php';
  25. require_once 'phing/tasks/ext/coverage/CoverageMerger.php';
  26. /**
  27. * Merges code coverage snippets into a code coverage database
  28. *
  29. * @author Michiel Rook <michiel.rook@gmail.com>
  30. * @version $Id: CoverageMergerTask.php 905 2010-10-05 16:28:03Z mrook $
  31. * @package phing.tasks.ext.coverage
  32. * @since 2.1.0
  33. */
  34. class CoverageMergerTask extends Task
  35. {
  36. /** the list of filesets containing the .php filename rules */
  37. private $filesets = array();
  38. /**
  39. * Add a new fileset containing the .php files to process
  40. *
  41. * @param FileSet the new fileset containing .php files
  42. */
  43. function addFileSet(FileSet $fileset)
  44. {
  45. $this->filesets[] = $fileset;
  46. }
  47. /**
  48. * Iterate over all filesets and return all the filenames.
  49. *
  50. * @return array an array of filenames
  51. */
  52. private function getFilenames()
  53. {
  54. $files = array();
  55. foreach ($this->filesets as $fileset)
  56. {
  57. $ds = $fileset->getDirectoryScanner($this->project);
  58. $ds->scan();
  59. $includedFiles = $ds->getIncludedFiles();
  60. foreach ($includedFiles as $file)
  61. {
  62. $fs = new PhingFile(basename($ds->getBaseDir()), $file);
  63. $files[] = $fs->getAbsolutePath();
  64. }
  65. }
  66. return $files;
  67. }
  68. function main()
  69. {
  70. $files = $this->getFilenames();
  71. $this->log("Merging " . count($files) . " coverage files");
  72. foreach ($files as $file)
  73. {
  74. $coverageInformation = unserialize(file_get_contents($file));
  75. CoverageMerger::merge($this->project, array($coverageInformation));
  76. }
  77. }
  78. }