2 ##############################################################################
3 # A descriptive listing of core Gradle commands
4 ############################################################################
5 function _gradle_core_commands
() {
7 _arguments
':subcommand:->subcommand' && ret
=0
12 "properties:Display all project properties"
13 "tasks:Calculate and display all tasks"
14 "dependencies:Calculate and display all dependencies"
15 "projects:Discover and display all sub-projects"
16 "build:Build the project"
19 _describe
-t subcommands
'gradle subcommands' subcommands
&& ret
=0
25 function _gradle_arguments
() {
27 '-a[Do not rebuild project dependencies]' \
29 '-D[System property]' \
30 '-d[Log at the debug level]' \
31 '--gui[Launches the Gradle GUI app]' \
32 '--stop[Stop the Gradle daemon]' \
33 '--daemon[Use the Gradle daemon]' \
34 '--no-daemon[Do not use the Gradle daemon]' \
35 '--no-opt[Do not perform any task optimization]' \
36 '-i[Log at the info level]' \
38 '-P[Set a project property]' \
39 '--profile[Profile the build time]' \
40 '-q[Log at the quiet level (only show errors)]' \
41 '-v[Print the Gradle version info]' \
42 '-x[Specify a task to be excluded]' \
43 '*::command:->command' \
48 ##############################################################################
49 # Are we in a directory containing a build.gradle file?
50 ############################################################################
51 function in_gradle
() {
52 if [[ -f build.gradle
]]; then
57 ############################################################################
58 # Define the stat_cmd command based on platform behavior
59 ##########################################################################
60 stat
-f%m .
> /dev
/null
2>&1
64 stat_cmd
=(stat
-L --format=%Y
)
67 ############################################################################## Examine the build.gradle file to see if its
68 # timestamp has changed, and if so, regen
69 # the .gradle_tasks cache file
70 ############################################################################
71 _gradle_does_task_list_need_generating
() {
72 if [ ! -f .gradletasknamecache
]; then return 0;
74 accurate
=$($stat_cmd .gradletasknamecache)
75 changed
=$($stat_cmd build.gradle)
76 return $(expr $accurate '>=' $changed)
81 ##############################################################################
82 # Discover the gradle tasks by running "gradle tasks --all"
83 ############################################################################
85 if [ in_gradle
]; then
87 if _gradle_does_task_list_need_generating
; then
88 gradle tasks
--all | grep "^[ ]*[a-zA-Z0-9]*\ -\ " | sed "s
/ - .
*$
//" | sed "s
/[\
]*//" > .gradletasknamecache
90 compadd -X "==== Gradle Tasks
====" `cat .gradletasknamecache`
95 if [ in_gradle ]; then
97 if _gradle_does_task_list_need_generating; then
98 gradlew tasks --all | grep "^
[ ]*[a-zA-Z0-9]*\
-\
" | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
100 compadd
-X "==== Gradlew Tasks ====" `cat .gradletasknamecache`
105 ##############################################################################
106 # Register the completions against the gradle and gradlew commands
107 ############################################################################
108 compdef _gradle_tasks gradle
109 compdef _gradlew_tasks gradlew
112 ##############################################################################
113 # Open questions for future improvements:
114 # 1) Should 'gradle tasks' use --all or just the regular set?
115 # 2) Should gradlew use the same approach as gradle?
116 # 3) Should only the " - " be replaced with a colon so it can work
117 # with the richer descriptive method of _arguments?
118 # gradle tasks | grep "^[a-zA-Z0-9]*\ -\ " | sed "s/ - /\:/"
119 #############################################################################