Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. def metaHandler (String prompt) {
  2. println ('\n' + (char)27 + '[1m*** ' + prompt + '\n')
  3. BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
  4. return br.readLine()
  5. }
  6.  
  7. // Dynamic task definition for cloning an existing module (with the module name embedded in the task name as <ID>)
  8. // Sample command: gradlew fetchModulePortals
  9. tasks.addRule("Pattern: fetchModule") { String taskName ->
  10. if (taskName.startsWith("fetchModule")) {
  11.  
  12. // Here's the actual task definition for each dynamically created task of name taskName
  13. task (taskName, type: GitClone) {
  14. // TODO: This task description does not get listed under the "Rules" section on "gradlew tasks" :-(
  15. description = 'Fetches source for a given module to the local project, cloned from GitHub'
  16.  
  17. // Interactive Variable
  18. def moduleList = []
  19. def moduleName = "moduleName"
  20. while ( moduleName != '' ) {
  21. moduleName = metaHandler('Insert module name (Leave blank if done):')
  22. if (moduleName != ''){
  23. moduleList.push(moduleName)
  24. }
  25. }
  26.  
  27. // Repo name is the dynamic part of the task name
  28. def parentDir = 'modules'
  29.  
  30. // Default GitHub account to use. Supply with -PgithubAccount="TargetAccountName" or via gradle.properties
  31. def githubHome = 'Terasology'
  32.  
  33. // Command line parameter has precedence - if it is set we do not check gradle.properties
  34. if (project.hasProperty('githubAccount')) {
  35. githubHome = githubAccount
  36. } else if (project.hasProperty('alternativeGithubHome')) {
  37. githubHome =alternativeGithubHome
  38. }
  39.  
  40. for (String item : moduleList) {
  41. def destination = file("$parentDir/$item")
  42.  
  43. // Don't clone this repo if we already have a directory by that name (also determines Gradle UP-TO-DATE)
  44. enabled = !destination.exists()
  45. println "fetchModule requested for $item from Github under $githubHome - exists already? " + !enabled
  46.  
  47. // Do the actual clone if we don't have the directory already
  48. if (enabled) {
  49. uri = "https://github.com/$githubHome/" + item + ".git"
  50. println "Fetching $item from $uri"
  51. destinationPath = destination
  52. bare = false
  53. }
  54. }
  55. // Copy in (replace if existing for some reason) a build.gradle from template, plus module.txt if missing
  56. doLast {
  57. for (String item : moduleList) {
  58. def destination = file("$parentDir/$item")
  59. destinationPath = destination
  60. bare = false
  61. File targetBuildGradle = new File(destination, 'build.gradle')
  62. targetBuildGradle.delete()
  63. targetBuildGradle << new File(rootDir, 'modules/Core/build.gradle').text
  64.  
  65. File moduleManifest = new File (destination, 'module.txt')
  66. if (!moduleManifest.exists()) {
  67. def moduleText = new File(templatesDir, 'module.txt').text
  68. moduleManifest << moduleText.replaceAll('MODULENAME', repo)
  69. println "WARNING: Module $item did not have a module.txt! One was created, please review and submit to GitHub"
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement