public static function getInstance() { if (!self::$instance) { self::$instance = new nbFileSystem(); } return self::$instance; }
protected function execute(array $arguments = array(), array $options = array()) { $timestamp = date('YmdHi', time()); $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']); $destinationDir = nbFileSystem::sanitizeDir($arguments['destination-dir']); $createDestinationDir = isset($options['create-destination-dir']); $archiveName = basename($sourceDir); $archiveDir = dirname($sourceDir); $filename = isset($options['filename']) ? $options['filename'] : sprintf('%s-%s.tar.gz', $archiveName, $timestamp); $this->logLine(sprintf('Archiving %s in %s/%s', $sourceDir, $destinationDir, $filename)); if (!is_dir($sourceDir)) { throw new InvalidArgumentException("Source directory not found: " . $sourceDir); } if (!is_dir($destinationDir)) { if (!$createDestinationDir) { throw new InvalidArgumentException("Archive directory not found: " . $destinationDir); } $this->getFileSystem()->mkdir($destinationDir, true); } // Options: // c: compress // v: verbose // z: gzip archive // f: archive to file // C: root dir in the archived file $cmd = sprintf('tar -c%szf %s/%s %s -C"%s"', $this->isVerbose() ? 'v' : '', $destinationDir, $filename, $sourceDir, $archiveDir); $this->executeShellCommand($cmd, true); $this->logLine(sprintf('Directory archived: %s in %s ', $sourceDir, $filename)); return true; }
protected function execute(array $arguments = array(), array $options = array()) { $sourceDir = nbFileSystem::sanitizeDir($arguments['source_dir']); $this->logLine('Updating bee from ' . $sourceDir, nbLogger::COMMENT); $this->executeShellCommand('cd ' . $sourceDir . ' && git pull'); $this->logLine('Bee successfully updated', nbLogger::COMMENT); }
protected function execute(array $arguments = array(), array $options = array()) { $this->logLine('Starting folder synchronization'); $exclude = ''; $include = ''; if (isset($options['config-file'])) { $configDir = nbConfig::get('nb_plugins_dir') . '/nbFileSystemPlugin/config'; $configFilename = $options['config-file']; $this->checkConfiguration($configDir, $configFilename); } if (isset($options['exclude-from']) && file_exists($options['exclude-from'])) { $exclude = ' --exclude-from \'' . $options['exclude-from'] . '\' '; } if (isset($options['include-from']) && file_exists($options['include-from'])) { $include = ' --include-from \'' . $options['include-from'] . '\' '; } $doit = isset($options['doit']) ? '' : '--dry-run'; $delete = isset($options['delete']) ? '--delete' : ''; // Trailing slash must be added after sanitize dir $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']) . '/'; $targetDir = nbFileSystem::sanitizeDir($arguments['target-dir']); $cmd = sprintf('rsync -rzChv %s %s %s %s %s %s', $doit, $include, $exclude, $delete, $sourceDir, $targetDir); $owner = isset($options['owner']) ? $options['owner'] : null; if ($owner) { $cmd = sprintf('sudo -u %s %s', $owner, $cmd); } if (!isset($options['doit'])) { $this->logLine('Executing command: ' . $cmd); } $this->executeShellCommand($cmd); $this->logLine('Folders synchronization completed'); return true; }
protected function execute(array $arguments = array(), array $options = array()) { $this->logLine('Creating Symfony2 project', nbLogger::INFO); $projectBaseDir = nbFileSystem::sanitizeDir($arguments['project-base-dir']); // Download Symfony framework $cmd = sprintf('composer create-project --no-interaction symfony/framework-standard-edition %s/Symfony 2.1.x-dev', $projectBaseDir); $this->executeShellCommand($cmd); // TODO: move web to httpdocs // TODO: change paths in app.php, app_dev.php, app/config/config.yml // TODO: generate the virtual host // Permissions on app/cache and app/logs $cmd = sprintf('sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx %1$s/Symfony/app/cache %1$s/Symfony/app/logs', $projectBaseDir); $this->executeShellCommand($cmd); $cmd = sprintf('sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx %1$s/Symfony/app/cache %1$s/Symfony/app/logs', $projectBaseDir); $this->executeShellCommand($cmd); // Create 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, false); } return true; }
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; }
protected function execute(array $arguments = array(), array $options = array()) { $this->logLine('Running tests', nbLogger::COMMENT); $command = '"' . $arguments['testapp'] . '" '; if (isset($options['output'])) { $command .= '--gtest_output=xml:' . $options['output'] . ' '; $testResultDir = dirname(nbConfig::get('project_testresult')); nbFileSystem::rmdir($testResultDir, true); nbFileSystem::mkdir($testResultDir, true); } // if(isset($options['nocolor'])) // $command .= '--gtest_color=no '; $this->executeShellCommand($command); }
protected function execute(array $arguments = array(), array $options = array()) { $versionFile = $arguments['version-file']; if (!file_exists($versionFile)) { throw new Exception('Version file: ' . $versionFile . ' does not exist'); } $configParser = new nbYamlConfigParser(); $configParser->parseFile($versionFile); $initialVersion = nbConfig::get('version'); $arrayVersion = array(); $arrayVersion = preg_split('/\\./', $initialVersion); $arrayVersion[3]++; $finalVersion = join('.', $arrayVersion); nbFileSystem::replaceTokens($initialVersion, $finalVersion, $versionFile); return true; }
protected function execute(array $arguments = array(), array $options = array()) { $this->logLine('Starting remote folder synchronization'); $exclude = ''; $include = ''; // Trailing slash must be added after sanitize dir $sourceDir = nbFileSystem::sanitizeDir($arguments['source-dir']) . '/*'; $remoteUser = $arguments['remote-user']; $remoteServer = $arguments['remote-server']; $remotePath = nbFileSystem::sanitizeDir($arguments['remote-dir']); if (isset($options['exclude-from']) && file_exists($options['exclude-from'])) { $exclude = ' --exclude-from \'' . $options['exclude-from'] . '\' '; } if (isset($options['include-from']) && file_exists($options['include-from'])) { $include = ' --include-from \'' . $options['include-from'] . '\' '; } $doit = isset($options['doit']) ? '' : '--dry-run'; $delete = isset($options['delete']) ? '--delete' : ''; $cmd = sprintf('rsync -rzChv %s %s %s %s %s -e ssh %s@%s:%s', $doit, $include, $exclude, $delete, $sourceDir, $remoteUser, $remoteServer, $remotePath); $this->executeShellCommand($cmd); $this->logLine('Remote folder synchronization completed'); }
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'); } }
protected function execute(array $arguments = array(), array $options = array()) { $timestamp = isset($options['add-timestamp']) ? date('YmdHi', time()) . '-' : null; $sources = $arguments['sources']; $destination = nbFileSystem::sanitizeDir($arguments['destination']); $force = isset($options['force']); $archiveName = sprintf('%s%s', $timestamp, basename($destination)); $archiveDir = dirname($destination); $this->logLine(sprintf('Creating archive <comment>%s/%s</comment>...', $archiveDir, $archiveName), nbLogger::INFO); foreach ($sources as $key => $source) { $sources[$key] = nbFileSystem::sanitizeDir($source); if (!is_dir($sources[$key])) { if (!is_file($sources[$key])) { throw new InvalidArgumentException("Source not found: " . $sources[$key]); } } } if (!is_dir($archiveDir)) { if (!$force) { throw new InvalidArgumentException("Destination directory not found: " . $archiveDir); } $this->getFileSystem()->mkdir($archiveDir, true); } // Options: // c: compress // v: verbose // z: gzip archive // f: archive to file // C: root dir in the archived file $cmd = sprintf('tar -czf %s/%s %s', $archiveDir, $archiveName, implode(' ', $sources)); $this->executeShellCommand($cmd, true); if ($this->isVerbose()) { $logLine = sprintf("Directories/Files <comment>\n - %s\n</comment>archived in \n <comment>%s/%s</comment>", implode("\n - ", $sources), $archiveDir, $archiveName); } else { $logLine = sprintf("Directories/Files archived in <comment>%s/%s</comment>", $archiveDir, $archiveName); } $this->logLine($logLine, nbLogger::INFO); return true; }
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); } }
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(32); $fs = nbFileSystem::getInstance(); $sourceDir = nbConfig::get('filesystem_dir-transfer_source-dir'); $targetDir = nbFileSystem::sanitizeDir(nbConfig::get('filesystem_dir-transfer_target-dir')); $fileToSync = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-sync'); $folderToExclude = $targetDir . '/' . nbConfig::get('filesystem_test_folder-to-exclude'); $fileToExclude = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-exclude'); $fileToInclude = $targetDir . '/' . nbConfig::get('filesystem_test_file-to-include'); $otherFileToSync = $targetDir . '/' . nbConfig::get('filesystem_test_other-file-to-sync'); $fileToDelete = $targetDir . '/fileToDelete'; $excludeFile = nbConfig::get('filesystem_dir-transfer_exclude-from'); $includeFile = nbConfig::get('filesystem_dir-transfer_include-from'); $cmd = new nbDirTransferCommand(); $fs->touch($fileToDelete); $commandLine = sprintf('--delete %s %s', $sourceDir, $targetDir); $t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Command nbDirTransfer called successfully dry run'); $t->ok(!file_exists($fileToSync), 'fileToSync wasn\'t synchronized in the target site because doit option was not set'); $t->ok(!file_exists($otherFileToSync), 'otherFileToSyn wasn\'t synchronized in the target folder'); $t->ok(!file_exists($folderToExclude), 'folderToExclude wasn\'t synchronized in the target folder'); $t->ok(!file_exists($fileToExclude), 'fileToExclude wasn\'t synchronized in the target folder'); $t->ok(!file_exists($fileToInclude), 'fileToInclude wasn\'t synchronized in the target folder'); $t->ok(file_exists($fileToDelete), 'fileToDelete wasn\'t deleted in the target folder'); $t->ok($cmd->run(new nbCommandLineParser(), '--doit ' . $commandLine), 'Command nbDirTransfer called successfully doit option set'); $t->ok(file_exists($fileToSync), 'fileToSync was synchronized in the target folder'); $t->ok(file_exists($otherFileToSync), 'otherFileToSync was synchronized in the target folder'); $t->ok(file_exists($folderToExclude), 'folderToExclude was synchronized in the target folder'); $t->ok(file_exists($fileToExclude), 'fileToEclude was synchronized in the target folder'); $t->ok(file_exists($fileToInclude), 'fileToInclude was synchronized in the target folder');
<?php require_once dirname(__FILE__) . '/../../../../test/bootstrap/unit.php'; //$configParser->parseFile(dirname(__FILE__) . '/../data/config/symfony2-plugin.yml', '', true); $configParser->parseFile(dirname(__FILE__) . '/../data/config/symfony2-deploy.yml', '', true); $serviceContainer->pluginLoader->loadPlugins(array('nbSymfony2Plugin', 'nbArchivePlugin', 'nbMysqlPlugin', 'nbFileSystemPlugin')); $fileSystem = nbFileSystem::getInstance(); $symfonyRootDir = nbConfig::get('symfony_project-deploy_symfony-root-dir'); $symfonyExePath = nbConfig::get('symfony_project-deploy_symfony-exe-path'); $application = nbConfig::get('test_application'); $environment = nbConfig::get('test_environment');
require_once dirname(__FILE__) . '/../../../bootstrap/unit.php'; nbConfig::set('nb_command_dir', nbConfig::get('nb_sandbox_dir') . '/command'); nbConfig::set('nb_plugins_dir', nbConfig::get('nb_sandbox_dir') . '/plugins'); $commandDir = nbConfig::get('nb_command_dir'); $pluginsDir = nbConfig::get('nb_plugins_dir'); $t = new lime_test(7); //Setup nbFileSystem::getInstance()->mkdir($commandDir); nbFileSystem::getInstance()->mkdir($pluginsDir . '/myPlugin/command', true); nbFileSystem::getInstance()->mkdir($commandDir . '/customFolder'); $cmd = new nbGenerateCommandCommand(); $cmd->run(new nbCommandLineParser(), 'ns:cmd className'); $t->ok(file_exists($commandDir . '/ns/className.php'), 'Command create new CommandFile in command folder'); $cmd->run(new nbCommandLineParser(), '--force ns:cmd className'); $t->ok(file_exists($commandDir . '/ns/className.php'), 'Command can overwrite a file'); $cmd->run(new nbCommandLineParser(), 'ns2:cmd className'); $t->ok(file_exists($commandDir . '/ns2/className.php'), 'Command create new CommandFile in command folder'); $cmd->run(new nbCommandLineParser(), 'cmd className'); $t->ok(file_exists($commandDir . '/className.php'), 'Command can create default (non namespace) commands'); $cmd->run(new nbCommandLineParser(), '-f :cmd className'); $t->ok(file_exists($commandDir . '/className.php'), 'Command can create default (non namespace) commands'); $cmd->run(new nbCommandLineParser(), '--directory=' . $commandDir . '/customFolder :cmd className'); $t->ok(file_exists($commandDir . '/customFolder/className.php'), 'Command accept --directory option'); // plugin command $cmd->run(new nbCommandLineParser(), '--plugin=myPlugin myPluginNs:cmd className'); $t->ok(file_exists($pluginsDir . '/myPlugin/command/myPluginNs/className.php'), 'Command accept --plugin option'); // Tear down nbFileSystem::getInstance()->rmdir($commandDir, true); nbFileSystem::getInstance()->rmdir($pluginsDir, true);
protected function execute(array $arguments = array(), array $options = array()) { $project = $arguments['project']; if (!$options['source']) { throw new Exception('Undefined source'); } if (!$options['destination']) { throw new Exception('Undefined destination'); } if (!$options['username']) { throw new Exception('Undefined username'); } $destName = isset($options['new-name']) ? $options['new-name'] : $project; $source = $options['source'] . '/' . $project; $destination = $options['username'] . '@' . $options['destination'] . ':' . $destName; $authorsFile = isset($options['authors-file']) ? $options['authors-file'] : false; $tempDir = isset($options['temp-dir']) ? $options['temp-dir'] : '~/temp'; $this->logLine('Converting ' . $project, nbLogger::COMMENT); $this->logLine('Source: ' . $source, nbLogger::COMMENT); $this->logLine('Destination: ' . $destination, nbLogger::COMMENT); if ($authorsFile) { $this->logLine('Authors: ' . $destination, nbLogger::COMMENT); } $trunk = isset($options['trunk']) ? $options['trunk'] : false; $tags = isset($options['tags']) ? $options['tags'] : false; $branches = isset($options['branches']) ? $options['branches'] : false; $useStandardLayout = !$trunk && !$tags && !$branches && !isset($options['no-standard-layout']); $this->logLine('Standard layout: ' . ($useStandardLayout ? 'true' : 'false'), nbLogger::COMMENT); $this->logLine('Removing temporary directory: ' . $tempDir, nbLogger::INFO); nbFileSystem::rmdir($tempDir, true); $command = sprintf('git svn clone %s %s', $source, $tempDir); $params = array(' --no-metadata'); if ($authorsFile) { $params[] = '-A' . $authorsFile; } if ($trunk) { $params[] = '-T' . $trunk; } if ($tags) { $params[] = '-t' . $tags; } if ($branches) { $params[] = '-b' . $branches; } if ($useStandardLayout) { $params[] = '--stdlayout'; } $dryRun = isset($options['dry-run']); $this->logLine('Cloning repository', nbLogger::INFO); $this->executeShellCommand($command . implode(' ', $params), $dryRun); $this->logLine('Applying git fix', nbLogger::INFO); $this->executeShellCommand('cd ' . $tempDir . ' && git svn-abandon-fix-refs', $dryRun); $this->executeShellCommand('cd ' . $tempDir . ' && git svn-abandon-cleanup', $dryRun); $this->executeShellCommand('cd ' . $tempDir . ' && git config --remove-section svn', $dryRun); $this->executeShellCommand('cd ' . $tempDir . ' && git config --remove-section svn-remote.svn', $dryRun); $this->logLine('Removing svn references', nbLogger::INFO); if (!isset($options['dry-run'])) { nbFileSystem::rmdir($tempDir . '/.git/svn', true); nbFileSystem::rmdir($tempDir . '/.git/refs/remotes/svn', true); nbFileSystem::rmdir($tempDir . '/.git/logs/refs/remotes/svn', true); } $this->logLine('Pushing to ' . $destination, nbLogger::INFO); $this->executeShellCommand('cd ' . $tempDir . sprintf(' && git remote add origin %s.git', $destination), $dryRun); $this->executeShellCommand('cd ' . $tempDir . ' && git push --all', $dryRun); $this->executeShellCommand('cd ' . $tempDir . ' && git push --tags', $dryRun); }
$t->pass('Command requires 1 argument'); } $t->comment(' 2. bee:install installs correctly on ' . $installDir); $cmd->run(new nbCommandLineParser(), $installDir . ' -s ' . nbConfig::get('nb_bee_dir') . '/'); $t->ok(file_exists($installDir . '/config'), 'Command created config directory in installation folder'); $t->ok(file_exists($installDir . '/data'), 'Command created data directory in installation folder'); $t->ok(file_exists($installDir . '/docs'), 'Command created docs directory in installation folder'); $t->ok(file_exists($installDir . '/lib'), 'Command created lib directory in installation folder'); $t->ok(file_exists($installDir . '/plugins'), 'Command created plugin directory in installation folder'); $t->ok(file_exists($installDir . '/test'), 'Command created test directory in installation folder'); $t->ok(file_exists($installDir . '/bee'), 'Command created bee file in installation folder'); /* if (PHP_OS == "Linux") { $t->ok(file_exists('/usr/bin/bee'), 'Command create symbolic link bee /usr/bin'); } else if (PHP_OS == "WINNT") { $t->pass( "TODO: check symbolic link"); } */ /* if (PHP_OS == "Linux") { $shell->execute( 'rm -rf '.$installDir); //$shell->execute( 'rm /usr/bin/bee'); } else if (PHP_OS == "WINNT") { $shell->execute( 'rd /S /Q '.$installDir); }*/ // Tear down nbFileSystem::getInstance()->rmdir($installDir, true); $t->ok(!file_exists($installDir), 'Installation folder removed successfully');
$finder = nbFileFinder::create('file'); $names = array('Class1.php', 'Class2.php', 'Class3.php'); $finder->sortByName(); $files = $finder->add('*.php')->in($dataDir); $t->is(count($files), 3, '->add() found 3 files'); for ($i = 0; $i != count($files); ++$i) { $t->is(nbFileSystem::getFileName($files[$i]), $names[$i], '->add() found ' . $names[$i]); } $t->comment('nbFileFinder - Test discard and sort'); $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; } }
protected function execute(array $arguments = array(), array $options = array()) { $time = strftime('%Y%m%d-%H%M%S', time()); $this->log("[{$time}] - Starting backup procedure...\n", nbLogger::COMMENT); $hudsonHome = $arguments['hudsonHome']; if (!is_dir($hudsonHome)) { throw new Exception('Cannot find hudson home directory: ' . $hudsonHome); } $finder = nbFileFinder::create(); // hudson config $files = $finder->setType('file')->relative()->maxdepth(0)->add('*.xml')->in($hudsonHome); $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'users', '*')); $excludeDirs = array(); if (isset($options['builds'])) { $this->log(" + including job builds\n", nbLogger::COMMENT); } else { $excludeDirs[] = 'builds'; } if (isset($options['workspace'])) { $this->log(" + including job workspace\n", nbLogger::COMMENT); } else { $excludeDirs[] = 'workspace'; } $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'jobs', '*', $excludeDirs)); if (isset($options['fingerprints'])) { $this->log(" + including fingerprints\n", nbLogger::COMMENT); $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'fingerprints', '*')); } if (isset($options['usercontent'])) { $this->log(" + including userContent\n", nbLogger::COMMENT); $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'userContent', '*')); } if (isset($options['hudson'])) { $this->log(" + including hudson server\n", nbLogger::COMMENT); $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'war', '*')); $files = array_merge($files, $this->findInSubFolder($hudsonHome, 'plugins', '*')); } $numFiles = count($files); // perform file copy if (isset($options['copy'])) { $backupHome = $options['copy']; if (isset($options['autoname'])) { $backupHome .= '-' . $time; } nbFileSystem::mkdir($backupHome, true); $progress = new nbProgress($numFiles, 8); $this->log("Copying from {$hudsonHome} to {$backupHome} {$numFiles} files... ", nbLogger::COMMENT); foreach ($files as $key => $file) { if (($p = $progress->getProgress($key)) !== null) { $this->log("{$p}% - "); } nbFileSystem::copy($hudsonHome . '/' . $file, $backupHome . '/' . $file); } $this->log("100%\n"); } // create zip file if (isset($options['zip'])) { if (class_exists('ZipArchive')) { $filename = $options['zip']; if (isset($options['autoname'])) { $filename .= '-' . $time; } $filename .= '.zip'; $this->log("Creating ZIP file {$filename} ... ", nbLogger::COMMENT); $zip = new ZipArchive(); if ($zip->open($filename, ZIPARCHIVE::CREATE) !== true) { throw new Exception('[nbBackupCommand:execute] cannot create zip file: ' . $filename); } $progress = new nbProgress($numFiles, 8); foreach ($files as $key => $file) { if (($p = $progress->getProgress($key)) !== null) { $this->log("{$p}% - "); } $zip->addFile($hudsonHome . '/' . $file, $file); } $zip->close(); $this->log("100%\n"); } else { $this->log("Zip support not found\n"); } } $time = strftime('%Y%m%d-%H%M%S', time()); $this->log("[{$time}] - Backup succesful.\n", nbLogger::COMMENT); return true; }
/** * @return nbFileSystem */ public function getFileSystem() { return nbFileSystem::getInstance(); }
<?php require_once dirname(__FILE__) . '/../bootstrap/unit.php'; $mode = '644'; $folder = nbConfig::get('nb_sandbox_dir') . '/folder'; $fs = nbFileSystem::getInstance(); if (php_uname('s') == 'Linux') { $fs->mkdir($folder); $t = new lime_test(1); $cmd = new nbChangeModeCommand(); $commandLine = sprintf('%s %s', $folder, $mode); $t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Folder mode changed successfully'); $fs->rmdir($folder); } else { $t = new lime_test(0); $t->comment('No tests under Windows'); }
<?php require_once dirname(__FILE__) . '/lib/core/autoload/nbAutoload.php'; $autoload = nbAutoload::getInstance(); $autoload->register(); $autoload->addDirectory(dirname(__FILE__) . '/lib/', '*.php', true); $autoload->addDirectory(dirname(__FILE__) . '/vendor/', '*.php', true); $beeDir = nbFileSystem::sanitizeDir(dirname(__FILE__)); nbConfig::set('nb_bee_dir', $beeDir); if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) { nbConfig::set('nb_user_dir', getenv('APPDATA') . '/.bee'); } else { nbConfig::set('nb_user_dir', getenv('HOME') . '/.bee'); } nbConfig::set('nb_user_config', nbConfig::get('nb_user_dir') . '/config.yml'); $yaml = new nbYamlConfigParser(); $yaml->parseFile(nbConfig::get('nb_bee_dir') . '/config/config.yml', '', true); if (file_exists(nbConfig::get('nb_user_config'))) { $yaml->parseFile(nbConfig::get('nb_user_config'), '', true); } if (file_exists('.bee/config.yml')) { $yaml->parseFile('.bee/config.yml', '', true); } if (file_exists('./.bee/' . nbConfig::get('nb_project_config'))) { $projectConfigurationFile = './.bee/' . nbConfig::get('nb_project_config'); } else { if (file_exists('./' . nbConfig::get('nb_project_config'))) { $projectConfigurationFile = './' . nbConfig::get('nb_project_config'); } else { if (file_exists(nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config'))) { $projectConfigurationFile = nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config');