예제 #1
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;
 }
예제 #2
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);
     }
 }
예제 #3
0
 public function process(Xinc_Build_Interface $build)
 {
     $build->debug('Setting property "${' . $this->_name . '}" to "' . $this->_value . '"');
     //$build->getProperties()->set($this->_name, $this->_value);
 }
예제 #4
0
 /**
  * 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;
 }