gradle.plugin.zsh 3.4 KB

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