Example #1
0
 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>';
 }
Example #2
0
 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);
 }
Example #3
0
 /**
  * Checks whether the Subversion project has been modified.
  *
  * @param Xinc_Build_Interface                       $build The running build.
  * @param Xinc_Plugin_Repos_ModificationSet_Svn_Task $task  The configured task
  *
  * @return Xinc_Plugin_Repos_ModificationSet_Result The result of the check.
  */
 public function checkModified(Xinc_Build_Interface $build, Xinc_Plugin_Repos_ModificationSet_Svn_Task $task)
 {
     $result = new Xinc_Plugin_Repos_ModificationSet_Result();
     try {
         $this->task = $task;
         $this->svn = VersionControl_SVN::factory(array('info', 'log', 'status', 'update'), array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC, 'username' => $task->getUsername(), 'password' => $task->getPassword(), 'trustServerCert' => $task->trustServerCert()));
         $strRemoteVersion = $this->getRemoteVersion();
         $strLocalVersion = $this->getLocalVersion();
     } catch (VersionControl_SVN_Exception $e) {
         $build->error('Test of Subversion failed: ' . $e->getMessage());
         $build->setStatus(Xinc_Build_Interface::FAILED);
         $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR);
         return $result;
     }
     $result->setRemoteRevision($strRemoteVersion);
     $result->setLocalRevision($strLocalVersion);
     if ($strRemoteVersion !== $strLocalVersion) {
         try {
             $this->getModifiedFiles($result);
             $this->getChangeLog($result);
             if ($this->task->doUpdate()) {
                 $this->update($result);
             }
             $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED);
         } catch (Exception $e) {
             var_dump($e->getMessage());
             $build->error('Processing SVN failed: ' . $e->getMessage());
             $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED);
         }
     }
     return $result;
 }
Example #4
0
 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;
 }
Example #5
0
 /**
  * Check if this modification set has been modified
  *
  * @param Xinc_Build_Interface                       $build The running build.
  * @param Xinc_Plugin_Repos_ModificationSet_Git_Task $task  The configured task
  *
  * @return Xinc_Plugin_Repos_ModificationSet_Result The result of the check.
  */
 public function checkModified(Xinc_Build_Interface $build, Xinc_Plugin_Repos_ModificationSet_Git_Task $task)
 {
     $result = new Xinc_Plugin_Repos_ModificationSet_Result();
     try {
         $this->git = new VersionControl_Git($task->getDirectory());
         $strBranch = $this->git->getCurrentBranch();
         $strRemoteHash = $this->getRemoteHash($strBranch);
         $strLocalHash = $this->getLocalHash($strBranch);
     } catch (Exception $e) {
         $build->error('Test of GIT Repos failed: ' . $e->getMessage());
         $build->setStatus(Xinc_Build_Interface::FAILED);
         $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED);
         return $result;
     }
     $result->setRemoteRevision($strRemoteHash);
     $result->setLocalRevision($strLocalHash);
     if ($strRemoteHash !== $strLocalHash) {
         $this->fetch();
         $this->getModifiedFiles($result);
         $this->getChangeLog($result);
         if ($task->getUpdate()) {
             try {
                 $this->update();
             } catch (Exception $e) {
                 $build->error('Update of GIT local failed: ' . $e->getMessage());
                 $result > setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED);
                 return $result;
             }
         }
         $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED);
     }
     return $result;
 }
Example #6
0
 private function _handleBuildConfig(Xinc_Build_Interface $build)
 {
     $timezone = $build->getConfigDirective('timezone');
     if ($timezone !== null) {
         Xinc_Timezone::set($timezone);
     } else {
         Xinc_Timezone::reset();
     }
 }
Example #7
0
 public function process(Xinc_Build_Interface $build)
 {
     $build->info('Processing publishers');
     foreach ($this->arSubtasks as $task) {
         $task->publish($build);
     }
     $build->info('Processing publishers done');
     //$project->setStatus(Xinc_Project_Build_Status_Interface::STOPPED);
 }
Example #8
0
 /**
  * Return the label for this build
  *
  * @param Xinc_Build_Interface $build
  *
  * @return string
  */
 public function getLabel(Xinc_Build_Interface $build)
 {
     $buildNo = $build->getNumber();
     if ($buildNo == null) {
         $buildNo = $this->_firstBuild;
     }
     $buildLabel = $this->_prefix . $buildNo;
     $build->getProperties()->set('build.label', $buildLabel);
     return $buildLabel;
 }
Example #9
0
 /**
  * Calculates the next build timestamp
  * this is a build once scheduler
  *
  * @return integer
  */
 public function getNextBuildTime(Xinc_Build_Interface $build)
 {
     if ($build->getLastBuild()->getBuildTime() == null && $build->getStatus() !== Xinc_Build_Interface::STOPPED) {
         if (!isset($this->nextBuildTime)) {
             $this->nextBuildTime = time();
         }
         return $this->nextBuildTime;
     } else {
         return null;
     }
 }
Example #10
0
 public function process(Xinc_Build_Interface $build)
 {
     $build->info('Processing builders');
     foreach ($this->arSubtasks as $task) {
         $task->process($build);
         if ($build->getStatus() != Xinc_Build_Interface::PASSED) {
             $build->error('Build FAILED ');
             return;
         }
     }
     $build->info('Processing builders done');
     //$project->setStatus(Xinc_Build_Interface::STOPPED);
 }
Example #11
0
 public function publish(Xinc_Build_Interface $build)
 {
     /**
      * We only process on success. 
      * Failed builds are not processed by this publisher
      */
     if ($build->getStatus() != Xinc_Build_Interface::PASSED) {
         return;
     }
     /**
      * Only if we recovered from a previous failed build cycle
      */
     $build->info('Last Build status: ' . $build->getLastBuild()->getStatus());
     if ($build->getLastBuild()->getStatus() !== 0) {
         return;
     }
     $published = false;
     $build->info('Publishing with OnRecovery Publishers');
     foreach ($this->arSubtasks as $task) {
         $published = true;
         $build->info('Publishing with OnRecovery Publisher: ' . get_class($task));
         $task->publish($build);
         if ($build->getStatus() != Xinc_Build_Interface::PASSED) {
             $build->error('Error while publishing on Recovery. OnRecovery-Publish-Process stopped');
             break;
         }
     }
     if (!$published) {
         $build->info('No Publishers registered for OnRecovery');
     }
 }
Example #12
0
 /**
  * Copies a file into a special artifacts directory for the build
  *
  * @param Xinc_Build_Interface $build
  * @param string $sourceFile
  *
  * @return boolean
  */
 public function registerArtifact(Xinc_Build_Interface $build, $sourceFile)
 {
     $sourceFile = realpath($sourceFile);
     $statusDir = Xinc::getInstance()->getStatusDir();
     $projectDir = Xinc::getInstance()->getProjectDir();
     $subDir = $build->getStatusSubDir();
     $fullDir = self::getArtifactsDir($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 artifact: ' . $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';
         }
     } else {
         $res = copy($sourceFile, $targetFile);
         if ($res) {
             chmod($targetFile, 0755);
             $status = 'OK';
         } else {
             $status = 'FAILURE';
         }
     }
     $build->info('Registering artifact: ' . $sourceFile . '->' . $targetFile . ', result: ' . $status);
     return $res;
 }
Example #13
0
 public function getContent(Xinc_Build_Interface $build)
 {
     $changeSet = $build->getProperties()->get('changeset');
     if ($changeSet instanceof Xinc_Plugin_Repos_ModificationSet_Result) {
         if (!$changeSet->isChanged()) {
             return false;
         }
         $templateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'modifications.phtml');
         $templateContent = file_get_contents($templateFile);
         $templateContent = str_replace(array('{previous_revision}', '{current_revision}', '{files_modified}', '{files_added}', '{files_deleted}', '{files_merged}', '{files_conflicted}'), array($changeSet->getLocalRevision(), $changeSet->getRemoteRevision(), count($changeSet->getUpdatedResources()), count($changeSet->getNewResources()), count($changeSet->getDeletedResources()), count($changeSet->getMergedResources()), count($changeSet->getConflictResources())), $templateContent);
         return $templateContent;
     } else {
         return false;
     }
 }
Example #14
0
 /**
  * Generates a short list with number of files, warnings and errors.
  *
  * @return string HTML string
  */
 public function getTestResults(Xinc_Build_Interface $build)
 {
     $numberOfFiles = $build->getStatistics()->get('checkstyle.numberOfFiles');
     if (null !== $numberOfFiles) {
         $numberOfWarnings = $build->getStatistics()->get('checkstyle.numberOfWarnings');
         $numberOfErrors = $build->getStatistics()->get('checkstyle.numberOfErrors');
         $content = $this->box('info', 'Number of files: ' . $numberOfFiles);
         if ($numberOfWarnings > 0) {
             $content .= $this->box('warning', 'Warnings: ' . $numberOfWarnings);
         }
         if ($numberOfErrors > 0) {
             $content .= $this->box('error', 'Errors: ' . $numberOfErrors);
         }
         return $content;
     } else {
         return false;
     }
 }
Example #15
0
 public function getContent(Xinc_Build_Interface $build)
 {
     $changeSet = $build->getProperties()->get('changeset');
     if ($changeSet instanceof Xinc_Plugin_Repos_ModificationSet_Result) {
         $logMessageTemplateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'modification_log_row.phtml');
         $logMessageTemplateContent = file_get_contents($logMessageTemplateFile);
         $logMessagesArr = array();
         $logMessages = $changeSet->getLogMessages();
         if (count($logMessages) == 0) {
             return false;
         }
         foreach ($logMessages as $log) {
             $xpandable = '';
             $logMessageString = $log['message'];
             $newLogString = '';
             for ($i = 0; $i < strlen($logMessageString); $i = $i + 60) {
                 $newLogString .= substr($logMessageString, $i, 60) . "<br/>";
             }
             $logMessageString = $newLogString;
             if (strlen($logMessageString) > 80) {
                 $xpandable = 'expandable';
                 $logMessageDiv = '<div class="mdesc">
                     <div class="short">' . substr($logMessageString, 0, 60) . ' ...</div>
         <div class="long">';
                 $logMessageDiv .= $logMessageString;
                 $logMessageDiv .= '</div>
                     </div>';
             } else {
                 $logMessageDiv = '<div class="mdesc">';
                 $logMessageDiv .= $logMessageString;
                 $logMessageDiv .= '</div>';
             }
             $logContent = str_replace(array('{author}', '{revision}', '{message}', '{expandable}'), array($log['author'], $log['revision'], $logMessageDiv, $xpandable), $logMessageTemplateContent);
             $logMessagesArr[] = $logContent;
         }
         $templateFile = Xinc_Data_Repository::getInstance()->getWeb('templates' . DIRECTORY_SEPARATOR . 'dashboard' . DIRECTORY_SEPARATOR . 'detail' . DIRECTORY_SEPARATOR . 'extension' . DIRECTORY_SEPARATOR . 'modification_log.phtml');
         $templateContent = file_get_contents($templateFile);
         $templateContent = str_replace(array('{logmessages}'), array(implode('', $logMessagesArr)), $templateContent);
         return $templateContent;
     } else {
         return false;
     }
 }
Example #16
0
 /**
  * loads properties from a property file
  * 
  * @param Xinc_Build_Interface $build
  * @param string $fileName
  */
 public function parsePropertyFile(Xinc_Build_Interface $build, $fileName)
 {
     $activeProperty = false;
     $trimNextLine = false;
     $arr = array();
     $fh = fopen($fileName, 'r');
     if (is_resource($fh)) {
         while ($line = fgets($fh)) {
             if (preg_match('/^[!#].*/', $line)) {
                 // comment
             } else {
                 if (preg_match("/^.*?([\\._-\\w]+?)\\s*[=:]+\\s*(.*)\$/", $line, $matches)) {
                     // we have a key definition
                     $activeProperty = true;
                     $key = $matches[1];
                     $valuePart = $matches[2];
                     $arr[$key] = trim($valuePart);
                     if ($arr[$key][strlen($arr[$key]) - 1] == '\\') {
                         $arr[$key] = substr($arr[$key], 0, -1);
                         $trimNextLine = true;
                     } else {
                         $trimNextLine = false;
                     }
                 } else {
                     if ($activeProperty) {
                         $trimmed = trim($line);
                         if (empty($trimmed)) {
                             $activeProperty = false;
                             continue;
                         } else {
                             if ($trimNextLine) {
                                 $line = $trimmed;
                             } else {
                                 $line = rtrim($line);
                             }
                         }
                         $arr[$key] .= "\n" . $line;
                         if ($arr[$key][strlen($arr[$key]) - 1] == '\\') {
                             $arr[$key] = substr($arr[$key], 0, -1);
                             $trimNextLine = true;
                         } else {
                             $trimNextLine = false;
                         }
                     }
                 }
             }
         }
         foreach ($arr as $key => $value) {
             $build->debug('Setting property "${' . $key . '}" to "' . $value . '"');
             $build->getProperties()->set($key, stripcslashes($value));
         }
     } else {
         $build->error('Cannot read from property file: ' . $fileName);
     }
 }
Example #17
0
 public function publish(Xinc_Build_Interface $build)
 {
     /**
      * We only process on failure. 
      * Successful builds are not processed by this publisher
      */
     if ($build->getStatus() != Xinc_Build_Interface::FAILED) {
         return;
     }
     $published = false;
     $build->info('Publishing with OnFailure Publishers');
     foreach ($this->arSubtasks as $task) {
         $published = true;
         $build->info('Publishing with OnFailure Publisher: ' . get_class($task));
         $task->publish($build);
     }
     if (!$published) {
         $build->info('No Publishers registered OnFailure');
     }
 }
Example #18
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;
 }
Example #19
0
 /**
  * Generates statistsics and saves them into the build.
  *
  * @param Xinc_Build_Interface $build      The actuall build.
  * @param string               $sourceFile The xml file to read stats from.
  *
  * @return boolean True if registering was ok, false if it failed.
  */
 public function generateStats(Xinc_Build_Interface $build, $file)
 {
     try {
         /**
          * @var string Contains content of the XML file
          */
         $strContent = file_get_contents($file);
         if ('' !== $strContent) {
             $arStats = $this->parseXml($strContent);
             /**
              * set the statistics data
              */
             foreach ($arStats as $strName => $mValue) {
                 $build->getStatistics()->set('checkstyle.' . $strName, $mValue);
             }
         }
     } catch (Exception $e) {
         Xinc_Logger::getInstance()->error('Could not parse checkstyle xml: ' . $e->getMessage() . "\n" . 'Trace: ' . $e->getTraceAsString());
         return false;
     }
     return true;
 }
Example #20
0
 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);
 }
Example #21
0
 public function publish(Xinc_Build_Interface $build)
 {
     /**
      * We only process on success. 
      * Failed builds are not processed by this publisher
      */
     if ($build->getStatus() != Xinc_Build_Interface::PASSED) {
         return;
     }
     $published = false;
     $build->info('Publishing with OnSuccess Publishers');
     foreach ($this->arSubtasks as $task) {
         $published = true;
         $build->info('Publishing with OnSuccess Publisher: ' . get_class($task));
         $task->publish($build);
         if ($build->getStatus() != Xinc_Build_Interface::PASSED) {
             $build->error('Error while publishing on Success. OnSuccess-Publish-Process stopped');
             break;
         }
     }
     if (!$published) {
         $build->info('No Publishers registered OnSuccess');
     }
 }
Example #22
0
 public function publish(Xinc_Build_Interface $build)
 {
     $statusBefore = $build->getStatus();
     $res = $this->plugin->email($build->getProject(), $this->_to, $this->_subject, $this->_message, $this->_from);
 }
Example #23
0
 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;
 }
Example #24
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;
 }
Example #25
0
 /**
  * Sorts the builds in the queue by buildtime.
  *
  * @param Xinc_Build_Interface $a
  * @param Xinc_Build_Interface $b
  *
  * @return int
  */
 public function sortQueue($a, $b)
 {
     $buildTimeA = $a->getNextBuildTime();
     $buildTimeB = $b->getNextBuildTime();
     if ($buildTimeA == $buildTimeB) {
         return 0;
     }
     return $buildTimeA < $buildTimeB ? -1 : 1;
 }
Example #26
0
 /**
  * The parent builder task will call this method
  *
  * @param Xinc_Build_Interface $build
  *
  * @return boolean
  */
 public function build(Xinc_Build_Interface $build)
 {
     if ($this->_if !== null) {
         $build->info('Checking condidition property: ' . $this->_if);
         $ifProp = $build->getProperties()->get($this->_if);
         if ($ifProp === true) {
             $build->info('--' . $this->_if . ' == true --> building');
             return $this->plugin->build($build, $this->_buildFile, $this->_target, $this->_params, $this->_workingDir);
         } else {
             $build->info('--' . $this->_if . ' == false --> not building');
             return true;
         }
     } else {
         return $this->plugin->build($build, $this->_buildFile, $this->_target, $this->_params, $this->_workingDir);
     }
 }
Example #27
0
 /**
  * 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;
 }
Example #28
0
 public function checkModified(Xinc_Build_Interface $build, $dir, $prefix, $switch = false, $svnFolderProperty = null)
 {
     $modResult = new Xinc_Plugin_Repos_ModificationSet_Result();
     if (!file_exists($dir)) {
         $build->error('Subversion checkout directory not present');
         $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR);
         return $modResult;
     }
     $cwd = getcwd();
     chdir($dir);
     $output = '';
     $result = 9;
     exec($this->_svnPath . ' info', $output, $result);
     $found = false;
     if ($result == 0) {
         $localSet = implode("\n", $output);
         $localRev = $this->getRevision($localSet);
         $remoteRev = 0;
         $url = $this->getRootURL();
         $output = '';
         $result = 9;
         exec($this->_svnPath . ' ls --xml ' . $url . '/' . $this->_getSvnSubDir(), $output, $result);
         $remoteSet = implode("\n", $output);
         if ($result != 0) {
             $build->setStatus(Xinc_Build_Interface::FAILED);
             $build->error('Problem with remote Subversion repository');
             $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR);
             return $modResult;
         }
         $xml = new SimplexmlElement($remoteSet);
         foreach ($xml->list as $i => $list) {
             foreach ($list->entry as $entry) {
                 if (substr($entry->name, 0, strlen($prefix)) != $prefix && !preg_match('/' . $prefix . '/', $entry->name)) {
                     continue;
                 }
                 $attributes = $entry->attributes();
                 if (strtolower((string) $attributes['kind']) != 'dir') {
                     continue;
                 }
                 $attributes = $entry->commit->attributes();
                 $rev = (int) $attributes->revision;
                 if ($rev > $localRev) {
                     $tagName = (string) $entry->name;
                     if ($svnFolderProperty != null) {
                         $build->getProperties()->set($svnFolderProperty, $tagName);
                     }
                     // switch to the latest release
                     if ($switch) {
                         exec($this->_svnPath . ' switch ' . $url . '/' . $this->_getSvnSubDir() . '/' . $tagName, $switchOut, $switchRes);
                         if ($switchRes != 0) {
                             $build->error('Could not switch to tag :' . $tagName . ', result:' . implode("\n", $switchOut));
                             $build->setStatus(Xinc_Build_Interface::FAILED);
                             $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED);
                             return $modResult;
                         }
                     }
                     $remoteRev = $rev;
                     $found = true;
                 }
             }
         }
         if ($remoteRev <= 0) {
             $build->info('Subversion checkout dir is ' . $dir . ' ' . 'local revision @ ' . $localRev . ' ' . 'No remote revision with matching tag prefix (' . $prefix . ')');
         } else {
             $build->info('Subversion checkout dir is ' . $dir . ' ' . 'local revision @ ' . $localRev . ' ' . 'Last remote revision with matching tag prefix @ ' . $remoteRev . ' (' . $prefix . ')');
         }
         chdir($cwd);
         $modResult->setLocalRevision($localRev);
         $modResult->setRemoteRevision($remoteRev);
         if ($modResult->isChanged()) {
             $modResult->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED);
         }
         return $modResult;
     } else {
         chdir($cwd);
         throw new Xinc_Exception_ModificationSet('Subversion checkout directory ' . 'is not a working copy.');
     }
 }
Example #29
0
 public function process(Xinc_Build_Interface $build)
 {
     if ($this->_if !== null) {
         /**
          * If we have a condition, we need to check
          */
         $property = $build->getProperties()->get($this->_if);
         if ($property !== true) {
             $build->info('Property: ' . $this->_name . ' does not apply, ' . $this->_if . ' == false');
             $build->setStatus(Xinc_Build_Interface::PASSED);
             return;
         }
     }
     if (isset($this->_file)) {
         if (file_exists($this->_file)) {
             $build->info('Reading property file: ' . $this->_file);
             $this->plugin->parsePropertyFile($build, $this->_file);
         } else {
             if (strstr($this->_file, '${')) {
                 // not substituted yet, will not use it
             } else {
                 $build->error('Cannot read property file: ' . $this->_file);
             }
         }
     } else {
         $build->debug('Setting property "${' . $this->_name . '}" to "' . $this->_value . '"');
         $build->getProperties()->set($this->_name, $this->_value);
         $build->setStatus(Xinc_Build_Interface::PASSED);
     }
 }
 public function set(Xinc_Build_Interface $build, $value)
 {
     $newvalue = $build->getProperties()->parseString($value);
     return $newvalue;
 }