From 8b6864468b3185c02f2aa4a9882a079a5e5673ff Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 19 Nov 2012 23:30:19 +0100 Subject: [PATCH] API Moved build tools to new silverstripe-buildtools module --- build.properties.default | 6 - build.xml | 504 +------------------------------ changelog-definitions.default | 12 - dependent-modules.default | 38 --- tools/CreateChangelog.php | 301 ------------------ tools/FindRepositoriesTask.php | 77 ----- tools/GitStashTask.php | 43 --- tools/LoadModulesTask.php | 474 ----------------------------- tools/SilverStripeBuildTask.php | 84 ------ tools/UpdateTranslationsTask.php | 229 -------------- tools/lib/sources.php | 151 --------- tools/lib/tools.php | 150 --------- 12 files changed, 6 insertions(+), 2063 deletions(-) delete mode 100644 build.properties.default delete mode 100644 changelog-definitions.default delete mode 100644 dependent-modules.default delete mode 100644 tools/CreateChangelog.php delete mode 100644 tools/FindRepositoriesTask.php delete mode 100644 tools/GitStashTask.php delete mode 100644 tools/LoadModulesTask.php delete mode 100644 tools/SilverStripeBuildTask.php delete mode 100644 tools/UpdateTranslationsTask.php delete mode 100644 tools/lib/sources.php delete mode 100644 tools/lib/tools.php diff --git a/build.properties.default b/build.properties.default deleted file mode 100644 index fbd41f7..0000000 --- a/build.properties.default +++ /dev/null @@ -1,6 +0,0 @@ -getlocalization.framework.project = sapphire -getlocalization.framework.user = silverstripe -getlocalization.framework.password = -getlocalization.cms.project = silverstripe_cms -getlocalization.cms.user = silverstripe -getlocalization.cms.password = \ No newline at end of file diff --git a/build.xml b/build.xml index bd274ae..7dc8bf4 100644 --- a/build.xml +++ b/build.xml @@ -1,124 +1,23 @@ - - + - - - - - - + + - - - - - - - - - - - - -SilverStripe Project Build ------------------------------------- - -This build file contains targets to assist in creating new SilverStripe builds and releases. -Run "phing -l" to get a full list of available targets. - - -Options: - --Dbasedir = . (the base directory to operate on) --Ddependent-modules-file = dependent-modules (the file of dependent modules to use when updating modules) --Dchangelog-definitions-file = changelog-definitions (the file of changelog-definitions to use when generating the changelog) --DchangelogSort = type (sort the changelog file by commit type) --Dni_build = false (non-interactive build, overwrite local changes without prompting) - --Dmodurl (the URL of a single module to load when using add_modules) --Dmodule (the name of the module directory to create the module in when using add_modules) - --Darchivename (the name of the created archive file) --Darchivedest (the destination directory to put the archive) - --Dtagname (the name of the tag/branch to check out or to create as a new tag) --DincludeBaseDir (whether or not to include the base dir in a git checkout operation) - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -154,395 +53,4 @@ Options: - - - - - - - - Please enter the name of the tag - - - - - - - - Push local tags to origin? - - - - - - - - - - - - - - - - - - - - Please enter the name of the tag or branch you wish to checkout - - - - - - - - - - - Include the base dir '${basedir}' in checkout? - - - - - - - - - - - - - - - - - - - - Please choose a version - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please choose a version - - - - - - - - - A new SilverStripe release is ready, and although it hasn't been publicly announced yet, is available at the following locations: - -${release_url}SilverStripe-cms-v${version}.tar.gz -${release_url}SilverStripe-framework-v${version}.tar.gz -${release_url}SilverStripe-cms-v${version}.zip -${release_url}SilverStripe-framework-v${version}.zip - -Thanks, -Your friendly automated release script. - - - - - - - - - - - - - - - - - - - - - - - - Please enter the module's git or svn URL - - - - - - - - - - - Please enter the module's name (i.e. the folder to module should be created in) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/changelog-definitions.default b/changelog-definitions.default deleted file mode 100644 index e54f2fb..0000000 --- a/changelog-definitions.default +++ /dev/null @@ -1,12 +0,0 @@ -# Use this file to define which git repositories the "phing changlog" task will include when generating -# a changelog.md file. -# -# Any paths not mentioned here will be excluded from the changelog. The script will ignore any paths that are not git -# repositories, or are otherwise invalid. -# -# Leave the fields blank to include all commits. -# -# -. 2.4.4-rc1 2.4.5 -framework 2.4.4-rc1 2.4.5 -cms 2.4.4-rc1 2.4.5 diff --git a/dependent-modules.default b/dependent-modules.default deleted file mode 100644 index 60f5c0a..0000000 --- a/dependent-modules.default +++ /dev/null @@ -1,38 +0,0 @@ -# File format -# ----------- -# Each line represents one dependent module. -# -# local_module_folder[:git_branch|:svn_revision_number] repository_url [run_dev_build=true] [local] -# -# Note that the local_module_folder can contain subfolders delimited via '/' characters -# A specific git branch or SVN revision can be added in by specifying after the local -# foldername, separated by a colon. By default, the 'master' branch of a git repository is used. -# -# Using the "piston" flag will strip versioning information, but keep metadata in the working copy -# to update from version control later on, and merge in potential local changes. -# See http://piston.rubyforge.org for details. -# -# It is recommended to have sqlite3 and cms first with [run_dev_build] set to "false". -# Having this set to 'false' prevents the execution of the dev/build process, meaning it can be -# deferred until all dependencies are in place, specifically the framework module. List -# all additional modules after that. -# -# Examples -# -# frontend-editing:development git://github.com/nyeholt/silverstripe-frontend-editing.git -# themes/mytheme git://local.server/themes/mytheme.git false - - -cms:3.0 git://github.com/silverstripe/silverstripe-cms.git -framework:3.0 git://github.com/silverstripe/sapphire.git -themes/simple:master git://github.com/silverstripe-themes/silverstripe-simple.git - - -# The following are the some other modules you might like to import - -# sqlite3:master git://github.com/silverstripe-labs/silverstripe-sqlite3.git -# userforms:master:0.3.0 git://github.com/silverstripe/silverstripe-userforms.git -# securefiles http://svn.polemic.net.nz/silverstripe/modules/SecureFiles/tags/0.30/ - - - diff --git a/tools/CreateChangelog.php b/tools/CreateChangelog.php deleted file mode 100644 index 7906a9e..0000000 --- a/tools/CreateChangelog.php +++ /dev/null @@ -1,301 +0,0 @@ - array('/^(APICHANGE|API-CHANGE|API CHANGE|API)\s?:?/i'), - 'Features and Enhancements' => array('/^(ENHANCEMENT|ENHNACEMENT|FEATURE|NEW)\s?:?/i'), - 'Bugfixes' => array('/^(BUGFIX|BUGFUX|BUG|FIX)\s?:?/i','/^(BUG FIX)\s?:?/i'), - 'Other' => array('/^(MINOR)\s?:?/i') - ); - - public $commitUrls = array( - '.' => 'https://github.com/silverstripe/silverstripe-installer/commit/%s', - 'framework' => 'https://github.com/silverstripe/sapphire/commit/%s', - 'cms' => 'https://github.com/silverstripe/silverstripe-cms/commit/%s', - 'themes/simple' => 'https://github.com/silverstripe-themes/silverstripe-simple/commit/%s', - ); - - public $ignoreRules = array( - '/^Merge/', - '/^Blocked revisions/', - '/^Initialized merge tracking /', - '/^Created (branches|tags)/', - '/^NOTFORMERGE/', - '/^\s*$/' - ); - - public function setDefinitions($definitions) { - $this->definitions = $definitions; - } - - public function setBaseDir($base) { - $this->baseDir = realpath($base); - } - - public function setSort($sort) { - $this->sort = $sort; - } - - public function setFilter($filter) { - $this->filter = $filter; - } - - /** - * Checks is a folder is a version control repository - */ - protected function isRepository($dir_path, $filter) { - $dir = $dir_path; - - if (file_exists($dir)) { - // open this directory - if ($handle = opendir($dir)) { - - // get each file - while (false !== ($file = readdir($handle))) { - if ($file == $filter && is_dir($file)) { - if ($filter == '.git') { //extra check for git repos - if (file_exists($dir.'/'.$file.'/HEAD')) { - return true; //$dir is a git repository - } - } else { //return true for .svn repos - return true; - } - } - } - - echo "Folder '$dir' is not a $filter repository\n"; - } - } else { - echo "Folder '$dir' does not exist\n"; - } - - return false; - } - - protected function isGitRepo($dir) { - return $this->isRepository($dir, '.git'); - } - - protected function isSvnRepo($dir) { - return $this->isRepository($dir, '.svn'); - } - - protected function gitLog($path, $from = null, $to = null) { - //set the from -> to range, depending on which os these have been set - if ($from && $to) $range = " $from..$to"; - elseif ($from) $range = " $from..HEAD"; - else $range = ""; - - $this->log(sprintf('Changing to directory "%s"', $path), Project::MSG_INFO); - - chdir("$this->baseDir/$path"); //switch to the module's path - - // Internal serialization format, ideally this would be JSON but we can't escape characters in git logs. - $log = $this->exec("git log --pretty=tformat:\"message:%s|||author:%aN|||abbrevhash:%h|||hash:%H|||date:%ad|||timestamp:%at\" --date=short {$range}", true); - - chdir($this->baseDir); //switch the working directory back - - return $log; - } - - /** Sort by the first two letters of the commit string. - * Put any commits without BUGFIX, ENHANCEMENT, etc. at the end of the list - */ - function sortByType($commits) { - $groupedByType = array(); - - // sort by timestamp - usort($commits, function($a, $b) { - if($a['timestamp'] == $b['timestamp']) return 0; - else return ($a['timestamp'] > $b['timestamp']) ? -1 : 1; - }); - - foreach($commits as $k => $commit) { - // TODO - // skip ignored revisions - // if(in_array($commit['changeset'], $this->ignorerevisions)) continue; - - // Remove email addresses - $commit['message'] = preg_replace('/(?)/mi', '', $commit['message']); - - // Condense git-style "From:" messages (remove preceding newline) - if(preg_match('/^From\:/mi', $commit['message'])) { - $commit['message'] = preg_replace('/\n\n^(From\:)/mi', ' $1', $commit['message']); - } - - $matched = false; - foreach($this->types as $name => $rules) { - if(!isset($groupedByType[$name])) $groupedByType[$name] = array(); - foreach($rules as $rule) { - if(!$matched && preg_match($rule, $commit['message'], $matches)) { - // @todo The fallback rule on other can't be replaced, as it doesn't match a full prefix - $commit['message'] = trim(preg_replace($rule, '', $commit['message'])); - $groupedByType[$name][] = $commit; - $matched = true; - } - } - } - if(!$matched) { - if(!isset($groupedByType['Other'])) $groupedByType['Other'] = array(); - $groupedByType['Other'][] = $commit; - } - - } - - // // remove all categories which should be ignored - // if($this->categoryIgnore) foreach($this->categoryIgnore as $categoryIgnore) { - // if(isset($groupedByType[$categoryIgnore])) unset($groupedByType[$categoryIgnore]); - // } - - return $groupedByType; - } - - function commitToArray($commit) { - $arr = array(); - $parts = explode('|||', $commit); - foreach($parts as $part) { - preg_match('/([^:]*)\:(.*)/', $part, $matches); - $arr[$matches[1]] = $matches[2]; - } - - return $arr; - } - - static function isupper($i) { - return (strtoupper($i) === $i); - } - static function islower($i) { - return (strtolower($i) === $i); - } - - public function main() { - error_reporting(E_ALL); - - chdir($this->baseDir); //change current working directory - - //parse the definitions file - $items = file($this->definitions); - $repos = array(); //git (or svn) repos to scan - foreach ($items as $item) { - $item = trim($item); - if (strpos($item, '#') === 0) { - continue; - } - - $bits = preg_split('/\s+/', $item); - - if (count($bits) == 1) { - $repos[$bits[0]] = ""; - } elseif (count($bits) == 2) { - $repos[$bits[0]] = array($bits[1], null); //framework => array(from => HEAD) - } elseif (count($bits) == 3) { - $repos[$bits[0]] = array($bits[1],$bits[2]); //framework => array(from => to) - } else { - continue; - } - } - - //check all the paths are valid git repos - $gitRepos = array(); - $svnRepos = array(); - foreach($repos as $path => $range) { - if ($this->isGitRepo($path)) $gitRepos[$path] = $range; //add all git repos to a special array - //TODO: for svn support use the isSvnRepo() method to add repos to the svnRepos array - } - - //run git log - $log = array(); - foreach($gitRepos as $path => $range) { - $logForPath = array(); - if (!empty($range)) { - $from = (isset($range[0])) ? $range[0] : null; - $to = (isset($range[1])) ? $range[1] : null; - $logForPath = explode("\n", $this->gitLog($path, $from, $to)); - } else { - $logForPath = explode("\n", $this->gitLog($path)); - } - foreach($logForPath as $commit) { - if(!$commit) continue; - $commitArr = $this->commitToArray($commit); - $commitArr['path'] = $path; - // Avoid duplicates by keying on hash - $log[$commitArr['hash']] = $commitArr; - } - } - - // Remove ignored commits - foreach($log as $k => $commit) { - $ignore = false; - foreach($this->ignoreRules as $ignoreRule) { - if(preg_match($ignoreRule, $commit['message'])) { - unset($log[$k]); - continue; - } - } - } - - //sort the output (based on params), grouping - if ($this->sort == 'type') { - $groupedLog = $this->sortByType($log); - } else { - //leave as sorted by default order - $groupedLog = array('All' => $log); - } - - //filter out commits we don't want - // if ($this->filter) { - // foreach($groupedLog as $key => $item) { - // if (preg_match($this->filter, $item)) unset($groupedLog[$key]); - // } - // } - - //convert to string - //and generate markdown (add list to beginning of each item) - $output = "\n"; - foreach($groupedLog as $groupName => $commits) { - if(!$commits) continue; - - $output .= "\n### $groupName\n\n"; - - foreach($commits as $commit) { - if(isset($this->commitUrls[$commit['path']])) { - $hash = sprintf('[%s](%s)', - $commit['abbrevhash'], - sprintf($this->commitUrls[$commit['path']], $commit['abbrevhash']) - ); - } else { - $hash = sprintf('[%s]', $commit['abbrevhash']); - } - $commitStr = sprintf('%s %s %s (%s)', - $commit['date'], - $hash, - // Avoid rendering HTML in markdown - str_replace(array('<', '>'), array('<', '>'), $commit['message']), - $commit['author'] - ); - // $commitStr = sprintf($this->exec("git log --pretty=tformat:\"%s\" --date=short {$hash}^..{$hash}", true), $this->gitLogFormat); - $output .= " * $commitStr\n"; - } - } - - $this->project->setProperty('changelogOutput',$output); - } -} - -?> diff --git a/tools/FindRepositoriesTask.php b/tools/FindRepositoriesTask.php deleted file mode 100644 index aa4f2fa..0000000 --- a/tools/FindRepositoriesTask.php +++ /dev/null @@ -1,77 +0,0 @@ -targetDir = $targetDir; - } - - public function setIncludeTarget($includeTarget) { - $this->includeTarget = $includeTarget; - } - - /** - * Recursively lists a folder and includes only those directories that have the filter parameter as a sub-item - */ - protected function recursiveListDirFilter($dir, &$result, $filter = '.git') { - $dir = realpath($dir); - - // open this directory - if ($handle = opendir($dir)) { - - // get each git entry - while (false !== ($file = readdir($handle))) { - if ($file == "." || $file == "..") continue; - //var_dump($file); - if ($file == '.git' && is_dir($file)) { - if (file_exists($dir.'/'.$file.'/HEAD')) { - $result[] = $dir; //$dir is a git repository - } - } else { - $path = $dir.'/'.$file; - if (is_dir($path)) { - $this->recursiveListDirFilter($path, $result, $filter); - } - } - } - } - - // close directory - closedir($handle); - - return $result; - } - - public function main() { - if (!is_dir($this->targetDir)) { - throw new BuildException("Invalid target directory: $this->targetDir"); - } - - $gitDirs = array(); - $this->recursiveListDirFilter($this->targetDir, $gitDirs, '.git'); - - $gitDirsOutput = array(); - if (!$this->includeTarget) { //don't include the target dir - foreach($gitDirs as $dir) { - if ($dir != $this->targetDir && $dir != realpath($this->targetDir)) { - $gitDirsOutput[] = $dir; - } - } - } else { - $gitDirsOutput = $gitDirs; - } - - $this->project->setProperty('GitReposList',implode(',',$gitDirsOutput)); - } -} - -?> \ No newline at end of file diff --git a/tools/GitStashTask.php b/tools/GitStashTask.php deleted file mode 100644 index 4af925d..0000000 --- a/tools/GitStashTask.php +++ /dev/null @@ -1,43 +0,0 @@ -repository = $repo; - } - - public function setGitPath($gitPath) { - $this->gitPath = $gitPath; - } - - public function setPop($pop) { - $this->pop = $pop; - } - - public function main() { - if (!is_dir($this->repository)) { - throw new BuildException("Invalid target directory: $this->repository"); - } - - $cwd = realpath(getcwd()); - - chdir($this->repository); - - if ($this->pop == true) $result = parent::exec("$this->gitPath stash pop",true); - else $result = parent::exec("$this->gitPath stash",true); - - if ($result) echo $result; - - chdir($cwd); - } -} - -?> \ No newline at end of file diff --git a/tools/LoadModulesTask.php b/tools/LoadModulesTask.php deleted file mode 100644 index f609ac4..0000000 --- a/tools/LoadModulesTask.php +++ /dev/null @@ -1,474 +0,0 @@ - - * - */ -class LoadModulesTask extends SilverStripeBuildTask { - /** - * Character used to separate the module/revision name from the output path - */ - const MODULE_SEPARATOR = ':'; - - /** - * The file that defines the dependency - * - * @var String - */ - private $file = ''; - /** - * Optionally specify a module name - * - * @var String - */ - private $name = ''; - /** - * And a module url - * @var String - */ - private $url = ''; - - /** - * Is this a non-interactive build session? - * @var boolean - */ - private $nonInteractive = false; - - public function setNoninteractive($v) { - if (!strpos($v, '${') && $v == 'true' || $v == 1) { - $this->nonInteractive = true; - } - } - - public function setFile($v) { - $this->file = $v; - } - - public function setName($v) { - $this->name = $v; - } - - public function setUrl($v) { - $this->url = $v; - } - - public function main() { - // $this->configureEnvFile(); - - if ($this->name) { - $this->loadModule($this->name, $this->url); - } else { - // load the items from the dependencies file - if (!file_exists($this->file)) { - throw new BuildException("Modules file " . $this->modulesFile . " cannot be read"); - } - - $items = file($this->file); - foreach ($items as $item) { - $item = trim($item); - if (strpos($item, '#') === 0) { - continue; - } - - $bits = preg_split('/\s+/', $item); - // skip malformed lines - if (count($bits) < 2) { - continue; - } - - $moduleName = trim($bits[0], '/'); - $url = trim($bits[1], '/'); - $storeLocally = false; - $usePiston = false; - if (isset($bits[2])) { - $devBuild = $bits[2] == 'true'; - $storeLocally = $bits[2] == 'local'; - $usePiston = $bits[2] == 'piston'; - if (isset($bits[3])) { - $storeLocally = $bits[3] == 'local'; - $usePiston = $bits[3] == 'piston'; - } - } - - $this->loadModule($moduleName, $url, $devBuild, $storeLocally, $usePiston); - } - } - } - - /** - * Actually load the module! - * - * @param String $moduleName - * @param String $url - * @param boolean $devBuild - * Do we run a dev/build? - * @param boolean $storeLocally - * Should we store the module locally, for it to be included in - * the local project's repository? - * @param boolean $usePiston Same as $storeLocally, but retain versioning metadata in piston. - */ - protected function loadModule($moduleName, $url, $devBuild = false, $storeLocally=false, $usePiston=false) { - $git = strrpos($url, '.git') == (strlen($url) - 4); - $branch = 'master'; - - $originalName = $moduleName; - - if (strpos($moduleName, self::MODULE_SEPARATOR) > 0) { - $branch = substr($moduleName, strpos($moduleName, self::MODULE_SEPARATOR) + 1); - $moduleName = substr($moduleName, 0, strpos($moduleName, self::MODULE_SEPARATOR)); - } - - $md = $this->loadMetadata(); - if (!isset($md['store'])) { - // backwards compatibility - $md['store'] = false; - } - - // create loader - if($usePiston) { - $loader = new LoadModulesTask_PistonLoader($this, $moduleName, $url, $branch); - } elseif($git) { - $loader = new LoadModulesTask_GitLoader($this, $moduleName, $url, $branch); - } else { - $loader = new LoadModulesTask_SubversionLoader($this, $moduleName, $url, $branch); - } - - // check the module out if it doesn't exist - if (!file_exists($moduleName)) { - $this->log("Check out $moduleName from $url"); - - // Create new working copy - $loader->checkout($storeLocally); - - // Ignore locally added modules from base working copy. - // Only applies when this base contains versioning information. - // Note: This is specific to the base working copy, not the module itself. - if (!$storeLocally && !$usePiston && file_exists('.gitignore')) { - $gitIgnore = file_get_contents('.gitignore'); - if (strpos($gitIgnore, $moduleName) === false) { - $this->exec("echo $moduleName >> .gitignore"); - } - } - } else { - $this->log("Updating $moduleName $branch from $url"); - - // Check for modifications - // TODO Shows all files as modified when switching repository types or branches' - $overwrite = true; - $mods = $loader->getModifiedFiles(); - if (strlen($mods) && !$storeLocally) { - $this->log("The following files are locally modified"); - $this->log($mods); - if (!$this->nonInteractive) { - $overwrite = strtolower(trim($this->getInput("Overwrite local changes? [y/N]"))); - $overwrite = $overwrite == 'y'; - } - } - - // get the metadata and make sure it's not the same - // TODO Doesn't handle switch from git to svn repositories - if ($md && isset($md[$moduleName]) && isset($md[$moduleName]['url'])) { - if ( - $md[$moduleName]['url'] != $url - || $md[$moduleName]['store'] != $storeLocally - || $md[$moduleName]['piston'] != $usePiston - ) { - if ($overwrite) { - // delete the directory and reload the module - $this->log("Deleting $moduleName and reloading"); - unset($md[$moduleName]); - $this->writeMetadata($md); - rrmdir($moduleName, true); - // TODO Doesn't handle changes between svn/git/piston - $loader->checkout($storeLocally); - return; - } else { - throw new Exception("You have chosen not to overwrite changes, but also want to change your " . - "SCM settings. Please resolve changes and try again"); - } - } - } - - // Update existing versioned copy - $loader->update($overwrite); - } - - // Write new metadata - $metadata = array( - 'url' => $url, - 'store' => $storeLocally, - 'piston' => $usePiston, - 'branch' => str_replace($moduleName, '', $originalName), - ); - $md[$moduleName] = $metadata; - $this->writeMetadata($md); - - // Make sure to remove from the .gitignore file - don't need to do it EVERY - // run, but it's better than munging code up above - if ($storeLocally && file_exists('.gitignore')) { - $gitIgnore = file('.gitignore'); - $newIgnore = array(); - foreach ($gitIgnore as $line) { - $line = trim($line); - if (!$line || $line == $moduleName || $line == "$moduleName/") { - continue; - } - $newIgnore[] = $line; - } - file_put_contents('.gitignore', implode("\n", $newIgnore)); - } - - if ($devBuild) $this->devBuild(); - } - - protected function loadMetadata() { - $metadataFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phing-metadata'; - - $md = array(); - if (file_exists($metadataFile)) { - $md = unserialize(file_get_contents($metadataFile)); - } - - return $md; - } - - protected function writeMetadata($md) { - $metadataFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phing-metadata'; - file_put_contents($metadataFile, serialize($md)); - } - - -} - -if (!function_exists('rrmdir')) { - function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir . "/" . $object) == "dir") - rrmdir($dir . "/" . $object); else - unlink($dir . "/" . $object); - } - } - reset($objects); - rmdir($dir); - } - } -} - -class LoadModulesTask_Loader { - - /** - * @var SilverStripeBuildTask - */ - protected $callingTask; - - /** - * @var string - */ - protected $url; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $branch; - - /** - * @var boolean - */ - protected $nonInteractive = false; - - /** - * @param SilverStripeBuildTask Phing crashes when extending the loader from SilverStripeBuildTask - * @param String - * @param String - * @param String - */ - function __construct($callingTask, $name, $url, $branch = null) { - $this->callingTask = $callingTask; - $this->name = $name; - $this->url = $url; - $this->branch = $branch; - } - - /** - * Check out a new working copy. - * Call {@link storeLocally()} afterwards to remove versioning information - * from the working copy. - */ - function checkout($storeLocally = false) { - // noop - } - - /** - * Update an existing working copy - */ - function update($overwrite = true) { - // noop - } - - /** - * @return array - */ - function getModifiedFiles() { - // noop - } - -} - -class LoadModulesTask_GitLoader extends LoadModulesTask_Loader { - - function checkout($storeLocally = false) { - $branch = $this->branch; - $currentDir = getcwd(); - $this->callingTask->exec("git clone $this->url $this->name"); - - if ($branch != 'master') { - // check if we're also hooking onto a revision - $commitId = null; - if (strpos($this->branch, LoadModulesTask::MODULE_SEPARATOR) > 0) { - $commitId = substr($branch, strpos($branch, LoadModulesTask::MODULE_SEPARATOR) + 1); - $branch = substr($branch, 0, strpos($branch, LoadModulesTask::MODULE_SEPARATOR)); - } - // need to make sure we've pulled from the correct branch also - if ($branch != 'master') { - $this->callingTask->exec("cd $this->name && git checkout -f -b $branch --track origin/$branch && cd \"$currentDir\""); - } - - if ($commitId) { - $this->callingTask->exec("cd $this->name && git checkout $commitId && cd \"$currentDir\""); - } - } - - if($storeLocally) rrmdir("$this->name/.git"); - } - - function getModifiedFiles() { - $currentDir = getcwd(); - $statCmd = "git diff --name-status"; - return trim($this->callingTask->exec("cd $this->name && $statCmd && cd \"$currentDir\"", true)); - } - - /** - * - * @param boolean $overwrite - */ - public function update($overwrite = true) { - $branch = $this->branch; - $currentDir = getcwd(); - - $commitId = null; - // Extract the branch and the commit to use for the update - if(strpos($branch, LoadModulesTask::MODULE_SEPARATOR) > 0) { - $commitId = substr($branch, strpos($branch, LoadModulesTask::MODULE_SEPARATOR) + 1); - $branch = substr($branch, 0, strpos($branch, LoadModulesTask::MODULE_SEPARATOR)); - } - - // Finds the current checked out branch - $cliBranches = trim($this->callingTask->exec("cd $this->name && git branch && cd \"$currentDir\"", true)); - $currentBranch = 'master'; - foreach(explode(PHP_EOL, $cliBranches) as $cliBranch) { - if(strstr($cliBranch, '* ') !== false) { - $currentBranch = str_replace('* ', '', $cliBranch); - break; - } - } - - $overwriteOpt = $overwrite ? '-f' : ''; - - // We are already on the target branch, don't checkout it again - if($currentBranch == $branch) { - $this->callingTask->exec("cd $this->name && git pull origin $branch && cd \"$currentDir\""); - } else { - $this->callingTask->exec("cd $this->name && git checkout $overwriteOpt $branch && git pull origin $branch && cd \"$currentDir\""); - } - - if ($commitId) { - $this->callingTask->exec("cd $this->name && git checkout $commitId && cd \"$currentDir\""); - } - } - -} - -class LoadModulesTask_SubversionLoader extends LoadModulesTask_Loader { - - function checkout($storeLocally = false) { - $revision = ''; - if ($this->branch != 'master') { - $revision = " --revision $this->branch "; - } - - $cmd = ($storeLocally) ? 'export' : 'co'; - $this->callingTask->exec("svn $cmd $revision $this->url $this->name"); - } - - function update($overwrite = true) { - $branch = $this->branch; - $currentDir = getcwd(); - - $revision = ''; - if ($branch != 'master') { - $revision = " --revision $branch "; - } - - echo $this->callingTask->exec("svn up $revision $this->name"); - } - - function getModifiedFiles() { - $currentDir = getcwd(); - $statCmd = "svn stat"; - return trim($this->callingTask->exec("cd $this->module && $statCmd && cd \"$currentDir\"", true)); - } - -} - -class LoadModulesTask_PistonLoader extends LoadModulesTask_Loader { - - function __construct($callingTask, $name, $url, $branch = null) { - parent::__construct($callingTask, $name, $url, $branch); - - if(strpos($branch, ':') !== FALSE) { - throw new BuildException(sprintf('Git tags not supported by piston')); - } - } - - function update($overwrite = true) { - $currentDir = getcwd(); - $revision = ($this->branch != 'master') ? " --commit $this->branch " : ''; - $overwriteOpts = ($overwrite) ? '--force' : ''; - echo $this->callingTask->exec("piston update $overwriteOpts $revision $this->name"); - - $this->callingTask->log(sprintf('Updated "$this->name" via piston, please don\'t forget to commit any changes')); - } - - function checkout($storeLocally = false) { - $git = strrpos($this->url, '.git') == (strlen($this->url) - 4); - $revision = ($this->branch != 'master') ? " --commit $this->branch " : ''; - $type = ($git) ? 'git' : 'subversion'; - $this->callingTask->exec("piston import --repository-type $type $revision $this->url $this->name"); - - $this->callingTask->log(sprintf('Created "$this->name" via piston, please don\'t forget to commit any changes')); - } - - /** - * @todo Check base working copy if not dealing with flattened directory. - */ - function getModifiedFiles() { - return ''; - } -} diff --git a/tools/SilverStripeBuildTask.php b/tools/SilverStripeBuildTask.php deleted file mode 100644 index 7290ea3..0000000 --- a/tools/SilverStripeBuildTask.php +++ /dev/null @@ -1,84 +0,0 @@ -cleanupEnv = false; - if (!file_exists($envFile)) { - file_put_contents($envFile, $ssEnv); - $this->cleanupEnv = true; - } - } - - function cleanEnv() { - if ($this->cleanupEnv) { - $envFile = dirname(dirname(__FILE__)).'/_ss_environment.php'; - if (file_exists($envFile)) { - unlink($envFile); - } - } - } - - function devBuild() { - if (file_exists('framework/cli-script.php')) { - $this->log("Running dev/build"); - $this->exec('php framework/cli-script.php dev/build'); - } - } - - - /** - * Get some input from the user - * - * @param string $prompt - * @return string - */ - function getInput($prompt) { - require_once 'phing/input/InputRequest.php'; - $request = new InputRequest($prompt); - $request->setPromptChar(':'); - - $this->project->getInputHandler()->handleInput($request); - $value = $request->getInput(); - return $value; - } - - function exec($cmd, $returnContent = false, $ignoreError = false) { - $ret = null; - $return = null; - - $this->log($cmd, Project::MSG_VERBOSE); - - if ($returnContent) { - $ret = shell_exec($cmd); - } else { - passthru($cmd, $return); - } - - if ($return != 0 && !$ignoreError) { - throw new BuildException("Command '$cmd' failed"); - } - - return $ret; - } -} diff --git a/tools/UpdateTranslationsTask.php b/tools/UpdateTranslationsTask.php deleted file mode 100644 index 85f8741..0000000 --- a/tools/UpdateTranslationsTask.php +++ /dev/null @@ -1,229 +0,0 @@ - 'lang', - 'js' => 'javascript/lang' - ); - - /** - * @var String If set, will use existing files rather than try to download them. - */ - protected $downloadPath; - - public function getGlUser() { - return $this->glUser; - } - - public function setGlUser($newGlUser) { - $this->glUser = $newGlUser; - return $this; - } - - public function getGlPassword() { - return $this->glPassword; - } - - public function setGlPassword($newGlPassword) { - $this->glPassword = $newGlPassword; - return $this; - } - - public function setModulePath($path) { - $this->modulePath = $path; - } - - public function setDownloadPath($path) { - $this->downloadPath = $path; - } - - public function setGlProductName($name) { - $this->glProductName = $name; - } - - public function main() { - if (!is_dir($this->modulePath)) { - throw new BuildException("Invalid target directory: $this->modulePath"); - } - - $downloadPath = $this->downloadPath ? $this->downloadPath : $this->download(); - $files = $this->findFiles($downloadPath); - foreach($files as $file) { - $ext = pathinfo($file, PATHINFO_EXTENSION); - if($ext == 'yml') { - $this->processYmlFile($file); - } elseif($ext == 'js') { - $this->processJavascriptFile($file); - } else { - throw new LogicException(sprintf('Unknown extension: %s', $ext)); - } - } - - } - - /** - * @return File path to a folder structure containing translation files - */ - protected function download() { - $tmpFolder = tempnam(sys_get_temp_dir(), $this->glProductName . '-'); - $tmpFilePath = $tmpFolder . '.zip'; - rename($tmpFolder, $tmpFilePath); - $url = sprintf(self::$url_translations, $this->glProductName); - - $this->log(sprintf("Downloading $url to $tmpFilePath")); - - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERPWD, $this->glUser. ":" . $this->glPassword); - $data = curl_exec($ch); - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if($code >= 400) { - throw new BuildException(sprintf( - 'Error downloading %s: %s %s', - $url, - $code, - $data - )); - } - if(curl_error($ch)) { - throw new BuildException(sprintf( - 'Error downloading %s: %s (#%s)', - $url, - curl_error($ch), - curl_errno($ch) - )); - } - - curl_close($ch); - file_put_contents($tmpFilePath, $data); - - $this->log(sprintf("Extracting to $tmpFolder")); - $this->exec("unzip $tmpFilePath -d $tmpFolder"); - - return $tmpFolder; - } - - /** - * @param String Absolute path to a folder structure containing translation files - * @return Array with file paths - */ - protected function findFiles($path) { - // Recursively find files with certain extensions. - // Can't use glob() since its non-recursive. - // Directory structure doesn't matter here. - $files = array(); - $matches = new RegexIterator( - new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path) - ), - '/^.+\.(yml$|js)/i', - RecursiveRegexIterator::GET_MATCH - ); - foreach($matches as $match) $files[] = $match[0]; - return $files; - } - - protected function processYmlFile($file) { - $this->log(sprintf("Processing $file")); - - // Rename locale to correct convention (underscored rather than dashed). - // GL wants filenames to adhere to its saved locales, but SS framework - // can't easily change to that format for backwards compat reasons, so we need to convert. - // The passed in file name doesn't really matter here, only the contained locale. - // By convention, the first line in the YAML file is always the locale used, as a YAML "root key". - $localeRegex = '/^([\w-_]*):/'; - $content = file_get_contents($file); - preg_match($localeRegex, $content, $matches); - $locale = $matches[1]; - $locale = str_replace('-', '_', $locale); - $locale = str_replace(':', '', $locale); - $content = preg_replace($localeRegex, $locale . ':', $content); - - // Convert faulty multiline double quoted string YAML - // to block format, in order to allow the YAML Parser to open it later - // TODO Remove once getlocalization.com has fixed their output format (see support.getlocalization.com #2022) - $isBlock = false; - $blockIndex = -1; - $lines = explode(PHP_EOL, $content); - $keyedLineRegex = '/^\s*[\w\d-_\.]*:\s*/'; - $leadingQuoteRegex = '/^\s*\"/'; - $trailingQuoteRegex = '/[^\\\\]\"$/'; - foreach($lines as $i => $line) { - preg_match($keyedLineRegex, $line, $matches); - $key = $matches ? $matches[0] : null; - $val = trim(preg_replace($keyedLineRegex, '', $line)); - // If its a multiline double quoted string (no unescaped closing quote) - if($val && $line != '"' && preg_match($leadingQuoteRegex, $val) && !preg_match($trailingQuoteRegex, $val)) { - $isBlock = true; - $blockIndex = $i; - } elseif($key) { - $isBlock = false; - $blockIndex = -1; - } else { - $lines[$blockIndex] .= $line; - unset($lines[$i]); - } - } - $content = implode(PHP_EOL, $lines); - - // Parse YML as a sanity check, - // and reorder alphabetically by key to ensure consistent diffs. - require_once dirname(__FILE__) . '/../framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYaml.php'; - require_once dirname(__FILE__) . '/../framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlParser.php'; - require_once dirname(__FILE__) . '/../framework/thirdparty/zend_translate_railsyaml/library/Translate/Adapter/thirdparty/sfYaml/lib/sfYamlDumper.php'; - $yamlHandler = new sfYaml(); - $yml = $yamlHandler->load($content); - if(isset($yml[$locale]) && is_array($yml[$locale])) { - ksort($yml[$locale]); - foreach($yml[$locale] as $k => &$v) { - if(is_array($v)) ksort($v); - } - } - $content = $yamlHandler->dump($yml, 99); // don't inline first levels - - // Save into correct path, overwriting existing files - $path = $this->modulePath . '/' . $this->langFolders['yml'] . '/' . $locale . '.yml'; - $this->log("Saving to $path"); - file_put_contents($path, $content); - } - - protected function processJavascriptFile($file) { - $this->log(sprintf("Processing $file")); - - $locale = pathinfo($file, PATHINFO_FILENAME); - $locale = str_replace('-', '_', $locale); - - // Save into correct path, overwriting existing files - $path = $this->modulePath . '/' . $this->langFolders['js'] . '/' . $locale . '.yml'; - $this->log("Saving to $path"); - file_put_contents($path, file_get_contents($file)); - } -} - - -?> \ No newline at end of file diff --git a/tools/lib/sources.php b/tools/lib/sources.php deleted file mode 100644 index 0f234c5..0000000 --- a/tools/lib/sources.php +++ /dev/null @@ -1,151 +0,0 @@ -data = $data; - } - - function repoURL() { - return $this->data['repo']; - } - - function export($out) { - throw new Exception('Dont know how to do this yet'); - } - - function canExport() { - return array('Cant currently use flat mode with git source repositories'); - } - - function piston($out) { - $data = $this->data; - Piston::import($this->repoURL(), $data['branch'], $out); - } - - function canPiston() { - $errors = array(); - if (!GIT::available()) $errors = "Git is not available."; - if (!Piston::available()) $errors[] = "Piston is not available."; - if (!SVN::isSVNRepo() && !GIT::isGITRepo()) $errors[] = "Piston only works on svn working copies and git repositories."; - return $errors; - } - - function checkout($out) { - $data = $this->data; - GIT::checkout($this->repoURL(), $data['branch'], $out); - } - - function canCheckout() { - $errors = array(); - if (!GIT::available()) $errors = "Git is not available."; - return $errors; - } -} - -class Github extends GitRepo { - protected $data; - - function __construct($data) { - $this->data = $data; - } - - function repoURL() { - $data = $this->data; - return "git://github.com/{$data['user']}/{$data['project']}.git"; - } - - function export($out) { - $data = $this->data; - - $tmp = tempnam(sys_get_temp_dir(), 'phpinstaller-') . '.zip'; - - HTTP::get("https://github.com/{$data['user']}/{$data['project']}/zipball/{$data['branch']}", $tmp); - Zip::import($tmp, $out, 1); - } - - function canExport() { - $errors = array(); - if (!HTTP::available()) $errors[] = "The curl module is not available"; - if (!Zip::available()) $errors[] = "The zip module is not available"; - return $errors; - } -} - -class GithubSparse extends Github { - function piston($out) { - $this->export($out); - if (Git::isGITRepo()) Git::add($out); - } - - function canPiston() { - $data = $this->data; - echo "WARNING: Sparse import of directory {$data['subdir']} from {$this->repoURL()} will be flat, not pistoned\n"; - return $this->canExport(); - } - - function checkout($out) { - $this->export($out); - } - - function canCheckout() { - $data = $this->data; - echo "WARNING: Sparse import of directory {$data['subdir']} from {$this->repoURL()} will be flat, not checked out\n"; - return $this->canExport(); - } - - function export($out) { - $data = $this->data; - - $tmp = tempnam(sys_get_temp_dir(), 'phpinstaller-') . '.zip'; - - HTTP::get("https://github.com/{$data['user']}/{$data['project']}/zipball/{$data['branch']}", $tmp); - Zip::import($tmp, $out, 1, $data['subdir']); - } -} - -class SvnRepo { - function __construct($data) { - $this->data = $data; - } - - function repoURL() { - $data = $this->data; - return "{$data['repo']}/{$data['branch']}" . (isset($data['subdir']) ? "/{$data['subdir']}" : ''); - } - - function export($out) { - SVN::export($this->repoURL(), $out); - } - - function canExport() { - $errors = array(); - if (!SVN::available()) $errors[] = "Subversion is not available."; - return $errors; - } - - function piston($out) { - Piston::import($this->repoURL(), null, $out); - } - - function canPiston() { - $errors = array(); - if (!SVN::available()) $errors[] = "Subversion is not available."; - if (!Piston::available()) $errors[] = "Piston is not available."; - if (!SVN::isSVNRepo() && !GIT::isGITRepo()) $errors[] = "Piston only works on svn working copies and git repositories."; - return $errors; - } - - function checkout($out) { - SVN::checkout($this->repoURL(), $out); - } - - function canCheckout() { - $errors = array(); - if (!SVN::available()) $errors[] = "Subversion is not available."; - return $errors; - } -} \ No newline at end of file diff --git a/tools/lib/tools.php b/tools/lib/tools.php deleted file mode 100644 index eeab7bd..0000000 --- a/tools/lib/tools.php +++ /dev/null @@ -1,150 +0,0 @@ -open($src); - if ($res === TRUE) { - - if ($skipdirs) { - $tmpdir = tempnam(sys_get_temp_dir(), 'phpinstaller-') . '.ext'; - mkdir($tmpdir, 0700); - - mkdir($dest); - - $zip->extractTo($tmpdir); - - for($i = 0; $i < $zip->numFiles; $i++){ - $name = $srcname = $zip->getNameIndex($i); - $parts = array(); - - while ($name && $name != '.' && $name != '/') { - array_unshift($parts, basename($name)); - $name = dirname($name); - } - - if ($subdir) { - // We only need to move the level after the level after the skipdirs level, presuming that level after the skipdirs level == $subdir - if (count($parts) != $skipdirs+2) continue; - if ($parts[$skipdirs] != $subdir) continue; - - $dstname = $parts[$skipdirs+1]; - } - else { - // We only need to move the very next level after the skipdirs level - if (count($parts) != $skipdirs+1) continue; - - $dstname = $parts[$skipdirs]; - } - - rename($tmpdir.'/'.$srcname, $dest.'/'.$dstname); - } - } - else { - $zip->extractTo($dest); - } - - $zip->close(); - } else { - throw new Exception('Could not extract zip at '.$src.' to '.$dest); - } - } -} -