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); }
/** * Copies a file into a special test results directory for the build and * parse the xml file to generate statistics * * @param Xinc_Build_Interface $build The actuall build. * @param string $sourceFile The xml file to read out. * * @return boolean True if registering was ok, false if it failed. */ public function registerResults(Xinc_Build_Interface $build, $sourceFile) { $statusDir = Xinc::getInstance()->getStatusDir(); $projectDir = Xinc::getInstance()->getProjectDir(); $subDir = $build->getStatusSubDir(); $fullDir = $statusDir . DIRECTORY_SEPARATOR . $subDir . DIRECTORY_SEPARATOR . self::TESTRESULTS_DIR; $targetFile = $fullDir . DIRECTORY_SEPARATOR . basename($sourceFile); /** * Verify that the source is in the projectdir */ $relativePath = str_replace($projectDir, '', $sourceFile); if ($relativePath == $sourceFile) { /** * the filename was not within the project path, * we need to prevent this file from being copied. * * Future: run Xinc in a chroot environment per project */ $build->error('Registering test results: ' . $sourceFile . '->' . $targetFile . ' failed.'); $build->error('-- ' . $sourceFile . ' is not within project dir. Security Problem.'); return false; } if (!file_exists($fullDir)) { mkdir($fullDir, 0755, true); } if (is_dir($sourceFile)) { if (DIRECTORY_SEPARATOR == '\\') { exec('xcopy /E /Y /I ' . $sourceFile . ' ' . $targetFile, $out, $res); //chmod($targetFile, 0755); } else { exec('cp -Rf ' . $sourceFile . ' ' . $targetFile, $out, $res); } if ($res == 0) { $status = 'OK'; } else { $status = 'FAILURE'; } } elseif (is_file($sourceFile)) { $res = copy($sourceFile, $targetFile); if ($res) { chmod($targetFile, 0755); $status = 'OK'; /** * register statistics */ $build->getInternalProperties()->set('phpunit.file', $targetFile); $this->generateStats($build, $targetFile); } else { $status = 'FAILURE'; } } else { $build->error('The phpunit file ' . $sourceFile . ' couldn\'t be read.'); return false; } $build->info('Registering test results: ' . $sourceFile . '->' . $targetFile . ', result: ' . $status); return $res; }
/** * Copies a file into a special artifacts directory for the build * * @param Xinc_Build_Interface $build * @param string $sourceFile * * @return boolean */ public function registerDeliverable(Xinc_Build_Interface $build, $sourceFile, $alias = null) { $build->debug('Trying to register deliverable: ' . $sourceFile); $sourceFile = realpath($sourceFile); $alias = basename($alias); $statusDir = Xinc::getInstance()->getStatusDir(); $projectDir = Xinc::getInstance()->getProjectDir(); $subDir = $build->getStatusSubDir(); $fullDir = self::getDeliverableDir($build); $targetFile = $fullDir . DIRECTORY_SEPARATOR . basename($sourceFile); /** * Verify that the source is in the projectdir */ $relativePath = str_replace($projectDir, '', $sourceFile); if ($relativePath == $sourceFile) { /** * the filename was not within the project path, * we need to prevent this file from being copied. * * Future: run Xinc in a chroot environment per project */ $build->error('Registering deliverable: ' . $sourceFile . '->' . $targetFile . ' failed.'); $build->error('-- ' . $sourceFile . ' is not within project dir. Security Problem.'); return false; } if (!file_exists($fullDir)) { mkdir($fullDir, 0755, true); } if (is_dir($sourceFile)) { $res = false; $status = 'FAILURE'; $build->info('Registering deliverable: ' . $sourceFile . ' failed, cannot register a directory as a deliverable'); } else { $res = copy($sourceFile, $targetFile); if ($res) { chmod($targetFile, 0755); $status = 'OK'; $deliverables = $build->getInternalProperties()->get('deliverables'); if (!is_array($deliverables)) { $deliverables = array(array('deliverables' => array()), array('aliases' => array())); } $deliverableFilename = basename($targetFile); if (!isset($deliverables['deliverables'])) { $deliverables['deliverables'] = array(); } if (!isset($deliverables['aliases'])) { $deliverables['aliases'] = array(); } $deliverables['deliverables'][$deliverableFilename] = $targetFile; if ($alias != null) { if (!isset($deliverables['aliases'])) { $deliverables['aliases'] = array(); } $deliverables['aliases'][$alias] = $deliverableFilename; } $build->getInternalProperties()->set('deliverables', $deliverables); } else { $status = 'FAILURE'; } } $build->info('Registering deliverable: ' . $sourceFile . '->' . $targetFile . ', result: ' . $status); return $res; }
/** * Copies a file into a special artifacts directory for the build * * @param Xinc_Build_Interface $build * @param string $sourceFile * @param string $alias * @param string $index * * @return boolean */ public function registerDocumentation(Xinc_Build_Interface $build, $sourceFile, $alias, $index) { $build->debug('Trying to register documentation: ' . $sourceFile); $sourceFile = realpath($sourceFile); $alias = basename($alias); $statusDir = Xinc::getInstance()->getStatusDir(); $projectDir = Xinc::getInstance()->getProjectDir(); $sourceFile = preg_replace('/\\/+/', '/', $sourceFile); $index = preg_replace('/\\/+/', '/', $index); $relativeIndex = str_replace($sourceFile, '', $index); $subDir = $build->getStatusSubDir(); $fullDir = self::getDocumentationDir($build); $targetDir = $fullDir . DIRECTORY_SEPARATOR . basename($alias); $targetFile = $targetDir . DIRECTORY_SEPARATOR . basename($sourceFile); if (!is_dir($targetDir)) { mkdir($targetDir, 0755, true); } /** * Verify that the source is in the projectdir */ $relativePath = str_replace($projectDir, '', $sourceFile); if ($relativePath == $sourceFile) { /** * the filename was not within the project path, * we need to prevent this file from being copied. * * Future: run Xinc in a chroot environment per project */ $build->error('Registering doc: ' . $sourceFile . '->' . $targetFile . ' failed.'); $build->error('-- ' . $sourceFile . ' is not within project dir. Security Problem.'); return false; } if (!file_exists($fullDir)) { mkdir($fullDir, 0755, true); } if (is_dir($sourceFile)) { $relativePath = str_replace($sourceFile, '', $index); if ($relativePath == $index) { /** * the index file was not within the doc path, * we need to prevent this file from being copied. * * Future: run Xinc in a chroot environment per project */ $build->error('Registering doc: ' . $sourceFile . '->' . $targetFile . ' failed.'); $build->error('-- ' . $index . ' is not within ' . $sourceFile . ' dir. Security Problem.'); return false; } if (DIRECTORY_SEPARATOR == '\\') { exec('xcopy /E /Y /I ' . escapeshellarg($sourceFile . '\\*') . ' ' . escapeshellarg($targetDir), $out, $res1); } else { exec('cp -Rf ' . escapeshellarg($sourceFile) . '/. ' . escapeshellarg($targetDir), $out, $res1); } $res = false; if ($res1 == 0) { $status = 'OK'; $res = true; } else { $status = 'FAILURE'; $res = false; } $targetIndexFile = $targetDir . DIRECTORY_SEPARATOR . $relativeIndex; $registerFile = $targetDir; } else { $res = copy($sourceFile, $targetFile); $targetIndexFile = $targetFile; $registerFile = $targetFile; } if ($res) { chmod($targetDir, 0755); $status = 'OK'; $docs = $build->getInternalProperties()->get('documentation'); if (!is_array($docs)) { $docs = array(); } $docsDir = dirname($targetFile); $docs[$alias] = array('file' => $registerFile, 'index' => $targetIndexFile); $build->getInternalProperties()->set('documentation', $docs); } else { $status = 'FAILURE'; } $build->info('Registering documentation: ' . $sourceFile . '->' . $targetFile . ', result: ' . $status); return $res; }