. */ require_once 'phing/Task.php'; require_once 'phing/system/io/PhingFile.php'; require_once 'phing/system/io/FileWriter.php'; require_once 'phing/util/ExtendedFileStream.php'; /** * Transform a Phing/Xdebug code coverage xml report. * The default transformation generates an html report in framed style. * * @author Michiel Rook * @version $Id: CoverageReportTransformer.php 905 2010-10-05 16:28:03Z mrook $ * @package phing.tasks.ext.coverage * @since 2.1.0 */ class CoverageReportTransformer { private $task = NULL; private $styleDir = ""; private $toDir = ""; private $document = NULL; function __construct(Task $task) { $this->task = $task; } function setStyleDir($styleDir) { $this->styleDir = $styleDir; } function setToDir($toDir) { $this->toDir = $toDir; } function setXmlDocument($document) { $this->document = $document; } function transform() { $dir = new PhingFile($this->toDir); if (!$dir->exists()) { throw new BuildException("Directory '" . $this->toDir . "' does not exist"); } $xslfile = $this->getStyleSheet(); $xsl = new DOMDocument(); $xsl->load($xslfile->getAbsolutePath()); $proc = new XSLTProcessor(); $proc->importStyleSheet($xsl); ExtendedFileStream::registerStream(); // no output for the framed report // it's all done by extension... $proc->setParameter('', 'output.dir', $dir->toString()); $proc->transformToXML($this->document); ExtendedFileStream::unregisterStream(); } private function getStyleSheet() { $xslname = "coverage-frames.xsl"; if ($this->styleDir) { $file = new PhingFile($this->styleDir, $xslname); } else { $path = Phing::getResourcePath("phing/etc/$xslname"); if ($path === NULL) { $path = Phing::getResourcePath("etc/$xslname"); if ($path === NULL) { throw new BuildException("Could not find $xslname in resource path"); } } $file = new PhingFile($path); } if (!$file->exists()) { throw new BuildException("Could not find file " . $file->getPath()); } return $file; } }