Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
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;
     }
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
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.');
     }
 }
Exemplo n.º 6
0
 public function set(Xinc_Build_Interface $build, $value)
 {
     $newvalue = $build->getProperties()->parseString($value);
     return $newvalue;
 }
Exemplo n.º 7
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);
     }
 }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
0
 /**
  * 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;
 }