Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def metaHandler (String prompt) {
- println ('\n' + (char)27 + '[1m*** ' + prompt + '\n')
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
- return br.readLine()
- }
- // Dynamic task definition for cloning an existing module (with the module name embedded in the task name as <ID>)
- // Sample command: gradlew fetchModulePortals
- tasks.addRule("Pattern: fetchModule") { String taskName ->
- if (taskName.startsWith("fetchModule")) {
- // Here's the actual task definition for each dynamically created task of name taskName
- task (taskName, type: GitClone) {
- // TODO: This task description does not get listed under the "Rules" section on "gradlew tasks" :-(
- description = 'Fetches source for a given module to the local project, cloned from GitHub'
- // Interactive Variable
- def moduleList = []
- def moduleName = "moduleName"
- while ( moduleName != '' ) {
- moduleName = metaHandler('Insert module name (Leave blank if done):')
- if (moduleName != ''){
- moduleList.push(moduleName)
- }
- }
- // Repo name is the dynamic part of the task name
- def parentDir = 'modules'
- // Default GitHub account to use. Supply with -PgithubAccount="TargetAccountName" or via gradle.properties
- def githubHome = 'Terasology'
- // Command line parameter has precedence - if it is set we do not check gradle.properties
- if (project.hasProperty('githubAccount')) {
- githubHome = githubAccount
- } else if (project.hasProperty('alternativeGithubHome')) {
- githubHome =alternativeGithubHome
- }
- for (String item : moduleList) {
- def destination = file("$parentDir/$item")
- // Don't clone this repo if we already have a directory by that name (also determines Gradle UP-TO-DATE)
- enabled = !destination.exists()
- println "fetchModule requested for $item from Github under $githubHome - exists already? " + !enabled
- // Do the actual clone if we don't have the directory already
- if (enabled) {
- uri = "https://github.com/$githubHome/" + item + ".git"
- println "Fetching $item from $uri"
- destinationPath = destination
- bare = false
- }
- }
- // Copy in (replace if existing for some reason) a build.gradle from template, plus module.txt if missing
- doLast {
- for (String item : moduleList) {
- def destination = file("$parentDir/$item")
- destinationPath = destination
- bare = false
- File targetBuildGradle = new File(destination, 'build.gradle')
- targetBuildGradle.delete()
- targetBuildGradle << new File(rootDir, 'modules/Core/build.gradle').text
- File moduleManifest = new File (destination, 'module.txt')
- if (!moduleManifest.exists()) {
- def moduleText = new File(templatesDir, 'module.txt').text
- moduleManifest << moduleText.replaceAll('MODULENAME', repo)
- println "WARNING: Module $item did not have a module.txt! One was created, please review and submit to GitHub"
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement