Esempio n. 1
0
 /**
  * Constructor: parses plugins and sets status dir
  *
  * @param string $pluginFile
  * @param string $statusDir
  */
 public function __construct($configFile, $statusDir)
 {
     $this->systemTimezone = Xinc_Timezone::get();
     $this->statusDir = realpath($statusDir);
     $this->setSystemConfigFile($configFile);
     self::$instance =& $this;
     $this->apiHandler = Xinc_Api_Handler::getInstance();
 }
Esempio n. 2
0
 public function getContent(Xinc_Build_Interface $build)
 {
     switch ($build->getStatus()) {
         case 1:
             $image = './images/passed.png';
             break;
         case -1:
             $image = './images/stopped.png';
             break;
         case 0:
             $image = './images/failed.png';
             break;
         default:
             $image = './images/stopped.png';
             break;
     }
     $overviewTemplateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'overview.phtml');
     $overviewTemplate = file_get_contents($overviewTemplateFile);
     $content = call_user_func_array('sprintf', array($overviewTemplate, $image, date('Y-m-d H:i:s', $build->getBuildTime()) . '-' . Xinc_Timezone::get(), $build->getLabel(), $this->_generateAllExtensions($build)));
     return $content;
 }
Esempio n. 3
0
 private function _getHistoryBuilds($projectName, $start, $limit = null)
 {
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $buildHistoryArr = Xinc_Build_History::getFromTo($project, $start, $limit);
         $totalCount = Xinc_Build_History::getCount($project);
         $builds = array();
         foreach ($buildHistoryArr as $buildTimestamp => $buildFileName) {
             try {
                 //echo $buildTimestamp . ' - '. $buildFileName . "<br>";
                 //Xinc_Build_Repository::getBuild($project, $buildTimestamp);
                 //$buildObject = Xinc_Build::unserialize($project,
                 //                                       $buildTimestamp,
                 //                                       Xinc_Gui_Handler::getInstance()->getStatusDir());
                 $buildObject = Xinc_Build_Repository::getBuild($project, $buildTimestamp);
                 $timezone = $buildObject->getConfigDirective('timezone');
                 if ($timezone !== null) {
                     Xinc_Timezone::set($timezone);
                 }
                 $builds[] = array('buildtime' => date('Y-m-d H:i:s', $buildObject->getBuildTime()), 'timezone' => Xinc_Timezone::get(), 'buildtimeRaw' => $buildObject->getBuildTime(), 'label' => $buildObject->getLabel(), 'status' => $buildObject->getStatus());
                 /**
                  * restore to system timezone
                  */
                 $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
                 if ($xincTimezone !== null) {
                     Xinc_Timezone::set($xincTimezone);
                 } else {
                     Xinc_Timezone::reset();
                 }
             } catch (Exception $e) {
                 // TODO: Handle
             }
         }
         //$builds = array_reverse($builds);
     } catch (Exception $e) {
         $builds = array();
         $totalCount = 0;
     }
     $object = new stdClass();
     $object->totalcount = $totalCount;
     $object->builds = $builds;
     //return new Xinc_Build_Iterator($builds);
     return $object;
 }
Esempio n. 4
0
 /**
  * Get a list of all builds of a project
  *
  * @param string $projectName
  * @param integer $start
  * @param integer $limit
  *
  * @return stdClass
  */
 private function _getLogMessagesArr($projectName, $buildTime, $start, $limit = null)
 {
     $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
     $historyFile = $statusDir . DIRECTORY_SEPARATOR . $projectName . '.history';
     $project = new Xinc_Project();
     $project->setName($projectName);
     $totalCount = 0;
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, $statusDir);
         $timezone = $build->getConfigDirective('timezone');
         if ($timezone !== null) {
             Xinc_Timezone::set($timezone);
         }
         $detailDir = Xinc_Build_History::getBuildDir($project, $buildTime);
         $logXmlFile = $detailDir . DIRECTORY_SEPARATOR . 'buildlog.xml';
         if (file_exists($logXmlFile)) {
             /**
              * Add fopen() to the function to just get the loglines
              * that we need.
              * the bigger the logfiles get, the more this gets a
              * performance problem
              */
             $xmlStr = '';
             $pos = 0;
             $fh = fopen($logXmlFile, 'r');
             $xmlStr = fgets($fh);
             $xmlStr .= fgets($fh);
             $tagOpen = false;
             while ($pos < $start && ($message = $this->_getNextMessage($fh)) !== false) {
                 $pos++;
                 $totalCount++;
             }
             if ($limit != null) {
                 $addClosingTag = true;
                 while ($pos < $start + $limit && ($message = $this->_getNextMessage($fh)) !== false) {
                     $xmlStr .= $message;
                     $pos++;
                     $totalCount++;
                 }
                 $xmlStr .= '</build>';
             } else {
                 while (($message = $this->_getNextMessage($fh)) !== false) {
                     $xmlStr .= $message;
                     $totalCount++;
                     $pos++;
                 }
                 $xmlStr .= '</build>';
             }
             $tagOpen = false;
             $tagClosed = false;
             while (($message = $this->_getNextMessage($fh)) !== false) {
                 $totalCount++;
                 $pos++;
             }
             fclose($fh);
             $logXml = new SimpleXMLElement($xmlStr);
         } else {
             $logXml = new SimpleXmlElement('<log/>');
         }
         $totalCount = $pos;
         //count($logXml->children());
         $i = $pos;
         $logmessages = array();
         $id = $totalCount - $start;
         foreach ($logXml->children() as $logEntry) {
             $attributes = $logEntry->attributes();
             $logmessages[] = array('id' => $id--, 'date' => (string) $attributes->timestamp, 'stringdate' => date('Y-m-d H:i:s', (int) $attributes->timestamp), 'timezone' => Xinc_Timezone::get(), 'priority' => (string) $attributes->priority, 'message' => base64_decode($logEntry));
         }
         /**
          * restore to system timezone
          */
         $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
         if ($xincTimezone !== null) {
             Xinc_Timezone::set($xincTimezone);
         } else {
             Xinc_Timezone::reset();
         }
         //$logmessages = array_slice($logmessages, $start, $limit, false);
     } catch (Exception $e1) {
         $totalCount = 0;
         $logmessages = array();
     }
     $object = new stdClass();
     $object->totalmessages = $totalCount;
     $object->logmessages = $logmessages;
     //return new Xinc_Build_Iterator($builds);
     return $object;
 }
Esempio n. 5
0
 public function handleEvent($eventId)
 {
     $query = $_SERVER['REQUEST_URI'];
     $projectName = isset($_REQUEST['project']) ? $_REQUEST['project'] : null;
     $buildTime = isset($_REQUEST['buildtime']) ? $_REQUEST['buildtime'] : null;
     if (empty($projectName) || empty($buildTime)) {
         die('Could not find phpunit test results');
     }
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, Xinc_Gui_Handler::getInstance()->getStatusDir());
         $buildLabel = $build->getLabel();
         $timezone = $build->getConfigDirective('timezone');
         if ($timezone !== null) {
             Xinc_Timezone::set($timezone);
         } else {
             $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
             if ($xincTimezone !== null) {
                 Xinc_Timezone::set($xincTimezone);
             } else {
                 Xinc_Timezone::set(Xinc_Gui_Handler::getInstance()->getSystemTimezone());
             }
         }
         $sourceFile = $build->getInternalProperties()->get('phpunit.file');
         if ($sourceFile != null && file_exists($sourceFile) && class_exists('XSLTProcessor')) {
             $xslFile = Xinc_Data_Repository::getInstance()->getPlugins('resources' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR . 'details.xsl');
             try {
                 $outputFileName = Xinc_Ini::getInstance()->get('tmp_dir', 'xinc') . DIRECTORY_SEPARATOR . 'phpunit_details_' . $projectName . '_' . $buildTime;
             } catch (Exception $e) {
                 Xinc_Logger::getInstance()->error('Cannot get xinc.ini configuration');
                 $outputFileName = 'phpunit_details_' . $projectName . '_' . $buildTime;
             }
             if (file_exists($outputFileName)) {
                 $details = file_get_contents($outputFileName);
             } else {
                 $details = $this->_transformResults($sourceFile, $xslFile, $outputFileName);
             }
             //$click = 'openMenuTab(\'phpunit-'.$projectName.'-'.$buildTimestamp.'\',\'PHPUnit - '.$projectName.'\',\''.$url.'\',null,false,false,\'auto\');';
             $title = 'PHPUnit Test Results';
             $buildTimeString = date('Y-m-d H:i:s', $build->getBuildTime()) . '-' . Xinc_Timezone::get();
             $content = str_replace(array('{title}', '{details}', '{projectName}', '{buildLabel}', '{buildTime}'), array($title, $details, $projectName, $buildLabel, $buildTimeString), $details);
         } else {
             $content = false;
         }
         Xinc_Timezone::reset();
         echo $content;
     } catch (Exception $e) {
         echo "Could not find phpunit test results";
     }
 }