diff --git a/dev/DevelopmentAdmin.php b/dev/DevelopmentAdmin.php index 982d9dce9..83f5a2daf 100644 --- a/dev/DevelopmentAdmin.php +++ b/dev/DevelopmentAdmin.php @@ -20,12 +20,17 @@ class DevelopmentAdmin extends Controller { $actions = array( "build" => "Build/rebuild this environment (formerly db/build). Call this whenever you have updated your project sources", "tests" => "See a list of unit tests to run", + "tests/all" => "Run all tests", + "modules/add" => "Add a module, for example, 'sake dev/modules/add ecommerce'", "tasks" => "See a list of build tasks to run", "viewcode" => "Read source code in a literate programming style", ); // Web mode if(!Director::is_cli()) { + // This action is sake-only right now. + unset($actions["modules/add"]); + $renderer = new DebugView(); $renderer->writeHeader(); $renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL()); @@ -57,6 +62,10 @@ class DevelopmentAdmin extends Controller { return new TaskRunner(); } + function modules() { + return new ModuleManager(); + } + function build() { $renderer = new DebugView(); $renderer->writeHeader(); diff --git a/dev/ModuleManager.php b/dev/ModuleManager.php new file mode 100644 index 000000000..f65199f06 --- /dev/null +++ b/dev/ModuleManager.php @@ -0,0 +1,99 @@ +moduleBase . $module; + + if($this->svnUrlExists($svnURL)) { + $moduleDir = strtok($module,'/'); + echo "Linking directory '$moduleDir' to '$svnURL' using svn:externals..."; + $this->svnAddExternal(Director::baseFolder(), $moduleDir, $svnURL); + + echo "Calling SVN update to get the new code..."; + $this->svnUpdate(Director::baseFolder()); + + echo "Rebuilding..."; + + // todo: we should be able to call the 'model' of the builder rather than its 'controller' + // it would make it easier to tailor the output + $da = new DevelopmentAdmin(); + $da->build(); + + } else { + echo "Can't find '$svnURL' in SVN"; + } + + } else { + echo "Bad module '$module'"; + } + + } + + } + } + + + /** + * Calls svn update + */ + protected function svnUpdate($baseDir) { + $CLI_baseDir = escapeshellarg($baseDir); + `svn update $CLI_baseDir`; + } + + /** + * Returns true if the given SVN url exists + */ + protected function svnUrlExists($svnURL) { + $CLI_svnURL = escapeshellarg($svnURL); + $info = `svn info --xml $CLI_svnURL`; + $xmlInfo = new SimpleXmlElement($info); + + return $xmlInfo->entry ? true : false; + } + + /** + * Add a new entry to the svn externals + */ + protected function svnAddExternal($baseDir, $externalDir, $externalURL) { + $CLI_baseDir = escapeshellarg($baseDir); + $oldExternals = trim(`svn propget svn:externals $CLI_baseDir`); + $newExternals = "$oldExternals\n$externalDir/ $externalURL"; + + $CLI_newExternals = escapeshellarg($newExternals); + `svn propset svn:externals $CLI_newExternals $CLI_baseDir`; + } + +} + +?> \ No newline at end of file