Exemplo n.º 1
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return \EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $project = EcrProjectHelper::getProject();
     $updateserver = new EcrProjectUpdateserver($project);
     $fileList = $ziper->getCreatedFiles();
     if (0 == count($fileList)) {
         return $this->abort('ERROR: No files to transfer', $ziper);
     }
     $path = ECRPATH_UPDATESERVER . '/' . $project->comName . '/' . $this->releaseState;
     $urlPath = ECRPATH_UPDATESERVER_URL . '/' . $project->comName . '/' . $this->releaseState;
     $urls = array();
     /* @ var EcrProjectZiperCreatedfile $f */
     foreach ($fileList as $f) {
         $dest = $path . '/' . $f->name;
         if (false == JFile::copy($f->path, $dest)) {
             return $this->abort(sprintf('ERROR: Can not copy the file %s to %s', $f->path, $dest), $ziper);
         }
         $ziper->logger->log(sprintf('The file<br />%s<br />has been copied to<br />%s', $f->path, $dest));
         $alternate = $f->alternateDownload;
         $urls[] = $alternate ?: $urlPath . '/' . $f->name;
     }
     $release = new EcrProjectUpdateserverRelease();
     $release->state = $this->releaseState;
     $release->downloads = $urls;
     $release->description = 'Bescreibung...';
     $updateserver->addRelease($release);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     $project = $ziper->project;
     $logger->log('Executing PHP Unit');
     $parts = array('phpunit', '--log-tap ' . ECRPATH_LOGS . '/phpunit.log', $this->arguments, $this->filedir);
     $cmd = implode(' ', $parts);
     $cmd = escapeshellcmd($cmd);
     $logger->log($cmd);
     $output = shell_exec($cmd . ' 2>&1 | tee -a ' . $ziper->logFile);
     if (false == JFile::exists(ECRPATH_LOGS . '/phpunit.log')) {
         $logger->log('PHP Unit Tests failed to run', 'Action', JLog::ERROR);
         return $this;
     }
     $log = JFile::read(ECRPATH_LOGS . '/phpunit.log');
     //$pattern = "/not ok (\d+) - ([a-Z]+):/";
     $pattern = "/not ok (\\d+) - (\\w+):/";
     preg_match_all($pattern, $log, $matches);
     $failures = array();
     $errors = array();
     if ($matches && isset($matches[2])) {
         //foreach($matches[2])
         $type = $matches[2][0];
         switch ($type) {
             case 'Failure':
                 $failures[] = $matches[0][0];
                 break;
             case 'Error':
                 $errors[] = $matches[0][0];
                 break;
             default:
                 $ziper->logger->log(__METHOD__ . ' - unknown type: ' . $type);
         }
         $logger->log('PHP Unit results:');
         //$logger->log(sprintf('Files processed: %s', $filesProcessed));
         $logger->log(sprintf('Failures: %d', count($failures)));
         $logger->log(sprintf('Errors:   %d', count($errors)));
         if (0 != $this->failureThreshold) {
             if (count($failures) >= $this->failureThreshold) {
                 $ziper->addFailure(sprintf('%s: The failure threshold of %d has been exceeded (%d failures)', $this->name, $this->failureThreshold, count($failures)));
                 $ziper->setInvalid();
             }
         }
         if (0 != $this->errorThreshold) {
             if (count($errors) >= $this->errorThreshold) {
                 $ziper->addFailure(sprintf('%s: The error threshold of %d has been exceeded (%d errors)', $this->name, $this->errorThreshold, count($errors)));
                 $ziper->setInvalid();
             }
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return \EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     //-- Require the Dropbox bootstrap
     require JPATH_COMPONENT . '/helpers/Dropbox/bootstrap.php';
     $protocol = false == empty($_SERVER['HTTPS']) ? 'https' : 'http';
     $callback = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     try {
         //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         $encrypter = new \Dropbox\OAuth\Storage\Encrypter('12312323423435456654457545646542');
         $storage = new \Dropbox\OAuth\Storage\Session($encrypter);
         $OAuth = new \Dropbox\OAuth\Consumer\Curl($this->dboxKey, $this->dboxSecret, $storage, $callback);
         $dropbox = new \Dropbox\API($OAuth);
         //$accountInfo = $dropbox->accountInfo();
         //$logger->log('Dropbox account info:'.print_r($accountInfo, 1));
         $files = $ziper->getCreatedFiles();
         /* @var EcrProjectZiperCreatedfile $file */
         foreach ($files as $i => $file) {
             $logger->log(sprintf('Uploading %s to Dropbox...', $file->name));
             $response = $dropbox->putFile($file->path);
             if ('200' !== $response['code']) {
                 $logger->log(print_r($response, 1));
                 $this->abort('Failed to upload the file to Dropbox', $ziper);
             }
             $response = $dropbox->shares($file->name);
             if ('200' !== $response['code']) {
                 $this->abort('Can not get the Dropbox share link', $ziper);
                 $logger->log(print_r($response['code'], 1));
             }
             $link = $response['body']->url;
             $ziper->setAlternateDownloadLink($i, $link);
             $logger->log('Copy the Link: ' . $link, '', JLog::WARNING);
         }
         $logger->log('Dropbox script executed succesfully.');
     } catch (Dropbox\Exception $e) {
         $this->abort(sprintf('Dropbox: %s', $e->getMessage()), $ziper);
     } catch (Exception $e) {
         $this->abort(sprintf('Dropbox action: %s', $e->getMessage()), $ziper);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return \EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $ziper->logger->log('Executing FTP transfer');
     $user = trim($this->user);
     $pass = trim($this->pass);
     if ('' == $user) {
         $text = 'FTP User';
         $command = escapeshellcmd('DISPLAY=:0 XAUTHORITY=/home/elkuku/.Xauthority' . ' kdialog --title "' . $text . '" --inputbox "' . $text . '"');
         $ziper->logger->log('Executing: ' . $command);
         $user = shell_exec($command . ' 2>&1');
         if ('' == $user) {
             $ziper->logger->log('ERROR: No user name given', 'FTP user', JLog::ERROR);
             return $this;
         }
     }
     if ('' == $pass) {
         $text = 'FTP Password';
         $command = escapeshellcmd('DISPLAY=:0 XAUTHORITY=/home/elkuku/.Xauthority' . ' kdialog --title "' . $text . '" --inputbox "' . $text . '"');
         $ziper->logger->log('Executing: ' . $command);
         $pass = shell_exec($command . ' 2>&1');
         if ('' == $pass) {
             $ziper->logger->log('ERROR: No password given', 'FTP user', JLog::ERROR);
             return $this;
         }
     }
     $ftp = EcrFtp::getClient($this->host, $this->port, null, $user, $pass);
     $files = explode(',', $this->files);
     $packages = $ziper->getCreatedFiles();
     foreach ($files as $file) {
         $file = trim($file);
         $path = '';
         $fileName = '';
         switch ($file) {
             case 'package':
                 $path = $packages[0]->path;
                 break;
             default:
                 $ziper->logger->log('ERROR: Unknown file type: ' . $file, 'FTP transfer', JLog::ERROR);
         }
         $remote = null;
         if ($this->folder) {
             $remote = $this->folder . '/' . basename($path);
         }
         if (false == $ftp->store($path, $remote)) {
             //@todo: deprecated JError
             $error = JError::getError();
             $ziper->logger->log('ERROR: ' . $error, 'FTP transfer (JFTP)', JLog::ERROR);
         } else {
             $ziper->logger->log('File transfered: ' . $fileName);
         }
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     $project = $ziper->project;
     $logger->log('Executing CodeSniffer');
     $files = implode(' ', $project->copies);
     $ignore = $this->ignore ? '--ignore=' . $this->ignore : '';
     $extensions = $this->extensions ? '--extensions=' . $this->extensions : '';
     $parts = array('phpcs', '-p', '--report=summary', '--standard=' . $this->standard, $ignore, $this->arguments, $files);
     $cmd = implode(' ', $parts);
     $cmd = escapeshellcmd($cmd);
     $logger->log($cmd);
     $output = shell_exec($cmd . ' 2>&1 | tee -a ' . $ziper->logFile);
     $pattern = "/A TOTAL OF (\\d+) ERROR\\(S\\) AND (\\d+) WARNING\\(S\\) WERE FOUND IN (\\d+) FILE\\(S\\)/";
     preg_match_all($pattern, $output, $matches);
     if ($matches && isset($matches[3])) {
         $errors = isset($matches[1][0]) ? $matches[1][0] : 'n/a';
         $warnings = isset($matches[2][0]) ? $matches[2][0] : 'n/a';
         $filesProcessed = isset($matches[3][0]) ? $matches[3][0] : 'n/a';
         $logger->log('PHP CodeSniffer results:');
         $logger->log(sprintf('Files processed: %s', $filesProcessed));
         $logger->log(sprintf('Errors:   %s', $errors));
         $logger->log(sprintf('Warnings: %s', $warnings));
         if (0 != $this->warningThreshold) {
             if ($warnings >= $this->warningThreshold) {
                 $ziper->addFailure(sprintf('%s: The warning threshold of %d has been exceeded (%d warnings)', $this->name, $this->warningThreshold, $warnings));
                 $ziper->setInvalid();
             }
         }
         if (0 != $this->errorThreshold) {
             if ($errors >= $this->errorThreshold) {
                 $ziper->addFailure(sprintf('%s: The error threshold of %d has been exceeded (%d errors)', $this->name, $this->errorThreshold, $errors));
                 $ziper->setInvalid();
             }
         }
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * DoIt
  *
  * @throws Exception
  * @return void
  */
 public function doExecute()
 {
     define('JPATH_BASE', THE_BUILD_PATH);
     define('JPATH_SITE', JPATH_BASE);
     define('JPATH_CACHE', JPATH_BASE . '/cache');
     define('JPATH_ADMINISTRATOR', JPATH_BASE . '/administrator');
     define('JPATH_COMPONENT', JPATH_ADMINISTRATOR . '/components/com_easycreator');
     define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_COMPONENT);
     define('JPATH_INSTALLATION', '');
     require JPATH_BASE . '/configuration.php';
     require JPATH_BASE . '/libraries/cms/version/version.php';
     $jversion = new JVersion();
     define('JVERSION', $jversion->getShortVersion());
     //-- Global constants
     require JPATH_COMPONENT . '/includes/defines.php';
     //-- Global functions
     require JPATH_COMPONENT . '/includes/loader.php';
     $buildOpts = array();
     if ($this->input->get('v') || $this->input->get('verbose')) {
         $buildOpts[] = 'logging';
     }
     if ($this->input->get('list')) {
         $this->printList();
         return;
     }
     $projectName = $this->input->get('project');
     if ('' == $projectName) {
         throw new Exception('Please specify a project with the option --project');
     }
     $project = EcrProjectHelper::getProject($projectName);
     foreach ($project->buildOpts as $opt => $v) {
         //-- @todo this is ugly..
         if ('1' == $v) {
             $buildOpts[] = $opt;
         }
     }
     $ziper = new EcrProjectZiper();
     $preset = new EcrProjectModelBuildpreset();
     $ziper->create($project, $preset, $buildOpts);
     $this->out('Finished =;)');
 }
Exemplo n.º 7
0
 /**
  * Copy the elements of a package.
  *
  * @throws EcrExceptionZiper
  * @return EcrProjectZiper
  */
 private function copyPackageElements()
 {
     if ($this->project->type != 'package') {
         return $this;
     }
     if (0 == count($this->project->elements)) {
         return $this;
     }
     $this->logger->log('Copying Package elements');
     foreach ($this->project->elements as $element => $path) {
         $this->ecr_project = JFactory::getApplication()->input->get('ecr_project');
         //-- Get the project
         try {
             $project = EcrProjectHelper::getProject($element);
         } catch (Exception $e) {
             $this->logger->log('Unable to load the project ' . $element . ' - ' . $e->getMessage(), 'ERROR');
             continue;
         }
         $ziper = new EcrProjectZiper();
         $result = $ziper->create($project, $project->getPreset(), $this->buildopts);
         $files = $ziper->getCreatedFiles();
         if (0 == count($files)) {
             $this->logger->log(sprintf('No packages files have been created for project %s', $element), 'ERROR', JLog::WARNING);
             continue;
         }
         $src = $files[0]->path;
         $fName = JFile::getName($src);
         //-- Set the elemnent path for manifest class
         $this->project->elements[$element] = $fName;
         $dest = $this->temp_dir . DS . $fName;
         if (JFile::copy($src, $dest)) {
             $this->logger->log(sprintf('Package %s copied from %s to %s', $element, $src, $dest));
         } else {
             throw new EcrExceptionZiper(__METHOD__ . ' - ' . sprintf('Unable to create package %s try to copy from %s to %s', $element, $src, $dest));
         }
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Replace variables in a string.
  *
  * @param string          $string
  * @param EcrProjectZiper $ziper
  *
  * @return string
  */
 protected function replaceVars($string, EcrProjectZiper $ziper)
 {
     $string = str_replace('${temp_dir}', $ziper->temp_dir, $string);
     $string = str_replace('${j_root}', JPATH_ROOT, $string);
     $string = str_replace('${package_path}', $ziper->preset->buildFolder, $string);
     /* @var EcrProjectZiperCreatedfile $file */
     foreach ($ziper->getCreatedFiles() as $file) {
         /*
                     $path = $download;
         
                     if(0 === strpos($download, 'file://'))
                         $path = substr($download, 7);
         */
         $string = str_replace('${package_' . JFile::getExt($file->name) . '}', $file->path, $string);
     }
     return $string;
 }
Exemplo n.º 9
0
 public function createPackage()
 {
     $input = JFactory::getApplication()->input;
     ob_start();
     try {
         $result = new stdClass();
         $buildopts = $input->get('buildopts', array(), 'array');
         $presetName = $input->get('preset');
         $buildOpts = array();
         foreach ($buildopts as $v) {
             $buildOpts[$v] = true;
         }
         $project = EcrProjectHelper::getProject();
         $ziper = new EcrProjectZiper();
         $preset = $project->getPreset($presetName)->loadValues($buildopts);
         $result->result = $ziper->create($project, $preset, $buildOpts);
         $result->errors = $ziper->getErrors();
         $result->downloadLinks = $ziper->getCreatedFiles();
         $result->log = $ziper->printLog();
         if ($result->errors) {
             $this->response->message = jgettext('Your ZIPfile has NOT been created');
             $this->response->status = 1;
             $this->response->debug = '<ul><li>' . implode('</li><li>', $result->errors) . '</li></ul>';
         } else {
             if (count($result->downloadLinks)) {
                 $m = '';
                 $m .= jgettext('Your ZIPfile has been created sucessfully');
                 $m .= '<ul class="downloadLinks">';
                 $m .= '<li><strong>' . jgettext('Downloads') . '</strong></li>';
                 /* @var EcrProjectZiperCreatedfile $link */
                 foreach ($result->downloadLinks as $link) {
                     $alt = $link->alternateDownload ? ' (<a href="' . $link->alternateDownload . '">' . $link->alternateDownload . '</a>)' : '';
                     $m .= '<li><a href="' . $link->downloadUrl . '">' . $link->name . '</a><' . $alt . '/li>';
                 }
                 $m .= '</ul>';
                 $this->response->message = $m;
             } else {
                 $this->response->message = jgettext('No download available');
                 $this->response->status = 1;
             }
         }
         if ($result->log) {
             $m = '';
             $m .= '<div class="ecr_codebox_header" style="font-size: 1.4em;"' . 'onclick="toggleDiv(\'ecr_logdisplay\');">' . jgettext('Log File') . '</div>';
             $m .= '<div id="ecr_logdisplay" style="display: none;">' . $result->log . '</div>';
             $this->response->message .= $m;
         }
     } catch (Exception $e) {
         $this->response->debug = ECR_DEBUG ? nl2br($e) : '';
         $this->response->message = $e->getMessage();
         $this->response->status = 1;
     }
     $buffer = ob_get_clean();
     if ($buffer) {
         $this->response->status = 1;
         $this->response->debug .= $buffer;
     }
     echo $this->response;
     jexit();
 }