示例#1
0
 private function _getHistoryBuilds(Xinc_Project $project, $start, $limit = null)
 {
     /**$statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
             $historyFile = $statusDir . DIRECTORY_SEPARATOR . $project->getName() . '.history';
     
             $buildHistoryArr = unserialize(file_get_contents($historyFile));
             $totalCount = count($buildHistoryArr);
             if ($limit==null) {
                 $limit = $totalCount;
             }
             /**
              * turn it upside down so the latest builds appear first
              */
     /**
             $buildHistoryArr = array_reverse($buildHistoryArr, true);
             $buildHistoryArr = array_slice($buildHistoryArr, $start, $limit, true);*/
     $buildHistoryArr = Xinc_Build_History::getFromTo($project, $start, $limit);
     $totalCount = Xinc_Build_History::getCount($project);
     $builds = array();
     foreach ($buildHistoryArr as $buildTimestamp => $buildFileName) {
         try {
             //$buildObject = Xinc_Build::unserialize($project,
             //                                       $buildTimestamp,
             //                                       Xinc_Gui_Handler::getInstance()->getStatusDir());
             $buildObject = Xinc_Build_Repository::getBuild($project, $buildTimestamp);
             $builds[] = array('number' => $buildObject->getNumber(), 'y' => $buildObject->getStatistics()->get('build.duration'), 'xlabel' => $buildObject->getNumber());
         } catch (Exception $e) {
             // TODO: Handle
         }
     }
     $builds = array_reverse($builds, true);
     return $builds;
 }
示例#2
0
 public function handleEvent($eventId)
 {
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 6) {
         echo "Could not find artifact";
         return;
     }
     $projectName = $matches[3];
     $buildTime = $matches[4];
     $file = $matches[5];
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         $build = Xinc_Build::unserialize($project, $buildTime, Xinc_Gui_Handler::getInstance()->getStatusDir());
         $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Artifacts::ARTIFACTS_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find artifact";
         } else {
             if (file_exists($fileName)) {
                 $contentType = $this->mime_content_type2($fileName);
                 if (!empty($contentType)) {
                     header("Content-Type: " . $contentType);
                 }
                 readfile($fileName);
             } else {
                 echo "Could not find artifact";
             }
         }
     } catch (Exception $e) {
         echo "Could not find any artifacts";
     }
 }
示例#3
0
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDeliverableFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find deliverable";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Deliverable::DELIVERABLE_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             // check if we have an alias name
             $deliverables = $build->getInternalProperties()->get('deliverables');
             if (is_array($deliverables)) {
                 $aliasTest = basename($file);
                 if (isset($deliverables['aliases']) && isset($deliverables['aliases'][$aliasTest])) {
                     $aliasFile = $deliverables['deliverables'][$deliverables['aliases'][$aliasTest]];
                     if (file_exists($aliasFile) && is_file($aliasFile)) {
                         return $this->_outputDeliverable($aliasFile);
                     }
                 }
             }
             echo "Could not find artifact";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDeliverable($fileName);
             } else {
                 echo "Could not find deliverable";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any deliverable";
         die;
     }
 }
示例#4
0
 private function getHistoryBuildsByTimestamp(Xinc_Project $project, $timestamp, $limit = null)
 {
     $buildHistoryArr = Xinc_Build_History::getFromToTimestamp($project, $timestamp, $limit, false);
     return $buildHistoryArr;
 }
示例#5
0
 public static function getLastSuccessfulBuild(Xinc_Project &$project)
 {
     $lastBuildTime = Xinc_Build_History::getLastSuccessfulBuildTime($project);
     //$lastBuildTime = $buildHistoryArr[count($buildHistoryArr) - 1];
     return self::getBuild($project, $lastBuildTime);
 }
示例#6
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();
     }
 }
 /**
  * Load the requested artifacts file and output it to the browser
  *
  * @param array $params
  */
 private function _getDocumentationFile($params)
 {
     /**$projectName = $params['p'];
        $buildTime = $params['buildtime'];
        $file = $params['file'];*/
     $query = urldecode($_SERVER['REQUEST_URI']);
     preg_match("/\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*?)\\/(.*)/", $query, $matches);
     if (count($matches) != 8) {
         echo "Could not find documentation 1";
         die;
     }
     $projectName = $matches[5];
     $buildTime = $matches[6];
     // if buildtime==latest, get latest build
     // latest
     // Xinc_Build_History::get()
     $file = $matches[7];
     //$file = urldecode($file);
     $file = str_replace('/', DIRECTORY_SEPARATOR, $file);
     $project = new Xinc_Project();
     $project->setName($projectName);
     try {
         /**$build = Xinc_Build::unserialize($project,
            $buildTime,
            Xinc_Gui_Handler::getInstance()->getStatusDir());*/
         if ($buildTime == 'latest-successful') {
             $build = Xinc_Build_Repository::getLastSuccessfulBuild($project);
             $statusDir = Xinc_Build_History::getLastSuccessfulBuildDir($project);
         } else {
             if ($buildTime == 'latest') {
                 $build = Xinc_Build_Repository::getLastBuild($project);
                 $statusDir = Xinc_Build_History::getLastBuildDir($project);
             } else {
                 $build = Xinc_Build_Repository::getBuild($project, $buildTime);
                 $statusDir = Xinc_Build_History::getBuildDir($project, $buildTime);
             }
         }
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Documentation::DOCUMENTATION_DIR . DIRECTORY_SEPARATOR;
         /**
          * Replace multiple / slashes with just one
          */
         $fileName = $statusDir . $file;
         $fileName = preg_replace('/\\' . DIRECTORY_SEPARATOR . '+/', DIRECTORY_SEPARATOR, $fileName);
         $realfile = realpath($fileName);
         if ($realfile != $fileName) {
             echo "Could not find documentation 2";
             die;
         } else {
             if (file_exists($fileName) && is_file($realfile)) {
                 return $this->_outputDoc($fileName);
             } else {
                 echo "Could not find documentation 3";
                 die;
             }
         }
     } catch (Exception $e) {
         echo "Could not find any documentation";
         die;
     }
 }
示例#8
0
 /**
  * Build the artifacts tree
  *
  * @param Xinc_Build_Interface $build
  * @param string $dirname
  *
  * @return array
  */
 private function _getArtifactsTree(Xinc_Build_Interface $build, $dirname)
 {
     $projectName = $build->getProject()->getName();
     $buildTime = $build->getBuildTime();
     try {
         $statusDir = Xinc_Build_History::getBuildDir($build->getProject(), $buildTime);
         $statusDir .= DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Artifacts::ARTIFACTS_DIR . DIRECTORY_SEPARATOR;
         $directory = $statusDir . $dirname;
         if (!is_dir($directory)) {
             return;
         }
         $dh = opendir($directory);
         $items = array();
         while ($file = readdir($dh)) {
             if (!in_array($file, array('.', '..'))) {
                 if (is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
                     $class = 'folder';
                     $leaf = false;
                 } else {
                     $class = 'file';
                     $leaf = true;
                 }
                 $items[] = array('text' => $file, 'id' => addslashes(str_replace(DIRECTORY_SEPARATOR, '/', $dirname . DIRECTORY_SEPARATOR . $file)), 'cls' => $class, 'leaf' => $leaf);
             }
         }
     } catch (Exception $e1) {
         return array();
     }
     return $items;
 }
示例#9
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;
 }
示例#10
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;
 }
示例#11
0
 /**
  * Unserialize a build by its project and buildtimestamp.
  *
  * @param Xincproject $project
  * @param int         $buildTimestamp
  *
  * @return Xinc_Build
  *
  * @throws Xinc_Build_Exception_Unserialization
  * @throws Xinc_Build_Exception_NotFound
  */
 public static function unserialize(Project $project, $buildTimestamp = null, $statusDir = null)
 {
     if ($statusDir == null) {
         $statusDir = Xinc::getInstance()->getStatusDir();
     }
     if ($buildTimestamp == null) {
         //$fileName = $statusDir . DIRECTORY_SEPARATOR . $project->getName()
         //          . DIRECTORY_SEPARATOR . 'build.ser';
         $fileName = Xinc_Build_History::getLastBuildFile($project);
     } else {
         //$subDirectory = self::generateStatusSubDir($project->getName(), $buildTimestamp);
         // throws Xinc_Build_Exception_NotFound
         $fileName = Xinc_Build_History::getBuildFile($project, $buildTimestamp);
     }
     //Xinc_Build_Repository::getBuild($project, $buildTimestamp);
     if (!file_exists($fileName)) {
         throw new Xinc_Build_Exception_NotFound($project, $buildTimestamp);
     } else {
         $serializedString = file_get_contents($fileName);
         $unserialized = @unserialize($serializedString);
         if (!$unserialized instanceof Xinc_Build) {
             throw new Xinc_Build_Exception_Unserialization($project, $buildTimestamp);
         } else {
             /*
              * compatibility with old Xinc_Build w/o statistics object
              */
             if ($unserialized->getStatistics() === null) {
                 $unserialized->_statistics = new Xinc_Build_Statistics();
             }
             if ($unserialized->getConfigDirective('timezone.reporting') == true) {
                 $unserialized->setConfigDirective('timezone', null);
             }
             if (!isset($unserialized->_internalProperties)) {
                 if (method_exists($unserialized, 'init')) {
                     $unserialized->init();
                 }
             }
             return $unserialized;
         }
     }
 }