Esempio n. 1
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     if (nbConfig::has('project_type')) {
         $projectType = nbConfig::get('project_type');
         if ($projectType == "bee") {
             $unitTest = new nbBeeTestUnitCommand();
             $retUnit = $unitTest->run(new nbCommandLineParser(), '', true);
             $pluginsTest = new nbBeeTestPluginsCommand();
             $retPlugin = $pluginsTest->run(new nbCommandLineParser(), '', true);
             if ($retUnit == 0 or $retPlugin == 0) {
                 return 0;
             } else {
                 return 1;
             }
         } else {
             try {
                 $commandSet = $this->getApplication()->getCommands();
                 $testAllCmd = $commandSet->getCommand($projectType . ':test-all');
                 $testAllCmd->run(new nbCommandLineParser(), '', true);
                 return true;
             } catch (Exception $e) {
                 $this->logLine($e->getMessage(), nbLogger::ERROR);
                 return false;
             }
         }
     } else {
         throw new Exception('Project type not defined');
     }
 }
Esempio n. 2
0
File: unit.php Progetto: nubee/bee
function checkMysql()
{
    if (nbConfig::has('mysql_admin-username')) {
        return true;
    }
    $t = new lime_test(0);
    return false;
}
Esempio n. 3
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->checkBeeProject();
     if (!nbConfig::has('project_repository_root-directory')) {
         throw new Exception('You must configure your project directory (absolute path!)');
     }
     $shell = new nbShell();
     if (!isset($options['force'])) {
         // git status
         $this->logLine("git status:", nbLogger::INFO);
         $command = 'git status';
         $shell->execute($command);
         // git tag
         $this->logLine("git tag", nbLogger::INFO);
         $command = 'git tag';
         $shell->execute($command);
         return 0;
     }
     if (!isset($arguments['message'])) {
         throw new Exception('You must write a commit message!');
     }
     $message = $arguments['message'];
     $repoDir = nbConfig::get('project_repository_root-directory');
     // git add <project repository directory>
     $command = sprintf('git add %s', $repoDir);
     $shell->execute($command);
     // git commit -m "<message>"
     $command = sprintf('git commit -m "%s"', $message);
     $shell->execute($command);
     // git pull
     $command = 'git pull';
     if (!$shell->execute($command)) {
         throw new Exception('There are conflicts. Resolve them and re-run this command.');
     }
     // test command
     if (!nbConfig::has('project_test-command')) {
         throw new Exception('You must configure your test command');
     }
     $command = nbConfig::get('project_test-command');
     if (!$shell->execute($command)) {
         throw new Exception('There are test failures. Fix them and re-run this command.');
     }
     if (isset($options['tag'])) {
         $tag = $options['tag'];
         $command = sprintf('git tag %s', $tag);
         $shell->execute($command);
         // git push with tags
         $command = 'git push origin master --tags';
     } else {
         // git push
         $command = 'git push';
     }
     $shell->execute($command);
 }
Esempio n. 4
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     if (nbConfig::has('project_android_test_build-file')) {
         $buildFile = nbConfig::get('project_android_test_build-file');
     } else {
         throw new Exception('"project_android_test_build-file" not set');
     }
     if (nbConfig::has('project_type') && nbConfig::get('project_type') == 'android') {
         $cmd = sprintf('ant -f %s test', $buildFile);
         $this->executeShellCommand($cmd);
         return true;
     } else {
         throw new Exception('This isn\'t a android project');
     }
 }
Esempio n. 5
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     if (nbConfig::has('project_type') and nbConfig::get('project_type') == 'symfony') {
         $symfonyExecutable = sprintf('%s/%s', nbFileSystem::sanitizeDir(nbConfig::get('project_symfony_exec-path')), 'symfony');
         $symfonyTestEnviroment = nbConfig::get('project_symfony_test-enviroment');
         $this->logLine(sprintf('Launching all test for %s enviroment', $symfonyTestEnviroment));
         if ($symfonyTestEnviroment == 'lime') {
             $cmd = sprintf('php %s test:all', $symfonyExecutable);
             $this->executeShellCommand($cmd);
         } else {
             if ($symfonyTestEnviroment == 'phpunit') {
                 $cmd = sprintf('php %s phpunit:test-all', $symfonyExecutable);
                 $this->executeShellCommand($cmd);
             } else {
                 return false;
             }
         }
         return true;
     } else {
         throw new Exception('This isn\'t a symfony project');
     }
 }
Esempio n. 6
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Diem Deploy');
     $configParser = new nbYamlConfigParser();
     $configParser->parseFile($arguments['config-file']);
     $symfonyExePath = nbConfig::get('symfony_project-deploy_symfony-root-dir');
     // Put website offline
     if (nbConfig::has('symfony_project-deploy_site-applications')) {
         foreach (nbConfig::get('symfony_project-deploy_site-applications') as $key => $value) {
             $cmd = new nbSymfonyGoOfflineCommand();
             $application = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_name");
             $environment = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_env");
             $cmd->run(new nbCommandLineParser(), sprintf('%s %s %s', $symfonyExePath, $application, $environment));
         }
     }
     // Archive site directory
     if (nbConfig::has('archive_inflate-dir')) {
         $cmd = new nbInflateDirCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Dump database
     if (nbConfig::has('mysql_dump')) {
         $cmd = new nbMysqlDumpCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Sync project
     if (nbConfig::has('filesystem_dir-transfer')) {
         $cmd = new nbDirTransferCommand();
         $commandLine = '--doit --delete --config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Check dirs
     $cmd = new nbSymfonyCheckDirsCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Check permissions
     $cmd = new nbSymfonyCheckPermissionsCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Change ownership
     $cmd = new nbSymfonyChangeOwnershipCommand();
     $commandLine = sprintf('%s %s %s', nbConfig::get('symfony_project-deploy_site-dir'), nbConfig::get('symfony_project-deploy_site-user'), nbConfig::get('symfony_project-deploy_site-group'));
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Restore database
     if (nbConfig::has('mysql_restore')) {
         $cmd = new nbMysqlRestoreCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Diem setup
     $cmd = new nbSymfonyDiemSetupCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Clear cache
     $cmd = new nbSymfonyClearCacheCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Put site online
     if (nbConfig::has('symfony_project-deploy_site-applications')) {
         foreach (nbConfig::get('symfony_project-deploy_site-applications') as $key => $value) {
             $cmd = new nbSymfonyGoOnlineCommand();
             $application = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_name");
             $environment = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_env");
             $cmd->run(new nbCommandLineParser(), sprintf('%s %s %s', $symfonyExePath, $application, $environment));
         }
     }
     $this->logLine('Done - Diem Deploy');
     return true;
 }
Esempio n. 7
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $interactiveMode = isset($options['interactive']) ? true : false;
     $forceMode = isset($options['force']) ? true : false;
     $message = $arguments["message"];
     $buildMessage = "Update build version";
     $repositoryType = nbConfig::get('project_repository_type', 'git');
     if (nbConfig::has('project_repository_root-directory')) {
         $projectRootDir = nbConfig::get('project_repository_root-directory');
     } else {
         throw new Exception('You must configure your project root directory');
     }
     $buildVersionFile = $projectRootDir . "/version.yml";
     if (nbConfig::has('project_repository') and $repositoryType == 'git') {
         $shell = new nbShell();
         $this->logLine(sprintf('Starting repository commit for project %', nbConfig::get('project_name')));
         // git add <project root dir>
         $this->logLine(sprintf('adding working dir %s to stage', $projectRootDir));
         $cmd = sprintf('git add %s', $projectRootDir);
         $code = $shell->execute($cmd);
         if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) {
             $this->logLine('Bye');
             die;
         }
         // git status
         $this->logLine('git status');
         $cmd = sprintf('git status', $projectRootDir);
         $code = $shell->execute($cmd);
         // git commit -m "<commit message>"
         if ($interactiveMode and !$this->askConfirmation("Do you want to commit your changes to your local repository?")) {
             $this->logLine('Bye');
             die;
         }
         $this->logLine(sprintf('commiting working dir %s to local repository', $projectRootDir));
         $cmd = sprintf('git commit -m "%s"', $message);
         $code = $shell->execute($cmd);
         // git pull
         if ($interactiveMode and !$this->askConfirmation("Do you want to update from your remote repository?")) {
             $this->logLine('Bye');
             die;
         }
         $this->logLine('updating local repository with remote changes');
         $cmd = 'git pull';
         $code = $shell->execute($cmd);
         if ($code == 0) {
             $this->logLine('git pull failed');
             die;
         }
         // bee test:all
         if (!$interactiveMode or $interactiveMode and $this->askConfirmation("Do you want to test your project?")) {
             $this->logLine('executing nbTestAllCommand');
             $cmd = new nbTestAllCommand();
             $cmd->setApplication($this->getApplication());
             $code = $cmd->run(new nbCommandLineParser(), '');
             if ($code == 0 and !$interactiveMode and !$forceMode or $code == 0 and $interactiveMode and !$this->askConfirmation('There are some errors in your tests, do you want to continue anyway?')) {
                 $this->logLine('Bye');
                 die;
             }
         }
         // commit repository updating build file
         if ($interactiveMode and !$this->askConfirmation("Do you want to commit your changes in the remote repository?")) {
             $this->logLine('Bye');
             die;
         }
         // bee version:update-build <build version file>
         $cmd = new nbUpdateBuildVersionCommand();
         $cmdLine = sprintf('%s', $buildVersionFile);
         $parser = new nbCommandLineParser();
         $cmd->run($parser, $cmdLine);
         // git add <build version file>
         $this->logLine('adding build version file');
         $cmd = sprintf('git add %s', $buildVersionFile);
         $code = $shell->execute($cmd);
         if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) {
             $this->logLine('Bye');
             die;
         }
         // git commit -m "<commit build message>"
         $this->logLine('updating local repository with remote changes');
         $cmd = sprintf('git commit -m "%s"', $buildMessage);
         $code = $shell->execute($cmd);
         if ($code == 0 and !$this->askConfirmation(sprintf('Error in "%s", do you want to continue anyway?', $cmd))) {
             $this->logLine('Bye');
             die;
         }
         // git push
         $this->logLine('merging remote repository with local repository');
         $cmd = 'git push';
         $code = $shell->execute($cmd);
         if ($code == 0) {
             $this->logLine('Push error');
             die;
         }
         $this->logLine('Repository commit executed succesfully');
     }
 }
Esempio n. 8
0
File: bee.php Progetto: nubee/bee
$output = new nbConsoleOutput();
$output->setFormatter(nbConfig::get('nb_output_color', 'false') == 'true' ? new nbAnsiColorFormatter() : new nbFormatter());
$logger = nbLogger::getInstance();
$logger->setOutput($output);
/* * ********************* */
if (nbConfig::has('project_bee_plugins_dir')) {
    $serviceContainer->pluginLoader->addDir(nbConfig::get('project_bee_plugins_dir'));
}
// Loads default plugins from path/to/bee/config/config.yml
if (!($defaultPlugins = nbConfig::get('nb_default_plugins'))) {
    $defaultPlugins = array();
} else {
    $serviceContainer->pluginLoader->loadPlugins($defaultPlugins);
}
//loads project plugins from project/path/bee.yml
if (nbConfig::has('project_bee_enabled_plugins')) {
    $plugins = nbConfig::get('project_bee_enabled_plugins');
    null === $plugins ? $serviceContainer->pluginLoader->loadAllPlugins() : $serviceContainer->pluginLoader->loadPlugins($plugins);
}
$autoload->addDirectory(nbConfig::get('nb_command_dir'), 'Command.php', true);
$serviceContainer->commandLoader->loadCommands();
$serviceContainer->commandLoader->loadCommandAliases();
try {
    $application = new nbBeeApplication($serviceContainer);
    $application->run();
} catch (Exception $e) {
    if ($application) {
        $application->renderException($e);
    }
    $statusCode = $e->getCode();
    exit(is_numeric($statusCode) && $statusCode ? $statusCode : 1);
Esempio n. 9
0
nbConfig::remove('bar');
$t->is(nbConfig::getAll(), array('foo' => 'fooValue'), '->remove() removes a sigle configuration key');
nbConfig::reset();
$t->comment('nbConfigTest - Test reset');
nbConfig::set('foo', 'fooValue');
nbConfig::set('bar', 'barValue');
$t->is(count(nbConfig::getAll()), 2, '->reset() remove all keys');
nbConfig::reset();
$t->is(nbConfig::getAll(), array(), '->reset() remove all keys');
$t->comment('nbConfigTest - Test has');
$t->is(nbConfig::has('key'), false, 'nbConfig::has() returns false if key is not present');
nbConfig::set('key', 'value');
$t->is(nbConfig::has('key'), true, 'nbConfig::has() returns true if key is present');
$key2 = array('foo' => 'fooValue');
nbConfig::set('key2', $key2);
$t->is(nbConfig::has('key2_foo'), true, 'nbConfig::has() returns true if "key path" is present');
$t->comment('nbConfigTest - Test get');
$t->is(nbConfig::get('fake-key'), null, 'nbConfig::get() returns null if key in not present');
$t->is(nbConfig::get('fake-key', 'value'), 'value', 'nbConfig::get() returns default value if key in not present');
$t->is(nbConfig::get('key2'), $key2, 'nbConfig::get() returns an array if key has subkeys');
$t->is(nbConfig::get('key2_foo'), $key2['foo'], 'nbConfig::get() parse a "key path" and returns leaf value');
$t->comment('nbConfigTest - Test set');
nbConfig::set('bar', 'barValue');
$t->is(nbConfig::get('bar'), 'barValue', 'nbConfig::set() sets a new value for key');
nbConfig::set('bar', 'newBarValue');
$t->is(nbConfig::get('bar'), 'newBarValue', 'nbConfig::set() sets a new value for key');
nbConfig::set('bar_sub', 'subValue');
$t->is(nbConfig::get('bar'), array('sub' => 'subValue'), 'nbConfig::set() sets a new value for key');
$t->is(nbConfig::get('bar_sub'), 'subValue', 'nbConfig::set() sets a new value for key');
nbConfig::set('bar_sub2', 'subValue2');
$t->is(nbConfig::get('bar'), array('sub' => 'subValue', 'sub2' => 'subValue2'), 'nbConfig::set() sets a new value for key');
Esempio n. 10
0
 /**
  * Parses command line arguments.
  *
  * @param mixed $arguments A string or an array of command line parameters
  */
 public function parse($commandLine = null, $namespace = '', $commandName = '')
 {
     if (null === $commandLine) {
         $this->commandLineTokens = $_SERVER['argv'];
         // we strip command line program
         if (count($this->commandLineTokens) && '-' != $this->commandLineTokens[0][0]) {
             array_shift($this->commandLineTokens);
         }
     } else {
         if (!is_array($commandLine)) {
             $commandLine = trim($commandLine);
             // hack to split arguments with spaces : --test="with some spaces"
             $commandLine = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '__PLACEHOLDER__', '\\2')", $commandLine);
             $this->commandLineTokens = preg_split('/\\s+/', $commandLine);
             $this->commandLineTokens = str_replace('__PLACEHOLDER__', ' ', $this->commandLineTokens);
         } else {
             $this->commandLineTokens = $commandLine;
         }
     }
     $this->argumentValues = array();
     $this->optionValues = array();
     $this->parsedArgumentValues = array();
     $this->errors = array();
     // get default values for optional arguments
     $this->argumentValues = $this->arguments->getDefaultValues();
     // parse option and arguments from $commandLineArguments
     while (!in_array($argument = array_shift($this->commandLineTokens), array('', null))) {
         if ('--' == $argument) {
             // stop options parsing
             //$this->parsedArgumentValues = array_merge($this->parsedArgumentValues, $this->commandLineArguments);
             $this->commandLineTokens = array();
             break;
         }
         if ('--' == substr($argument, 0, 2)) {
             $this->parseLongOption(substr($argument, 2));
         } else {
             if ('-' == $argument[0]) {
                 $this->parseShortOption(substr($argument, 1));
             } else {
                 $this->parsedArgumentValues[] = $argument;
             }
         }
     }
     // If option config-file is set, get all arguments and parameters from the configuration file
     if (isset($this->parsedLongOptionValues['config-file']) && $this->options->hasOption('config-file')) {
         $option = $this->parsedLongOptionValues['config-file'];
         $configFilename = isset($option[0]) && !is_bool($option[0]) ? $option[0] : null;
         if (!$configFilename) {
             $configFilename = $this->options->getOption('config-file')->getValue();
         }
         if (!$configFilename) {
             throw new InvalidArgumentException('Config filename not defined (and no default provided)');
         }
         $configFile = $this->checkDefaultConfigurationDirs($configFilename);
         if (!$configFile) {
             throw new InvalidArgumentException(sprintf('Config file: %s not found (checked in %s)', $configFilename, implode(', ', $this->getDefaultConfigurationDirs())));
         }
         $configParser = new nbYamlConfigParser();
         $configParser->parseFile($configFile, '', true);
         $ymlPath = $namespace . '_' . $commandName;
         if (nbConfig::has($ymlPath)) {
             $configurationValues = nbConfig::get($ymlPath);
             foreach ($configurationValues as $name => $value) {
                 if (!$this->getArguments()->hasArgument($name) || '' == $value) {
                     continue;
                 }
                 $this->argumentValues[$name] = $value;
             }
             foreach ($configurationValues as $name => $value) {
                 if (!$this->getOptions()->hasOption($name)) {
                     continue;
                 }
                 $option = $this->getOptions()->getOption($name);
                 if ($value !== false && $value !== null) {
                     $this->setOption($option, $value);
                 }
             }
         }
     }
     //set argumentValues parsed from command line
     $position = 0;
     foreach ($this->arguments->getArguments() as $argument) {
         if (array_key_exists($position, $this->parsedArgumentValues)) {
             if ($argument->isArray()) {
                 $this->argumentValues[$argument->getName()] = array_slice($this->parsedArgumentValues, $position);
                 break;
             } else {
                 $this->argumentValues[$argument->getName()] = $this->parsedArgumentValues[$position];
             }
         }
         ++$position;
     }
     // set long option values parsed from command line
     foreach ($this->options->getOptions() as $option) {
         $name = $option->getName();
         if (isset($this->parsedLongOptionValues[$name])) {
             foreach ($this->parsedLongOptionValues[$name] as $key => $value) {
                 $this->setOption($option, $value);
             }
         } else {
             if ($option->hasShortcut() && isset($this->parsedShortOptionValues[$option->getShortcut()])) {
                 foreach ($this->parsedShortOptionValues[$option->getShortcut()] as $key => $value) {
                     $this->setOption($option, $value);
                 }
             }
         }
     }
     // get default values for option with optional parameter not set
     foreach ($this->getOptionValues() as $optionName => $optionValue) {
         $option = $this->options->getOption($optionName);
         if ($option->hasOptionalParameter() && ($this->optionValues[$optionName] == '' || $this->optionValues[$optionName] === true)) {
             $this->setOption($option, $option->getValue());
         }
     }
 }
Esempio n. 11
0
 public function loadCommandAliases()
 {
     if (!nbConfig::has('project_commands')) {
         return;
     }
     $namespaces = nbConfig::get('project_commands');
     foreach ($namespaces as $namespace => $commands) {
         if ($namespace === 'default') {
             $namespace = '';
         }
         foreach ($commands as $alias => $commandName) {
             if (is_array($commandName)) {
                 try {
                     $command = new nbChainCommand("{$namespace}:{$alias}");
                     foreach ($commandName as $c) {
                         $command->addCommand($this->commands->getCommand($c));
                     }
                 } catch (Exception $e) {
                     echo "{$commandName} not found (" . $e->getMessage() . ")\n";
                 }
             } else {
                 $command = $this->commands->getCommand($commandName);
             }
             try {
                 $this->commands->addCommand(new nbAliasCommand("{$namespace}:{$alias}", $command));
             } catch (Exception $e) {
                 echo "{$commandName} not found (" . $e->getMessage() . ")\n";
             }
         }
     }
 }