Ejemplo n.º 1
0
 private function _handleBuildConfig(Xinc_Build_Interface $build)
 {
     $timezone = $build->getConfigDirective('timezone');
     if ($timezone !== null) {
         Xinc_Timezone::set($timezone);
     } else {
         Xinc_Timezone::reset();
     }
 }
Ejemplo 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;
 }
Ejemplo n.º 3
0
 public function handleEvent($eventId)
 {
     $this->projectName = $_GET['project'];
     if (isset($_GET['timestamp'])) {
         $this->buildTimeStamp = $_GET['timestamp'];
     }
     $this->project = new Xinc_Project();
     $this->project->setName($this->projectName);
     switch ($eventId) {
         case Xinc_Gui_Event::PAGE_LOAD:
             $handler = Xinc_Gui_Handler::getInstance();
             $statusDir = $handler->getStatusDir();
             if ($this->buildTimeStamp != null) {
                 $fullStatusDir = Xinc_Build_History::getBuildDir($this->project, $this->buildTimeStamp);
             } else {
                 $fullStatusDir = Xinc_Build_History::getLastBuildDir($this->project);
                 $this->buildTimeStamp = Xinc_Build_History::getLastBuildTime($this->project);
             }
             //$statusFile = $fullStatusDir . DIRECTORY_SEPARATOR . 'build.ser';
             $this->build = Xinc_Build::unserialize($this->project, $this->buildTimeStamp, Xinc_Gui_Handler::getInstance()->getStatusDir());
             $timezone = $this->build->getConfigDirective('timezone');
             if ($timezone !== null) {
                 Xinc_Timezone::set($timezone);
             }
             $detailDir = $fullStatusDir;
             /**
              * get History Builds
              */
             //$this->historyBuilds = $this->getHistoryBuilds($statusDir);
             /**
              * Generate the build selector on the right
              */
             $this->_generateBuildsView();
             /**
              * Overview info tab
              */
             $this->_generateSummaryView();
             /**
              * Generate the tab for the log messages
              */
             $this->_generateLogView();
             /**
              * Generate the external tabs that were registered through a hook
              */
             $this->_generateExternalExtensions();
             include Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'projectDetail.phtml');
             break;
         default:
             break;
     }
     /**
      * restore to system timezone
      */
     $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
     if ($xincTimezone !== null) {
         Xinc_Timezone::set($xincTimezone);
     } else {
         Xinc_Timezone::reset();
     }
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 private function handleBuildConfig(Xinc_Build_Interface $build)
 {
     $logLevel = $build->getConfigDirective('loglevel');
     if ($logLevel !== null) {
         Xinc_Logger::getInstance()->setLogLevel($logLevel);
     }
     $timezone = $build->getConfigDirective('timezone');
     if ($timezone !== null) {
         Xinc_Timezone::set($timezone);
     }
 }
Ejemplo n.º 7
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";
     }
 }
Ejemplo n.º 8
0
 private function setConfigDirective($name, $value)
 {
     $this->config[$name] = $value;
     switch ($name) {
         case 'loglevel':
             Xinc_Logger::getInstance()->setLogLevel($value);
             break;
         case 'timezone':
             Xinc_Timezone::set($value);
             break;
         default:
     }
 }
Ejemplo n.º 9
0
 public function handleEvent($eventId)
 {
     switch ($eventId) {
         case Xinc_Gui_Event::PAGE_LOAD:
             $query = urldecode($_SERVER['REQUEST_URI']);
             $this->features = $this->extensions['PROJECT_FEATURE'];
             $handler = Xinc_Gui_Handler::getInstance();
             $statusDir = $handler->getStatusDir();
             $dir = opendir($statusDir);
             while ($file = readdir($dir)) {
                 $project = array();
                 $fullfile = $statusDir . DIRECTORY_SEPARATOR . $file;
                 if (!in_array($file, array('.', '..')) && is_dir($fullfile)) {
                     $project['name'] = $file;
                     $statusfile = $fullfile . DIRECTORY_SEPARATOR . 'build.ser';
                     //$xincProject = $fullfile . DIRECTORY_SEPARATOR . '.xinc';
                     if (file_exists($statusfile)) {
                         //$ini = parse_ini_file($statusfile, true);
                         $project = new Xinc_Project();
                         $project->setName($file);
                         try {
                             $object = Xinc_Build_Repository::getLastBuild($project);
                             $this->builds->add($object);
                         } catch (Exception $e) {
                         }
                     } else {
                         if (file_exists($xincProject)) {
                             $project['build.status'] = -10;
                             $project['build.time'] = 0;
                             $project['build.label'] = '';
                             $this->projects[] = $project;
                         }
                     }
                     $this->menu = '';
                     if (isset($this->extensions['MAIN_MENU'])) {
                         if (is_array($this->extensions['MAIN_MENU'])) {
                             foreach ($this->extensions['MAIN_MENU'] as $extension) {
                                 $this->menu .= call_user_func_array($extension, array($this, 'Dashboard'));
                             }
                         }
                     }
                 }
             }
             if (preg_match('/\\/dashboard\\/projects.*/', $query)) {
                 include_once Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'projects.phtml');
             }
             break;
         default:
             break;
     }
     /**
      * restore to system timezone
      */
     $xincTimezone = Xinc_Gui_Handler::getInstance()->getConfigDirective('timezone');
     if ($xincTimezone !== null) {
         Xinc_Timezone::set($xincTimezone);
     } else {
         Xinc_Timezone::reset();
     }
 }
Ejemplo n.º 10
0
 public static function generateStatusSubDir($projectName, $buildTime)
 {
     $oldTimeZone = ini_get('date.timezone');
     if (Xinc_Timezone::getIniTimezone() == null) {
         ini_set('date.timezone', 'UTC');
     }
     $yearMonthDay = date('Ymd', $buildTime);
     $subDirectory = $projectName;
     $subDirectory .= DIRECTORY_SEPARATOR;
     $subDirectory .= $yearMonthDay . DIRECTORY_SEPARATOR . $buildTime;
     if (Xinc_Timezone::getIniTimezone() == null) {
         ini_set('date.timezone', $oldTimeZone);
     }
     return $subDirectory;
 }