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"; } }
/** * 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; } }
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; } }
/** * 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; }
/** * 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; }