gradle.plugin.zsh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!zsh
  2. ##############################################################################
  3. # A descriptive listing of core Gradle commands
  4. ############################################################################
  5. function _gradle_core_commands() {
  6. local ret=1 state
  7. _arguments ':subcommand:->subcommand' && ret=0
  8. case $state in
  9. subcommand)
  10. subcommands=(
  11. "properties:Display all project properties"
  12. "tasks:Calculate and display all tasks"
  13. "dependencies:Calculate and display all dependencies"
  14. "projects:Discover and display all sub-projects"
  15. "build:Build the project"
  16. "help:Display help"
  17. )
  18. _describe -t subcommands 'gradle subcommands' subcommands && ret=0
  19. esac
  20. return ret
  21. }
  22. function _gradle_arguments() {
  23. _arguments -C \
  24. '-a[Do not rebuild project dependencies]' \
  25. '-h[Help]' \
  26. '-D[System property]' \
  27. '-d[Log at the debug level]' \
  28. '--gui[Launches the Gradle GUI app]' \
  29. '--stop[Stop the Gradle daemon]' \
  30. '--daemon[Use the Gradle daemon]' \
  31. '--no-daemon[Do not use the Gradle daemon]' \
  32. '--rerun-task [Specifies that any task optimization is ignored.]' \
  33. '-i[Log at the info level]' \
  34. '-m[Dry run]' \
  35. '-P[Set a project property]' \
  36. '-p[Specifies the start directory]' \
  37. '--profile[Profile the build time]' \
  38. '-q[Log at the quiet level (only show errors)]' \
  39. '-v[Print the Gradle version info]' \
  40. '-x[Specify a task to be excluded]' \
  41. '-b[Specifies the build file.]' \
  42. '-c[Specifies the settings file.]' \
  43. '--continue[Continues task execution after a task failure.]' \
  44. '-g[Specifies the Gradle user home directory.]' \
  45. '-I[Specifies an initialization script.]' \
  46. '--refresh-dependencies[Refresh the state of dependencies.]' \
  47. '-u[Don''t search in parent directories for a settings.gradle file.]' \
  48. '*::command:->command' \
  49. && return 0
  50. }
  51. ##############################################################################
  52. # Are we in a directory containing a build.gradle file?
  53. ############################################################################
  54. function in_gradle() {
  55. if [[ -f build.gradle ]]; then
  56. echo 1
  57. fi
  58. }
  59. ############################################################################## Examine the build.gradle file to see if its
  60. # timestamp has changed, and if so, regen
  61. # the .gradle_tasks cache file
  62. ############################################################################
  63. _gradle_does_task_list_need_generating () {
  64. [ ! -f .gradletasknamecache ] && return 0;
  65. [ build.gradle -nt .gradletasknamecache ] && return 0;
  66. return 1;
  67. }
  68. ##############################################################################
  69. # Discover the gradle tasks by running "gradle tasks --all"
  70. ############################################################################
  71. _gradle_tasks () {
  72. if [ in_gradle ]; then
  73. _gradle_arguments
  74. if _gradle_does_task_list_need_generating; then
  75. gradle tasks --all | grep "^[ ]*[a-zA-Z0-9:]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
  76. fi
  77. compadd -X "==== Gradle Tasks ====" `cat .gradletasknamecache`
  78. fi
  79. }
  80. _gradlew_tasks () {
  81. if [ in_gradle ]; then
  82. _gradle_arguments
  83. if _gradle_does_task_list_need_generating; then
  84. ./gradlew tasks --all | grep "^[ ]*[a-zA-Z0-9:]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
  85. fi
  86. compadd -X "==== Gradlew Tasks ====" `cat .gradletasknamecache`
  87. fi
  88. }
  89. ##############################################################################
  90. # Register the completions against the gradle and gradlew commands
  91. ############################################################################
  92. compdef _gradle_tasks gradle
  93. compdef _gradlew_tasks gradlew
  94. ##############################################################################
  95. # Open questions for future improvements:
  96. # 1) Should 'gradle tasks' use --all or just the regular set?
  97. # 2) Should gradlew use the same approach as gradle?
  98. # 3) Should only the " - " be replaced with a colon so it can work
  99. # with the richer descriptive method of _arguments?
  100. # gradle tasks | grep "^[a-zA-Z0-9]*\ -\ " | sed "s/ - /\:/"
  101. #############################################################################