コード例 #1
0
ファイル: nbPluginLoader.php プロジェクト: nubee/bee
 /**
  * Register All plugins in pluginDir.
  *
  */
 public function loadAllPlugins()
 {
     $plugins = nbFileFinder::create('dir')->discard('test')->prune('test')->add('*Plugin')->in($this->pluginDirs);
     foreach ($plugins as $plugin) {
         $this->addPlugin(basename($plugin));
     }
 }
コード例 #2
0
ファイル: nbBeeInstallCommand.php プロジェクト: nubee/bee
 protected function execute(array $arguments = array(), array $options = array())
 {
     $fs = $this->getFileSystem();
     $dest = $fs->sanitizeDir($arguments['install-dir']);
     $source = $fs->sanitizeDir(isset($options['source-dir']) ? $options['source-dir'] : './');
     if (!file_exists($dest)) {
         $fs->mkdir($dest, true);
     }
     $this->logLine('Installing bee on: ' . $dest, nbLogger::COMMENT);
     $finder = nbFileFinder::create('any');
     $fs->mirror($source, $dest, $finder, array('overwrite' => true));
     try {
         if (PHP_OS == "Linux") {
             if (file_exists('/usr/bin/bee')) {
                 $this->executeShellCommand('rm /usr/bin/bee');
             }
             $this->executeShellCommand('ln -s ' . $dest . '/bee /usr/bin/bee');
         } else {
             if (PHP_OS == "WINNT") {
                 $this->logLine('Remember to add ' . $dest . ' to your Path environment variable', nbLogger::COMMENT);
             } else {
                 throw new Exception("Operating System not supported");
             }
         }
         $this->logLine('Bee successfully installed', nbLogger::COMMENT);
     } catch (Exception $e) {
         $this->logLine('Error installing bee: ' . $e->getMessage(), nbLogger::ERROR);
         throw $e;
     }
 }
コード例 #3
0
ファイル: nbAutoload.php プロジェクト: nubee/bee
 /**
  * Adds a directory to the autoloading system if not yet present and give it the highest possible precedence.
  *
  * @param string $dir The directory to look for classes
  * @param string $ext The extension to look for
  */
 public function addDirectory($dir, $ext = '.php', $recursive = false)
 {
     $finder = nbFileFinder::create('file');
     if (!$recursive) {
         $finder->maxdepth(0);
     }
     $finder->followLink()->add('*' . $ext);
     $this->addFiles($finder->in($dir), false);
 }
コード例 #4
0
ファイル: nbWebsiteInitCommand.php プロジェクト: nubee/bee
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->checkBeeProject();
     $this->logLine('Initialising website', nbLogger::INFO);
     $verbose = isset($options['verbose']);
     $files = nbFileFinder::create('file')->add('website-*')->remove('.')->remove('..')->in('.bee');
     foreach ($files as $file) {
         $backupDir = dirname($file);
         $backupFile = 'backup_' . basename($file);
         $this->getFileSystem()->copy($file, sprintf('%s/%s', $backupDir, $backupFile), true);
     }
     // Enable required plugins for website:deploy
     $cmd = new nbEnablePluginCommand();
     $cmdLine = 'nbFileSystemPlugin --no-configuration';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     $cmdLine = 'nbMysqlPlugin --no-configuration';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     $cmdLine = 'nbWebsitePlugin -f';
     $this->executeCommand($cmd, $cmdLine, true, $verbose);
     // Makes web directory
     $deployDir = isset($arguments['deploy-dir']) ? nbFileSystem::sanitizeDir($arguments['deploy-dir']) : null;
     if ($deployDir) {
         $webDir = isset($options['change-web-dir']) ? $options['change-web-dir'] : 'httpdocs';
         $webDir = sprintf('%s/%s', $deployDir, $webDir);
         $this->logLine('Creating/Checking dir: ' . $webDir, nbLogger::COMMENT);
         if (!is_dir($webDir)) {
             $this->getFileSystem()->mkdir($webDir, true);
         }
     }
     // Creates the database
     $dbName = isset($options['db-name']) ? $options['db-name'] : null;
     $dbUser = isset($options['db-user']) ? $options['db-user'] : null;
     $dbPass = isset($options['db-pass']) ? $options['db-pass'] : null;
     $mysqlUser = isset($options['mysql-user']) ? $options['mysql-user'] : '******';
     $mysqlPass = isset($options['mysql-pass']) ? $options['mysql-pass'] : '';
     if ($dbName && $dbUser && $dbPass) {
         $cmdLine = sprintf('%s %s %s --username=%s --password=%s', $dbName, $mysqlUser, $mysqlPass, $dbUser, $dbPass);
         $cmd = new nbMysqlCreateCommand();
         $this->executeCommand($cmd, $cmdLine, true, $verbose);
     }
     // Restores the database
     $dbDumpFile = isset($options['db-dump-file']) ? $options['db-dump-file'] : null;
     if (is_file($dbDumpFile)) {
         if (!$dbName) {
             $this->logLine('You must specify the database name (use option: --db-name)', nbLogger::ERROR);
             return false;
         }
         $cmd = new nbMysqlRestoreCommand();
         $cmdLine = sprintf('%s %s %s %s', $dbName, $dbDumpFile, $mysqlUser, $mysqlPass);
         $this->executeCommand($cmd, $cmdLine, true, $verbose);
     }
     $this->logLine('Website initialized successfully', nbLogger::INFO);
     return true;
 }
コード例 #5
0
ファイル: nbEnablePluginCommand.php プロジェクト: nubee/bee
 protected function execute(array $arguments = array(), array $options = array())
 {
     $allPluginsDir = nbConfig::get('nb_plugins_dir');
     $pluginName = $arguments['plugin-name'];
     $projectDir = $arguments['project-dir'];
     $configDir = $projectDir . '/.bee';
     $beeConfig = $configDir . '/bee.yml';
     $force = isset($options['force']);
     $pluginPath = $allPluginsDir . '/' . $pluginName;
     $verbose = isset($options['verbose']);
     if (!file_exists($pluginPath)) {
         throw new Exception('plugin ' . $pluginName . ' not found in ' . nbConfig::get('nb_plugins_dir'));
     }
     if (!file_exists($beeConfig)) {
         throw new Exception($beeConfig . ' not found');
     }
     $configParser = sfYaml::load($beeConfig);
     $plugins = $configParser['project']['bee']['enabled_plugins'];
     $plugins = isset($configParser['project']['bee']['enabled_plugins']) ? $configParser['project']['bee']['enabled_plugins'] : array();
     if (!is_array($plugins)) {
         $plugins = array();
     }
     if (!in_array($pluginName, $plugins)) {
         array_push($plugins, $pluginName);
         $configParser['project']['bee']['enabled_plugins'] = $plugins;
         $yml = sfYaml::dump($configParser, 99);
         file_put_contents($beeConfig, $yml);
         $this->logLine('Installing plugin ' . $pluginName);
     } else {
         $this->logLine('Plugin ' . $pluginName . ' already installed');
     }
     // Configuration will not generated
     if (isset($options['no-configuration'])) {
         return true;
     }
     // Configure plugin
     $pluginConfigDir = sprintf('%s/%s/config', $allPluginsDir, $pluginName);
     $files = nbFileFinder::create('file')->add('*.template.yml')->in($pluginConfigDir);
     $generator = new nbConfigurationGenerator();
     $this->getFileSystem()->mkdir($configDir, true);
     foreach ($files as $file) {
         $target = sprintf('%s/%s', $configDir, str_replace('.template.yml', '.yml', basename($file)));
         $generator->generate($file, $target, $force);
         if ($verbose) {
             $this->logLine('file+: ' . $target, nbLogger::INFO);
         }
     }
     return true;
 }
コード例 #6
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $fs = $this->getFileSystem();
     $from = $arguments['from'];
     $to = $arguments['to'];
     $projectName = $arguments['project-name'];
     $destination = sprintf('%s/%s/', $to, $projectName);
     $exclude = array('nbproject', '.netbeans', 'cache', 'log');
     $files = nbFileFinder::create('any')->discard($exclude)->prune($exclude)->remove('.')->remove('..')->in($from);
     $cloneExists = is_dir($destination);
     if ($cloneExists) {
         $finder = nbFileFinder::create('file');
         $files = array_diff($files, $finder->add('*.yml')->in($from . '/config'));
         $files = array_diff($files, $finder->add('*')->in($from . '/web/images'));
         $files = array_diff($files, $finder->add('*.css')->in($from . '/web/css'));
         $files = array_diff($files, $finder->add('*.js')->in($from . '/web/js'));
         $files = array_diff($files, $finder->add('*.yml')->in($from . '/apps/frontend/config'));
         $files = array_diff($files, $finder->add('*.yml')->in($from . '/apps/admin/config'));
     }
     $sourceProjectName = isset($options['source-project-name']) ? $options['source-project-name'] : basename($from);
     $verbose = isset($options['verbose']) && $options['verbose'];
     $count = 0;
     foreach ($files as $file) {
         $dest = preg_replace('/^.+' . $sourceProjectName . '\\//', $destination, $file);
         if (is_dir($file)) {
             if ($verbose) {
                 $this->logLine('dir+: ' . $dest, sfLogger::INFO);
             }
             $fs->mkdir($dest, true);
         } else {
             if ($verbose) {
                 $this->logLine('file+: ' . $dest, sfLogger::INFO);
             }
             $fs->copy($file, $dest, true);
         }
         if (!$verbose && $count++ % 100 == 0) {
             $this->log('.');
         }
     }
     $this->logLine('');
     if (!$cloneExists) {
         $files = nbFileFinder::create('file')->remove('.')->remove('..')->in($destination);
         $fs->replaceTokens($sourceProjectName, $projectName, $files);
     }
     return true;
 }
コード例 #7
0
ファイル: nbBeeTestUnitCommand.php プロジェクト: nubee/bee
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Unit testing bee');
     $files = array();
     $dirs = isset($options['dir']) ? $options['dir'] : array();
     if (!isset($options['exclude-project-folder'])) {
         $dirs[] = nbConfig::get('nb_test_dir', 'test/unit');
     }
     if (count($arguments['name'])) {
         foreach ($dirs as $dir) {
             foreach ($arguments['name'] as $name) {
                 $finder = nbFileFinder::create('file')->followLink()->add(basename($name) . 'Test.php');
                 $files = array_merge($files, $finder->in($dir . '/' . dirname($name)));
             }
         }
     } else {
         // filter and register unit tests
         $finder = nbFileFinder::create('file')->add('*Test.php');
         $files = $finder->in($dirs);
     }
     if (count($files) == 0) {
         $this->log('no tests found', nbLogger::ERROR);
         return false;
     }
     $h = new lime_harness();
     $h->register($files);
     $ret = $h->run(isset($options['showall']));
     // print output to file
     if (isset($options['output'])) {
         $fileName = $options['output'];
         $fh = fopen($fileName, 'w');
         if ($fh === false) {
             return $ret;
         }
         fwrite($fh, isset($options['xml']) ? $h->to_xml() : '');
         fclose($fh);
     }
     return $ret;
 }
コード例 #8
0
ファイル: nbIvyRetrieveCommand.php プロジェクト: nubee/bee
 protected function execute(array $arguments = array(), array $options = array())
 {
     nbFileSystem::rmdir(nbConfig::get('project_dependencies'), true);
     $client = new nbIvyClient();
     $this->logLine('Retrieving dependencies...', nbLogger::COMMENT);
     $command = $client->getRetrieveCmdLine();
     $this->executeShellCommand($command);
     $finder = nbFileFinder::create('file');
     $files = $finder->add('*-api.zip')->in(nbConfig::get('project_dependencies'));
     $zip = new ZipArchive();
     foreach ($files as $file) {
         if ($zip->open($file, ZIPARCHIVE::CHECKCONS) !== true) {
             throw new Exception('Error opening zip file ' . $file);
         }
         $zip->extractTo(dirname($file));
         $zip->close();
         $this->logLine(sprintf('Unzipping %s', $file), nbLogger::COMMENT);
     }
     $files = $finder->add('*.zip')->in(nbConfig::get('project_dependencies'));
     foreach ($files as $file) {
         nbFileSystem::delete($file);
     }
 }
コード例 #9
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $filename = isset($options['filename']) ? $options['filename'] : null;
     $printer = new nbConfigurationPrinter();
     $printer->addConfiguration(nbConfig::getAll());
     if ($filename) {
         $this->logLine(sprintf('bee configuration (file: %s)', $filename), nbLogger::COMMENT);
         $printer->addConfigurationFile($filename);
     } else {
         $dirs = array('./', nbConfig::get('nb_config_dir'));
         $this->logLine(sprintf('bee configuration (dirs: %s)', implode(', ', $dirs)), nbLogger::COMMENT);
         $finder = nbFileFinder::create('file')->add('*.yml')->maxdepth(0);
         foreach ($dirs as $dir) {
             $files = $finder->in($dir);
             foreach ($files as $file) {
                 $this->logLine('Adding ' . $file, nbLogger::COMMENT);
                 $printer->addConfigurationFile($file);
             }
         }
     }
     $this->logLine($printer->printAll());
     return true;
 }
コード例 #10
0
ファイル: nbCommandLoader.php プロジェクト: nubee/bee
 public function addCommandsFromDir($dir)
 {
     if (!is_dir($dir)) {
         return;
     }
     if (key_exists($dir, $this->dirs) && $this->dirs[$dir]) {
         return;
     }
     $finder = nbFileFinder::create('file')->add('*Command.php');
     $this->commandFiles = array();
     foreach ($finder->in($dir) as $file) {
         $this->commandFiles[basename($file, '.php')] = $file;
     }
     // register local autoloader for tasks
     spl_autoload_register(array($this, 'autoloadCommand'));
     foreach ($this->commandFiles as $command => $file) {
         // forces autoloading of each command class
         $this->commands->addCommand(new $command());
     }
     // unregister local autoloader
     spl_autoload_unregister(array($this, 'autoloadCommand'));
     $this->dirs[$dir] = true;
 }
コード例 #11
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $pluginName = $arguments['plugin-name'];
     $force = isset($options['force']);
     $destination = isset($options['config-dir']) ? $options['config-dir'] : nbConfig::get('nb_config_dir');
     $pluginsDir = nbConfig::get('nb_plugins_dir');
     $pluginDir = sprintf('%s/%s', $pluginsDir, $pluginName);
     $this->logLine('Configuring plugin: ' . $pluginName, nbLogger::COMMENT);
     if (!is_dir($pluginDir)) {
         throw new LogicException('Plugin ' . $pluginName . ' not found in ' . $pluginsDir);
     }
     $source = sprintf('%s/%s/config', $pluginsDir, $pluginName);
     //TODO: copy all files in config (?)
     $files = nbFileFinder::create('file')->add('*.template.yml')->remove('.')->remove('..')->in($source);
     $generator = new nbConfigurationGenerator();
     $this->getFileSystem()->mkdir($destination, true);
     foreach ($files as $file) {
         $target = sprintf('%s/%s', $destination, str_replace('.template.yml', '.yml', basename($file)));
         $generator->generate($file, $target, $force);
         $this->logLine('file+: ' . $target, nbLogger::INFO);
     }
     $this->logLine(sprintf('Plugin %s successully configured in %s', $pluginName, $destination), nbLogger::COMMENT);
     return true;
 }
コード例 #12
0
ファイル: nbFileFinderTest.php プロジェクト: nubee/bee
$finder = nbFileFinder::create('file');
$names = array('Class1.php', 'Class2.php', 'Class3.php');
$finder->sortByName();
$files = $finder->discard('Class.java')->in($dataDir);
$t->is(count($files), 3, '->discard() found 3 files');
for ($i = 0; $i != count($files); ++$i) {
    $t->is(nbFileSystem::getFileName($files[$i]), $names[$i], '->discard() found ' . $names[$i]);
}
$t->comment('nbFileFinder - Test execute function or method');
$GLOBALS['callbackFunctionCount'] = 0;
function callbackFunction()
{
    ++$GLOBALS['callbackFunctionCount'];
}
class CallbackClass
{
    public $callbackMethodCount = 0;
    public function callbackMethod()
    {
        ++$this->callbackMethodCount;
    }
}
$finder = nbFileFinder::create('file');
$finder->execute('callbackFunction');
$finder->add('*.php')->in($dataDir);
$t->is($GLOBALS['callbackFunctionCount'], 3, '->execute() calls "callbackFunction" 3 times');
$object = new CallbackClass();
$finder = nbFileFinder::create('file');
$finder->execute(array($object, 'callbackMethod'));
$finder->add('*.php')->in($dataDir);
$t->is($object->callbackMethodCount, 3, '->execute() calls "callbackMethod" 3 times');
コード例 #13
0
ファイル: nbBackupCommand.php プロジェクト: nubee/bee
 private function findInSubFolder($hudsonHome, $dir, $pattern, $excludeDirs = array())
 {
     $finder = nbFileFinder::create();
     $files = $finder->relative()->prune($excludeDirs)->add($pattern)->in($hudsonHome . '/' . $dir);
     foreach ($files as $key => $file) {
         $files[$key] = $dir . '/' . $file;
     }
     return $files;
 }
コード例 #14
0
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
$cloneFrom = nbConfig::get('symfony_project-clone_from');
$cloneTo = nbConfig::get('symfony_project-clone_to');
$name = nbConfig::get('symfony_project-clone_name');
$t = new lime_test(5);
$t->comment('Symfony Project Clone');
$cmd = new nbSymfonyCloneProjectCommand();
$commandLine = sprintf('%s %s %s', $cloneFrom, $cloneTo, $name);
$finder = nbFileFinder::create('any');
$appFiles = $finder->add('*.*')->remove('.')->remove('..')->relative()->in($cloneFrom);
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Symfony project cloned successfully');
$t->ok(file_exists($cloneTo . '/' . $name), 'project is cloned');
//TODO rivedere directory cache e il test in generale 20???
$t->comment('Total files are 46 with cache and log directories');
$clonedAppFiles = $finder->add('*.*')->remove('.')->remove('..')->relative()->in($cloneTo . '/' . $name);
$t->is(count($clonedAppFiles), 46, 'All files (cache and log are excluded) are cloned');
$fsr = new File_SearchReplace($name, '', $cloneTo . '/' . $name . '/symfony/config/properties.ini', '', false);
$fsr->doSearch();
$t->is($fsr->getNumOccurences(), 1, 'File properties.ini modified');
$fsr = new File_SearchReplace($name, '', $cloneTo . '/' . $name . '/symfony/config/databases.yml', '', false);
$fsr->doSearch();
$t->is($fsr->getNumOccurences(), 2, 'File databases.yml modified');
$fileSystem->rmdir($cloneTo . '/' . $name, true);
コード例 #15
0
ファイル: nbFileSystem.php プロジェクト: nubee/bee
 /**
  * Mirrors a directory to another.
  *
  * @param string   $originDir  The origin directory
  * @param string   $targetDir  The target directory
  * @param sfFinder $finder     An sfFinder instance
  * @param array    $options    An array of options (see copy())
  */
 public function mirror($originDir, $targetDir, nbFileFinder $finder, $options = array())
 {
     $overwrite = isset($options['overwrite']) ? $options['overwrite'] : false;
     foreach ($finder->relative()->in($originDir) as $file) {
         if (is_dir($originDir . DIRECTORY_SEPARATOR . $file)) {
             $this->mkdir($targetDir . DIRECTORY_SEPARATOR . $file);
         } else {
             if (is_file($originDir . DIRECTORY_SEPARATOR . $file)) {
                 $this->copy($originDir . DIRECTORY_SEPARATOR . $file, $targetDir . DIRECTORY_SEPARATOR . $file, $overwrite);
             } else {
                 if (is_link($originDir . DIRECTORY_SEPARATOR . $file)) {
                     $this->symlink($originDir . DIRECTORY_SEPARATOR . $file, $targetDir . DIRECTORY_SEPARATOR . $file);
                 } else {
                     throw new Exception(sprintf('Unable to guess "%s" file type.', $file));
                 }
             }
         }
     }
 }