Exemplo n.º 1
0
 /**
  * Fired when the build finishes, this adds the time taken and any
  * error stacktrace to the build element and writes the document to disk.
  *
  * @param BuildEvent $event An event with any relevant extra information.
  *                          Will not be <code>null</code>.
  * @throws BuildException
  */
 public function buildFinished(BuildEvent $event)
 {
     $elapsedTime = Phing::currentTimeMillis() - $this->getBuildTimerStart();
     $this->getBuildElement()->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime));
     if ($event->getException() != null) {
         $this->getBuildElement()->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage());
         $errText = $this->getDoc()->createCDATASection($event->getException()->getTraceAsString());
         $stacktrace = $this->getDoc()->createElement(XmlLogger::STACKTRACE_TAG);
         $stacktrace->appendChild($errText);
         $this->getBuildElement()->appendChild($stacktrace);
     }
     $this->getDoc()->appendChild($this->getBuildElement());
     $outFilename = $event->getProject()->getProperty("JsonLogger.file");
     if ($outFilename == null) {
         $outFilename = "log.json";
     }
     try {
         $stream = $this->getOut();
         if ($stream === null) {
             $stream = new FileOutputStream($outFilename);
         }
         $writer = new OutputStreamWriter($stream);
         $writer->write($this->xml2js(simplexml_import_dom($this->getDoc())));
         $writer->close();
     } catch (IOException $exc) {
         try {
             $stream->close();
             // in case there is a stream open still ...
         } catch (Exception $x) {
         }
         throw new BuildException("Unable to write log file.", $exc);
     }
     // cleanup:remove the buildElement
     $this->setBuildElement(null);
     array_pop($this->getElementStack());
     array_pop($this->getTimesStack());
 }
Exemplo n.º 2
0
 /**
  * Fired when the build finishes, this adds the time taken and any
  * error stacktrace to the build element and writes the document to disk.
  *
  * @param BuildEvent $event An event with any relevant extra information.
  *                          Will not be <code>null</code>.
  * @throws BuildException
  */
 public function buildFinished(BuildEvent $event)
 {
     $elapsedTime = Phing::currentTimeMillis() - $this->buildTimerStart;
     $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime));
     if ($event->getException() != null) {
         $this->buildElement->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage());
         $errText = $this->doc->createCDATASection($event->getException()->getTraceAsString());
         $stacktrace = $this->doc->createElement(XmlLogger::STACKTRACE_TAG);
         $stacktrace->appendChild($errText);
         $this->buildElement->appendChild($stacktrace);
     }
     $this->doc->appendChild($this->buildElement);
     $outFilename = $event->getProject()->getProperty("XmlLogger.file");
     if ($outFilename == null) {
         $outFilename = "log.xml";
     }
     try {
         $stream = $this->out;
         if ($stream === null) {
             $stream = new FileOutputStream($outFilename);
         }
         // Yes, we could just stream->write() but this will eventually be the better
         // way to do this (when we need to worry about charset conversions.
         $writer = new OutputStreamWriter($stream);
         $writer->write($this->doc->saveXML());
         $writer->close();
     } catch (IOException $exc) {
         try {
             $stream->close();
             // in case there is a stream open still ...
         } catch (Exception $x) {
         }
         throw new BuildException("Unable to write log file.", $exc);
     }
     // cleanup:remove the buildElement
     $this->buildElement = null;
     array_pop($this->elementStack);
     array_pop($this->timesStack);
 }
Exemplo n.º 3
0
 /**
  * Construct a new FileWriter.
  * @param mixed $file PhingFile or string pathname.
  * @param boolean $append Append to existing file?
  */
 function __construct($file, $append = false)
 {
     $out = new FileOutputStream($file, $append);
     parent::__construct($out);
 }
Exemplo n.º 4
0
 /**
  * Write frame to stream
  *
  * @param   io.streams.OutputStreamWriter out
  */
 public function write(OutputStreamWriter $out)
 {
     $out->write($this->command() . "\n");
     foreach ($this->getHeaders() as $key => $value) {
         $out->write($key . ':' . $value . "\n");
     }
     $out->write("\n" . $this->getBody() . chr(0));
 }