public function getContent(Xinc_Build_Interface $build) { $deliverableLinkTemplateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'documentation-link.phtml'); $deliverableLinkTemplate = file_get_contents($deliverableLinkTemplateFile); $getDeliverableUrl = './api/documentation/get/file/' . $build->getProject()->getName() . '/' . $build->getBuildTime() . '/'; $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir(); $subDir = $build->getStatusSubDir(); $docDir = $statusDir . DIRECTORY_SEPARATOR . $subDir . DIRECTORY_SEPARATOR . Xinc_Plugin_Repos_Documentation::DOCUMENTATION_DIR; $deliverableLinks = array(); $docs = $build->getInternalProperties()->get('documentation'); if (!is_array($docs)) { return false; } foreach ($docs as $alias => $array) { $publicName = $alias; $dirName = dirname($array['file']); $indexFile = preg_replace('/\\/+/', '/', $array['index']); $myDocDir = $docDir . DIRECTORY_SEPARATOR . $publicName; $myDocDir = preg_replace('/\\/+/', '/', $myDocDir); $indexFile = str_replace($myDocDir, '', $indexFile); $link = $getDeliverableUrl . $publicName . '/' . $indexFile; $link = preg_replace('/\\/+/', '/', $link); $deliverableLinks[] = call_user_func_array('sprintf', array($deliverableLinkTemplate, $link, $publicName)); } return implode(', ', $deliverableLinks); }
public function getContent(Xinc_Build_Interface $build) { $projectName = $build->getProject()->getName(); $url = './statistics/?project=' . $projectName; $click = 'appXinc.addNewTab(\'statistics-' . $projectName . '\',\'Statistics - ' . $projectName . '\',\'' . $url . '\');'; return '<a href="#" onclick="' . $click . '">Graphs</a>'; }
public function getContent(Xinc_Build_Interface $build) { $allBuildsTemplateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'allBuildsJs.phtml'); $allBuildsTemplate = file_get_contents($allBuildsTemplateFile); $content = str_replace(array('{projectname}', '{buildtime}'), array($build->getProject()->getName(), $build->getBuildTime()), $allBuildsTemplate); return $content; }
public function getContent(Xinc_Build_Interface $build) { $deliverableLinkTemplateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'deliverable-link.phtml'); $deliverableLinkTemplate = file_get_contents($deliverableLinkTemplateFile); $getDeliverableUrl = './api/deliverable/get/download/' . $build->getProject()->getName() . '/' . $build->getBuildTime() . '/'; $deliverableLinks = array(); $deliverables = $build->getInternalProperties()->get('deliverables'); if (!isset($deliverables['deliverables'])) { return false; } foreach ($deliverables['deliverables'] as $fileName => $fileLocation) { $publicName = $fileName; foreach ($deliverables['aliases'] as $alias => $realName) { if ($realName == $publicName) { $publicName = $alias; break; } } $link = $getDeliverableUrl . $publicName; $deliverableLinks[] = call_user_func_array('sprintf', array($deliverableLinkTemplate, $link, $publicName)); } return implode(', ', $deliverableLinks); }
public function publish(Xinc_Build_Interface $build) { $statusBefore = $build->getStatus(); $res = $this->plugin->email($build->getProject(), $this->_to, $this->_subject, $this->_message, $this->_from); }
/** * 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; }
public function getArtifacts(Xinc_Build_Interface $build) { $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir(); $projectName = $build->getProject()->getName(); $buildTimestamp = $build->getBuildTime(); $buildLabel = $build->getLabel(); $templateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'artifactsJs.phtml'); $template = file_get_contents($templateFile); $content = str_replace(array('{projectname}', '{buildtime}', '{buildlabel}'), array($projectName, $buildTimestamp, $buildLabel), $template); return $content; }
public function getTestResults(Xinc_Build_Interface $build) { require_once 'PEAR/Config.php'; $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir(); $projectName = $build->getProject()->getName(); $buildTimestamp = $build->getBuildTime(); $buildLabel = $build->getLabel(); $templateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'phpunit-summary.phtml'); $template = file_get_contents($templateFile); $url = '/phpunit/results/?project=' . $projectName . '&buildtime=' . $buildTimestamp . '&f=results.html'; $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 . 'summary.xsl'); try { $outputFileName = Xinc_Ini::getInstance()->get('tmp_dir', 'xinc') . DIRECTORY_SEPARATOR . 'phpunit_summary_' . $projectName . '_' . $buildTimestamp; } catch (Exception $e) { Xinc_Logger::getInstance()->error('Cannot get xinc.ini configuration'); $outputFileName = 'phpunit_summary_' . $projectName . '_' . $buildTimestamp; } if (file_exists($outputFileName)) { $summary = file_get_contents($outputFileName); } else { $summary = $this->_transformResults($sourceFile, $xslFile, $outputFileName); } //$click = 'openMenuTab(\'phpunit-'.$projectName.'-'.$buildTimestamp.'\',\'PHPUnit - '.$projectName.'\',\''.$url.'\',null,false,false,\'auto\');'; $detailsLink = '<a href="' . $url . '">Details</a>'; $content = str_replace(array('{detailsLink}', '{summary}'), array($detailsLink, $summary), $template); } else { $content = false; } return $content; }
/** * calling phing * * @param Xinc_Build_Interface $build * @param string $buildfile * @param string $target * @param string $extraParams * @param string $workingDir * * @return boolean */ public function build(Xinc_Build_Interface $build, $buildfile, $target, $extraParams = null, $workingDir = null) { //$phing = new Phing(); $logLevel = Xinc_Logger::getInstance()->getLogLevel(); $arguments = array(); switch ($logLevel) { case Xinc_Logger::LOG_LEVEL_VERBOSE: $arguments[] = '-verbose'; break; } $oldPwd = getcwd(); /** * set workingdir if not set from task, * use project dir */ if ($workingDir == null) { $workingDir = Xinc::getInstance()->getProjectDir() . DIRECTORY_SEPARATOR . $build->getProject()->getName(); } if (is_dir($workingDir)) { Xinc_Logger::getInstance()->debug('Switching to directory: ' . $workingDir); chdir($workingDir); } $logFile = getcwd() . DIRECTORY_SEPARATOR . md5($build->getProject()->getName() . time()) . '.log'; if (file_exists($logFile)) { unlink($logFile); } $arguments[] = '-logger'; //$arguments[] = 'phing.listener.DefaultLogger'; $arguments[] = 'phing.listener.NoBannerLogger'; $arguments[] = '-logfile'; $arguments[] = $logFile; $arguments[] = '-buildfile'; $arguments[] = $buildfile; if ($target != null) { $arguments[] = $target; } $arguments[] = '-Dxinc.buildlabel=' . $this->_encodeParam($build->getLabel()); $arguments[] = '-Dprojectname=' . $this->_encodeParam($build->getProject()->getName()); $arguments[] = '-Dcctimestamp=' . $this->_encodeParam($build->getBuildTime()); foreach ($build->getProperties()->getAllProperties() as $name => $value) { $arguments[] = '-Dxinc.' . $this->_encodeParam($name) . '=' . $this->_encodeParam($value); } try { $phingPath = Xinc_Ini::getInstance()->get('path', 'phing'); } catch (Exception $e) { $phingPath = null; } if (empty($phingPath)) { if (DIRECTORY_SEPARATOR != '/') { /** * windows has the phing command inside the bin_dir directory */ $phingPath = PEAR_Config::singleton()->get('bin_dir') . DIRECTORY_SEPARATOR . 'phing'; } else { $phingPath = 'phing'; } } if (DIRECTORY_SEPARATOR == '/') { $redirect = "2>&1"; } else { $redirect = ""; } $command = $phingPath . ' ' . implode(' ', $arguments) . ' ' . $extraParams . ' ' . $redirect; exec($command, $output, $returnValue); chdir($oldPwd); $buildSuccess = false; if (file_exists($logFile)) { $fh = fopen($logFile, 'r'); if (is_resource($fh)) { while ($line = fgets($fh)) { Xinc_Logger::getInstance()->info($line); if (strstr($line, "BUILD FINISHED")) { $buildSuccess = true; } } fclose($fh); } unlink($logFile); } if (count($output) > 0) { Xinc_Logger::getInstance()->error('Errors on command line:'); foreach ($output as $line) { Xinc_Logger::getInstance()->error($line); } } switch ($returnValue) { case 0: case 1: if ($buildSuccess) { return true; } else { $build->error('Phing command ' . $command . ' exited with status: ' . $returnValue); $build->setStatus(Xinc_Build_Interface::FAILED); return false; } break; case -1: case -2: $build->error('Phing build script: ' . $command . ' exited with status: ' . $returnValue); $build->setStatus(Xinc_Build_Interface::FAILED); return false; break; } return false; }
/** * Adds a build to the history file * * @param Xinc_Build_Interface $build * @param string $serialFileName * @throws Xinc_Build_History_Exception_General */ public static function addBuild(Xinc_Build_Interface &$build, $serialFileName) { $buildSuccess = $build->getStatus() == Xinc_Build_Interface::PASSED; $project = $build->getProject(); $metaFileArr = self::_loadMetaData($project->getName()); if (!isset($metaFileArr['meta'])) { self::_migrate($project->getName(), $metaFileArr); $metaFileArr = self::_loadMetaData($project->getName()); } if (count($metaFileArr['parts']) > 0) { $lastNo = count($metaFileArr['parts']) - 1; $lastPart = $metaFileArr['parts'][$lastNo]; $count = $lastPart['count']; if ($count >= self::PART_MAX) { $arr = array(); $arr[$build->getBuildTime()] = $serialFileName; try { $partFile = self::_writePartFile($project->getName(), $lastNo + 1, $arr); } catch (Xinc_Build_History_Exception_Storage $e1) { Xinc_Logger::getInstance()->error('Cannot write build history file for ' . $project->getName()); } $metaFileArr['parts'][] = array('no' => $lastNo + 1, 'count' => 1, 'filename' => $partFile, 'from' => $build->getBuildTime(), 'to' => $build->getBuildTime()); } else { $arr = self::_readPartFile($project->getName(), $lastNo); $arr[$build->getBuildTime()] = $serialFileName; $metaFileArr['parts'][$lastNo]['count']++; $metaFileArr['parts'][$lastNo]['to'] = $build->getBuildTime(); try { self::_writePartFile($project->getName(), $lastNo, $arr); } catch (Xinc_Build_History_Exception_Storage $e1) { Xinc_Logger::getInstance()->error('Cannot write build history file for ' . $project->getName()); } } } else { $arr = array(); $arr[$build->getBuildTime()] = $serialFileName; try { $partFile = self::_writePartFile($project->getName(), 0, $arr); } catch (Xinc_Build_History_Exception_Storage $e1) { Xinc_Logger::getInstance()->error('Cannot write build history file for ' . $project->getName()); $partFile = null; } $metaFileArr['parts'][] = array('no' => 0, 'count' => 1, 'filename' => $partFile, 'from' => $build->getBuildTime(), 'to' => $build->getBuildTime()); } try { $metaFileArr['lastSuccessfulBuild'] = array('filename' => $serialFileName, 'buildtime' => $build->getBuildTime()); self::_writeMetaData($project->getName(), $metaFileArr); } catch (Exception $e) { Xinc_Logger::getInstance()->error($e->getMessage() . '; Project: ' . $project->getName()); } }