/**
  * 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;
 }
Ejemplo n.º 2
0
 public function testWillFailOnMissingConfigFile()
 {
     try {
         $args = explode(' ', $this->_arguments['missingParameter']);
         $arguments = Xinc_Config_Getopt::getopt($args, Xinc::getShortOptions(), Xinc::getLongOptions());
     } catch (Exception $e) {
         return true;
     }
     $this->assertTrue(false, 'Should have thrown a missing config file exception');
 }
Ejemplo n.º 3
0
 /**
  * Gets a build defined by its project name and buildTime
  *
  * @param string $projectName
  * @param integer $buildTime
  * @throws Xinc_Build_Exception_Unserialization
  * @throws Xinc_Build_Exception_NotFound
  * @return Xinc_Build_Interface
  */
 public static function getBuild(Xinc_Project $project, $buildTime)
 {
     $statusDir = null;
     if (class_exists('Xinc_Gui_Handler')) {
         $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
     } else {
         if (class_exists('Xinc')) {
             $statusDir = Xinc::getInstance()->getStatusDir();
         }
     }
     return Xinc_Build::unserialize($project, $buildTime, $statusDir);
 }
Ejemplo n.º 4
0
 public function testRegisterDocumentationFile()
 {
     try {
         $this->sharedFixture[1]->registerDocumentation($this->sharedFixture[0], $this->sharedFixture[2] . DS . 'test.html', 'test', $this->sharedFixture[2] . DS . 'sub' . DS . 'index.html');
     } catch (Exception $e) {
         var_dump($e);
     }
     $statusDir = Xinc::getInstance()->getStatusDir();
     $documentationDir = $statusDir . DS . $this->sharedFixture[0]->getStatusSubDir() . DS . 'documentation' . DS . 'test' . DS . 'test.html';
     $documentationDir = realpath($documentationDir);
     $docProp = $this->sharedFixture[0]->getInternalProperties()->get('documentation');
     //var_dump($docProp);
     $compareDir1 = $docProp['test']['file'];
     $compareDir = realpath($compareDir1);
     $this->assertEquals($documentationDir, $compareDir, 'Files should be equal: ' . $documentationDir . '<>' . $compareDir1);
 }
Ejemplo n.º 5
0
 /**
  * Validate if all information the task needs to run
  * properly have been set
  *
  * @return boolean
  */
 public function validateTask()
 {
     // validate if buildfile exists
     // try in working dir
     $workingdir = Xinc::getInstance()->getWorkingDir();
     $file2 = $workingdir . DIRECTORY_SEPARATOR . $this->_buildFile;
     $file = $this->_buildFile;
     if (!file_exists($file) && !file_exists($file2)) {
         Xinc_Logger::getInstance()->error('Build-File ' . $file . ' does not exist');
         return false;
     } else {
         if (file_exists($file2)) {
             $this->_buildFile = $file2;
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     if (!self::$registered) {
         stream_wrapper_register("xinclogger", "Xinc_StreamLogger") or die("Failed to register protocol");
         $cwd = dirname(dirname(dirname(__FILE__)));
         $testDir = '"' . $cwd . '"';
         $configFile = '"' . $cwd . '/resources/testSystem.xml"';
         $statusDir = '"' . $cwd . '"';
         $debug = Xinc_Logger::LOG_LEVEL_DEBUG;
         $commandLine = "-s {$statusDir} -w {$testDir} -p {$testDir} -f {$configFile} -l xinclogger://test -o -v {$debug}";
         //echo $commandLine;
         Xinc::main($commandLine);
         //Xinc::getInstance()->setStatusDir($testDir);
         //Xinc_Logger::getInstance()->setXincLogFile("xinclogger://test");
         //Xinc_Logger::getInstance()->setBuildLogFile("xinclogger://test");
         //Xinc_Logger::getInstance()->setLogLevel(Xinc_Logger::LOG_LEVEL_DEBUG);
         self::$registered = true;
     }
 }
Ejemplo n.º 7
0
 /**
  * Validates if a task can run by checking configs, directries and so on.
  *
  * @return boolean Is true if task can run.
  */
 public function validateTask()
 {
     if (!class_exists('VersionControl_SVN')) {
         throw new Xinc_Exception_MalformedConfig('PEAR::VersionControl_SVN doesn\'t exists. You need to install it to use this task.');
     }
     if (!isset($this->strDirectory)) {
         throw new Xinc_Exception_MalformedConfig('Element modificationSet/svn - required attribute "directory" is not set.');
     }
     $file = $this->strDirectory;
     $file2 = Xinc::getInstance()->getWorkingDir() . DIRECTORY_SEPARATOR . $file;
     if (!file_exists($file) && !file_exists($file2)) {
         Xinc_Logger::getInstance()->error('Directory ' . $file2 . ' does not exist.');
         return false;
     } elseif (file_exists($file2)) {
         $this->strDirectory = $file2;
     }
     return true;
 }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 /**
  * Parses the projects xml
  * loads all the tasks
  * assigns them to the builds
  *
  * @param Xinc\Core\Project\Iterator $projects
  *
  * @return array the builds
  */
 public function parseProjectOld($project)
 {
     $builds = array();
     //         $this->setters = Xinc_Plugin_Repository::getInstance()
     //             ->getTasksForSlot(Xinc_Plugin_Slot::PROJECT_SET_VALUES);
     $build = null;
     /**
      * trying to recover the last build information
      */
     try {
         $build = \Xinc\Core\Build::unserialize($project);
         $build->setBuildTime(null);
         $build->resetConfigDirective();
     } catch (Xinc_Build_Exception_NotFound $e) {
         Xinc_Logger::getInstance()->info('No status data found for ' . $project->getName());
     } catch (Exception $e) {
         Xinc_Logger::getInstance()->error('Could not unserialize old status of ' . $project->getName());
     }
     $projectXml = $project->getConfig();
     if (!$build instanceof Xinc_Build_Interface) {
         $build = new Xinc_Build($this->engine, $project);
     }
     $build->getProperties()->set('project.name', $project->getName());
     $build->getProperties()->set('build.number', $build->getNumber());
     $build->getProperties()->set('build.label', $build->getLabel());
     $builtinProps = Xinc::getInstance()->getBuiltinProperties();
     foreach ($builtinProps as $prop => $value) {
         $build->getProperties()->set($prop, $value);
     }
     $taskRegistry = new Xinc_Build_Tasks_Registry();
     $this->_parseTasks($build, $projectXml, $taskRegistry);
     $build->setTaskRegistry($taskRegistry);
     $build->process(Xinc_Plugin_Slot::PROJECT_INIT);
     if (!$build->haveScheduler()) {
         // set default scheduler
         $scheduler = new Xinc_Build_Scheduler_Default();
         $build->addScheduler($scheduler);
     }
     $labeler = $build->getLabeler();
     if ($labeler == null) {
         // set default scheduler
         $labeler = new Xinc_Build_Labeler_Default();
         $build->setLabeler($labeler);
     }
     $builds[] = $build;
     return $builds;
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
0
 /**
  * Clean up after a build is completed.
  *
  * @return void
  */
 private function endBuild()
 {
     $this->build = null;
     Xinc::getInstance()->restoreConfigDirectives();
 }
Ejemplo n.º 12
0
 /**
  * Validates if a task can run by checking configs, directries and so on.
  *
  * @return boolean Is true if task can run.
  */
 public function validateTask()
 {
     if (!isset($this->_directory)) {
         throw new Xinc_Exception_MalformedConfig('Element modificationSet/svntag - required attribute "directory" is not set');
     }
     if (!isset($this->_prefix)) {
         throw new Xinc_Exception_MalformedConfig('Element modificationSet/svntag - required attribute "prefix" is not set');
     }
     $file = $this->_directory;
     $file2 = Xinc::getInstance()->getWorkingDir() . DIRECTORY_SEPARATOR . $file;
     if (!file_exists($file) && !file_exists($file2)) {
         Xinc_Logger::getInstance()->error('Directory ' . $file2 . ' does not exist');
         return false;
     } elseif (file_exists($file2)) {
         $this->_directory = $file2;
     }
     return true;
 }
Ejemplo n.º 13
0
 /**
  *  Fired whenever a message is logged.
  *
  *  @param BuildEvent The BuildEvent
  *
  *  @see BuildEvent::getMessage()
  */
 public function messageLogged(BuildEvent $event)
 {
     $logger = Xinc_Logger::getInstance();
     /**
      * write to a temporary logfile
      * - which will be read afterwards and the logentries will
      * - be used to determine the status of the build
      */
     switch ($event->getPriority()) {
         case self::MSG_DEBUG:
         case self::MSG_VERBOSE:
             $logger->debug('[phing] ' . $event->getMessage());
             break;
         case self::MSG_INFO:
             $logger->info('[phing] ' . $event->getMessage());
             break;
         case self::MSG_WARN:
             $logger->warn('[phing] ' . $event->getMessage());
             break;
         case self::MSG_ERR:
             $logger->error('[phing] ' . $event->getMessage());
             Xinc::getCurrentBuild()->setStatus(Xinc_Build_Interface::FAILED);
             break;
     }
     $exception = $event->getException();
     if ($exception != null) {
         $logger->error('[phing] ' . $exception->getMessage());
         Xinc::getCurrentBuild()->setStatus(Xinc_Build_Interface::FAILED);
     }
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
0
 /**
  * returns the status dir
  *
  * @return string
  */
 private static function _getStatusDir()
 {
     $statusDir = null;
     $isGuiMode = false;
     $isXincMode = false;
     if (class_exists('Xinc_Gui_Handler')) {
         $handler = Xinc_Gui_Handler::getInstance();
         $isGuiMode = $handler instanceof Xinc_Gui_Handler;
     }
     if (class_exists('Xinc')) {
         $xinc = Xinc::getInstance();
         $isXincMode = $xinc instanceof Xinc;
     }
     if ($isGuiMode) {
         // we are in gui mode
         $statusDir = Xinc_Gui_Handler::getInstance()->getStatusDir();
     } else {
         if ($isXincMode) {
             $statusDir = Xinc::getInstance()->getStatusDir();
         } else {
             try {
                 $statusDir = Xinc_Ini::getInstance()->get('status_dir', 'xinc');
             } catch (Exception $e) {
                 $statusDir = null;
             }
         }
     }
     return $statusDir;
 }
Ejemplo n.º 16
0
 public function updateTasks()
 {
     $this->setters = Xinc_Plugin_Repository::getInstance()->getTasksForSlot(Xinc_Plugin_Slot::PROJECT_SET_VALUES);
     $this->setProperty('project.name', $this->getProject()->getName());
     $this->setProperty('build.number', $this->getNumber());
     $this->setProperty('build.label', $this->getLabel());
     $builtinProps = Xinc::getInstance()->getBuiltinProperties();
     foreach ($builtinProps as $prop => $value) {
         $this->setProperty($prop, $value);
     }
     $tasks = $this->getTaskRegistry()->getTasks();
     while ($tasks->hasNext()) {
         $task = $tasks->next();
         $this->_updateTask($task);
     }
 }