function run_freeze($task, $args) { // check that the symfony librairies are not already freeze for this project if (is_readable(sfConfig::get('sf_lib_dir') . '/symfony')) { throw new Exception('You can only freeze when lib/symfony is empty.'); } if (is_readable(sfConfig::get('sf_data_dir') . '/symfony')) { throw new Exception('You can only freeze when data/symfony is empty.'); } if (is_readable(sfConfig::get('sf_web_dir') . '/sf')) { throw new Exception('You can only freeze when web/sf is empty.'); } if (is_link(sfConfig::get('sf_web_dir') . '/sf')) { pake_remove(sfConfig::get('sf_web_dir') . '/sf', ''); } $symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir'); $symfony_data_dir = sfConfig::get('sf_symfony_data_dir'); pake_echo_action('freeze', 'freezing lib found in "' . $symfony_lib_dir . '"'); pake_echo_action('freeze', 'freezing data found in "' . $symfony_data_dir . '"'); pake_mkdirs(sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'symfony'); pake_mkdirs(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'symfony'); $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, $symfony_lib_dir, sfConfig::get('sf_lib_dir') . '/symfony'); pake_mirror($finder, $symfony_data_dir, sfConfig::get('sf_data_dir') . '/symfony'); pake_rename(sfConfig::get('sf_data_dir') . '/symfony/web/sf', sfConfig::get('sf_web_dir') . '/sf'); // change symfony paths in config/config.php file_put_contents('config/config.php.bak', "{$symfony_lib_dir}#{$symfony_data_dir}"); _change_symfony_dirs("dirname(__FILE__).'/../lib/symfony'", "dirname(__FILE__).'/../data/symfony'"); // install the command line pake_copy($symfony_data_dir . '/bin/symfony.php', 'symfony.php'); }
function run_propel_init_admin($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $theme = isset($args[3]) ? $args[3] : 'default'; try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name, 'THEME' => $theme); $moduleDir = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // create module structure $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf'); $dirs = sfLoader::getGeneratorSkeletonDirs('sfPropelAdmin', $theme); foreach ($dirs as $dir) { if (is_dir($dir)) { pake_mirror($finder, $dir, $moduleDir); break; } } // customize php and yml files $finder = pakeFinder::type('file')->ignore_version_control()->name('*.php', '*.yml'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); }
function run_propel_generate_crud($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } if (count($args) < 3) { throw new Exception('You must provide your model class name.'); } $theme = isset($args[3]) ? $args[3] : 'default'; $app = $args[0]; $module = $args[1]; $model_class = $args[2]; $sf_root_dir = sfConfig::get('sf_root_dir'); // generate module $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true)); sfConfig::set('sf_module_cache_dir', $tmp_dir); $generator_manager = new sfGeneratorManager(); $generator_manager->initialize(); $generator_manager->generate('sfPropelCrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme)); $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; // copy our generated module $finder = pakeFinder::type('any'); pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir); // change module name pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module)); try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name); // customize php and yml files $finder = pakeFinder::type('file')->name('*.php', '*.yml'); pake_replace_tokens($finder, $moduleDir, '##', '##', $constants); // create basic test pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/module/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php'); // customize test file pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants); // delete temp files $finder = pakeFinder::type('any'); pake_remove($finder, $tmp_dir); }
function pake_symlink($origin_dir, $target_dir, $copy_on_windows = false) { if (!function_exists('symlink') && $copy_on_windows) { $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, $origin_dir, $target_dir); return; } $ok = false; if (is_link($target_dir)) { if (readlink($target_dir) != $origin_dir) { unlink($target_dir); } else { $ok = true; } } if (!$ok) { pake_echo_action('link+', $target_dir); symlink($origin_dir, $target_dir); } }
/** * Creates the tarballs for a release */ function run_dist($task = null, $args = array(), $cliOpts = array()) { // copy workspace dir into dist dir, without git pake_mkdirs(Builder::distDir()); $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir())); // remove unwanted files from dist dir // also: do we still need to run dos2unix? // create tarballs $cwd = getcwd(); chdir(dirname(Builder::distDir())); foreach (Builder::distFiles() as $distFile) { // php can not really create good zip files via phar: they are not compressed! if (substr($distFile, -4) == '.zip') { $cmd = Builder::tool('zip'); $extra = '-9 -r'; pake_sh("{$cmd} {$distFile} {$extra} " . basename(Builder::distDir())); } else { $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()) . '/**'); // see https://bugs.php.net/bug.php?id=58852 $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile); pakeArchive::createArchive($finder, '.', $pharFile); rename($pharFile, $distFile); } } chdir($cwd); }
/** * Downloads the extension from its source repository, removes files not to be built * (the list of files to be removed is in part hardcoded and in part specified in * the configuration file). * Options: skip-init, skip-init-fetch, skip-init-clean * * @todo add a dependency on a check-updates task that updates script itself? * @todo split this in two tasks and avoid this unsightly mess of options? */ static function run_init($task = null, $args = array(), $cliopts = array()) { $skip_init = @$cliopts['skip-init']; $skip_init_fetch = @$cliopts['skip-init-fetch'] || $skip_init; $skip_init_clean = @$cliopts['skip-init-clean'] || $skip_init; if (!$skip_init) { $opts = self::getOpts(@$args[0], @$args[1], $cliopts); pake_mkdirs(self::getBuildDir($opts)); $destdir = self::getBuildDir($opts) . '/' . $opts['extension']['name']; if (!SharedLock::acquire($opts['extension']['name'], LOCK_EX, $opts)) { throw new PakeException("Source code locked by another process"); } } if (!$skip_init_fetch) { if (@$opts['svn']['url'] != '') { pake_echo("Fetching code from SVN repository {$opts['svn']['url']}"); pakeSubversion::checkout($opts['svn']['url'], $destdir); /// @todo test that we got at least one file if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { sleep(3); } } else { if (@$opts['git']['url'] != '') { pake_echo("Fetching code from GIT repository {$opts['git']['url']}"); pakeGit::clone_repository($opts['git']['url'], $destdir); if (@$opts['git']['branch'] != '') { /// @todo test checking out a specific branch pakeGit::checkout_repo($destdir, $opts['git']['branch']); /// @todo test that we got at least one file } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { sleep(3); } } else { if (@$opts['file']['url'] != '') { pake_echo("Fetching code from local repository {$opts['file']['url']}"); /// @todo (!important) exclude stuff we know we're going to delete immediately afterwards $files = pakeFinder::type('any')->relative()->in($opts['file']['url']); if (count($files) == 0) { SharedLock::release($opts['extension']['name'], LOCK_EX, $opts); throw new pakeException("Empty source repo option: no files found in {$opts['file']['url']}"); } pake_mirror($files, $opts['file']['url'], $destdir); } else { SharedLock::release($opts['extension']['name'], LOCK_EX, $opts); throw new pakeException("Missing source repo option: either svn:url, git:url or file:url"); } } } } // remove files if (!$skip_init_clean) { // known files/dirs not to be packed / md5'ed /// @todo !important shall we make this configurable? /// @bug 'build' & 'dist' we should probably take from options $files = array('ant/', 'build.xml', '**/.svn', '.git/', 'build/', 'dist/', 'composer.phar', 'composer.lock', '.idea/', 'vendor/'); // hack! when packing ourself, we need to keep this stuff if ($opts['extension']['name'] != 'ezextensionbuilder') { $files = array_merge($files, array('pake/', 'pakefile.php', '**/.gitignore')); } // files from user configuration $files = array_merge($files, $opts['files']['to_exclude']); /// we figured a way to allow user to specify both: /// files in a specific subdir /// files to be removed globally (ie. from any subdir) //pakeFinder::type( 'any' )->name( $files )->in( $destdir ); $files = self::pake_antpattern($files, $destdir); foreach ($files as $key => $file) { if (is_dir($file)) { pake_remove_dir($file); unset($files[$key]); } } pake_remove($files, ''); } if (!$skip_init) { // move package file where it has to be $file = pakeFinder::type('file')->name('package.xml')->maxdepth(0)->in($destdir); if (count($file)) { if ($opts['create']['tarball'] || $opts['create']['zip']) { pake_rename($destdir . '/package.xml', $destdir . '/../../package.xml'); } else { pake_remove($file, ''); } } SharedLock::release($opts['extension']['name'], LOCK_EX, $opts); } }
function run_init_module($task, $args) { if (count($args) < 2) { throw new Exception('You must provide your module name.'); } $app = $args[0]; $module = $args[1]; $sf_root_dir = sfConfig::get('sf_root_dir'); $module_dir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module; if (is_dir($module_dir)) { throw new Exception(sprintf('The directory "%s" already exists.', $module_dir)); } try { $author_name = $task->get_property('author', 'symfony'); } catch (pakeException $e) { $author_name = 'Your name here'; } $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'AUTHOR_NAME' => $author_name); if (is_readable(sfConfig::get('sf_data_dir') . '/skeleton/module')) { $sf_skeleton_dir = sfConfig::get('sf_data_dir') . '/skeleton/module'; } else { $sf_skeleton_dir = sfConfig::get('sf_symfony_data_dir') . '/skeleton/module'; } // create basic application structure $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf'); pake_mirror($finder, $sf_skeleton_dir . '/module', $module_dir); // create basic test pake_copy($sf_skeleton_dir . '/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php'); // customize test file pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants); // customize php and yml files $finder = pakeFinder::type('file')->name('*.php', '*.yml'); pake_replace_tokens($finder, $module_dir, '##', '##', $constants); }
function pake_symlink($origin_dir, $target_dir, $copy_on_windows = false) { if (!function_exists('symlink') && $copy_on_windows) { $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, $origin_dir, $target_dir); return; } $ok = false; if (is_link($target_dir)) { if (readlink($target_dir) != $origin_dir) { unlink($target_dir); } else { $ok = true; } } if (!$ok) { pake_echo_action('link+', $target_dir); // symlink can fail, esp. on windows where user needs admin privileges if (!symlink($origin_dir, $target_dir)) { throw new pakeException('Unable to create symlink "' . $target_dir . '"'); } } }
function run_phpbb_init_module($task, $args) { _phpbb_standard_load($args); $skeleton_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'skeleton'; $module_dir = sfConfig::get('sf_app_module_dir'); $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, $skeleton_dir . DIRECTORY_SEPARATOR . 'module', $module_dir); }