/** * Executes svn command and returns output as a SimpleXMLElement object * * @param string $options Options to provide to svn command * @return SimpleXMLElement */ protected function _execute($options) { $command = 'svn ' . $options . ' --non-interactive --xml'; VcsStats_Runner_Cli::displayDebug("Executing command '{$command}'"); exec($command, $output, $returnCode); $output = implode('', $output); return new SimpleXMLElement($output); }
/** * Displays report or generates its files * * @param VcsStats_Report $report Report * @return void */ public function render(VcsStats_Report $report) { VcsStats_Runner_Cli::displayMessage('Rendering report to text'); foreach ($report->getSections() as $section) { foreach ($section->getElements() as $element) { switch (get_class($element)) { case 'VcsStats_Report_Element_Table': $this->renderTable($element); break; } } } }
/** * Main function. Sets up the environment and coordinate the work. * * @return void */ public static function run() { // Set autoload up require_once 'VcsStats/Loader.php'; spl_autoload_register(array('VcsStats_Loader', 'autoload')); require_once 'ezc/Base/base.php'; spl_autoload_register(array('ezcBase', 'autoload')); // Set console output up $output = new ezcConsoleOutput(); $output->formats->version->style = array('bold'); $output->formats->debug->color = 'yellow'; $output->formats->debug->style = array('italic'); $output->formats->error->color = 'red'; self::$consoleOutput = $output; // Set console input up $input = new ezcConsoleInput(); self::$consoleInput = $input; $debugOption = new ezcConsoleOption('d', 'debug'); $debugOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($debugOption); $helpOption = new ezcConsoleOption('h', 'help'); $helpOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($helpOption); $revisionsOption = new ezcConsoleOption('r', 'revisions'); $revisionsOption->type = ezcConsoleInput::TYPE_STRING; $input->registerOption($revisionsOption); $verboseOption = new ezcConsoleOption('v', 'verbose'); $verboseOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($verboseOption); $versionOption = new ezcConsoleOption(null, 'version'); $versionOption->type = ezcConsoleInput::TYPE_NONE; $input->registerOption($versionOption); // Process console input try { $input->process(); } catch (ezcConsoleOptionException $exception) { echo $exception->getMessage() . "\n"; exit(1); } if ($input->getOption('help')->value) { self::displayHelp(); exit(0); } else { if ($input->getOption('version')->value) { self::displayVersion(); exit(0); } } $arguments = $input->getArguments(); if (1 !== count($arguments)) { self::displayError('Path to repository is missing', 'error'); exit(1); } $repositoryPath = $arguments[0]; // Do the actual work self::displayVersion(); try { $options = array('path' => $repositoryPath); $wrapper = new VcsStats_Wrapper_Subversion($options); $cachePath = realpath(dirname(__FILE__) . '/../../tmp'); $cache = new VcsStats_Cache($wrapper, $cachePath); $revisionsRange = self::_extractRevisionsRange($input->getOption('revisions')->value); $cache->updateData($revisionsRange['end']); $analyzer = new VcsStats_Analyzer($cache); $report = $analyzer->getReport($revisionsRange['start'], $revisionsRange['end']); $renderer = new VcsStats_Renderer_Text(); $renderer->render($report); } catch (Exception $exception) { self::displayError($exception->getMessage()); exit(1); } }
/** * Class constructor * * @param VcsStats_Cache $cache Cache instance * @return void */ public function __construct(VcsStats_Cache $cache) { VcsStats_Runner_Cli::displayMessage('Initializing analyzer'); $this->_cache = $cache; }
/** * Updates the cache data * * @param int|null $endRevisionId Id of the last revision to retrieve * @return void */ public function updateData($endRevisionId = null) { VcsStats_Runner_Cli::displayMessage('Updating cache data'); $startRevisionId = $this->getLastCachedRevisionId(); if (null === $startRevisionId) { $startRevisionId = 1; } if ($startRevisionId >= $endRevisionId) { VcsStats_Runner_Cli::displayDebug('Everything is already in cache'); return; } if (null === $endRevisionId) { $endRevisionId = 'HEAD'; } $data = $this->_wrapper->getRevisionsData($startRevisionId, $endRevisionId); $this->_populate($data); }
/** * Class constructor * * @param array $options Options * @return void */ public function __construct(array $options) { VcsStats_Runner_Cli::displayMessage('Initializing wrapper'); $this->_options = $options; }