22632aac7c99e02ec38223c84b2348435a82d1b5

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge pull request #3859 from gnagy/master

gradle plugin: also list tasks in subprojects
Cleanup gradle plugin file

Diff

 1diff --git a/plugins/gradle/gradle.plugin.zsh b/plugins/gradle/gradle.plugin.zsh
 2index 661c29d5b5a9cf373df6f1a6cf8d31ba86448bd5..a908eaeaa9ba3db60dafad77257e012b403739a8 100644
 3--- a/plugins/gradle/gradle.plugin.zsh
 4+++ b/plugins/gradle/gradle.plugin.zsh
 5@@ -1,4 +1,3 @@
 6-#!zsh
 7 ##############################################################################
 8 # A descriptive listing of core Gradle commands
 9 ############################################################################
10@@ -54,22 +53,11 @@ function _gradle_arguments() {
11 
12 
13 ##############################################################################
14-# Are we in a directory containing a build.gradle file?
15-############################################################################
16-function in_gradle() {
17-    if [[ -f build.gradle ]]; then
18-        echo 1
19-    fi
20-}
21-
22-############################################################################## Examine the build.gradle file to see if its
23-# timestamp has changed, and if so, regen
24-# the .gradle_tasks cache file
25+# Examine the build.gradle file to see if its timestamp has changed;
26+# and if so, regenerate the .gradle_tasks cache file
27 ############################################################################
28 _gradle_does_task_list_need_generating () {
29-  [ ! -f .gradletasknamecache ] && return 0;
30-  [ build.gradle -nt .gradletasknamecache ] && return 0;
31-  return 1;
32+  [[ ! -f .gradletasknamecache ]] || [[ build.gradle -nt .gradletasknamecache ]]
33 }
34 
35 
36@@ -77,22 +65,22 @@ _gradle_does_task_list_need_generating () {
37 # Discover the gradle tasks by running "gradle tasks --all"
38 ############################################################################
39 _gradle_tasks () {
40-  if [ in_gradle ]; then
41+  if [[ -f build.gradle ]]; then
42     _gradle_arguments
43     if _gradle_does_task_list_need_generating; then
44-     gradle tasks --all | grep "^[ ]*[a-zA-Z0-9:]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
45+      gradle tasks --all | awk '/[a-zA-Z0-9:-]* - / {print $1}' > .gradletasknamecache
46     fi
47-    compadd -X "==== Gradle Tasks ====" `cat .gradletasknamecache`
48+    compadd -X "==== Gradle Tasks ====" $(cat .gradletasknamecache)
49   fi
50 }
51 
52 _gradlew_tasks () {
53-  if [ in_gradle ]; then
54+  if [[ -f build.gradle ]]; then
55     _gradle_arguments
56     if _gradle_does_task_list_need_generating; then
57-     ./gradlew tasks --all | grep "^[ ]*[a-zA-Z0-9:]*\ -\ " | sed "s/ - .*$//" | sed "s/[\ ]*//" > .gradletasknamecache
58+      ./gradlew tasks --all | awk '/[a-zA-Z0-9:-]* - / {print $1}' > .gradletasknamecache
59     fi
60-    compadd -X "==== Gradlew Tasks ====" `cat .gradletasknamecache`
61+    compadd -X "==== Gradlew Tasks ====" $(cat .gradletasknamecache)
62   fi
63 }
64 
65@@ -102,13 +90,3 @@ _gradlew_tasks () {
66 ############################################################################
67 compdef _gradle_tasks gradle
68 compdef _gradlew_tasks gradlew
69-
70-
71-##############################################################################
72-# Open questions for future improvements:
73-# 1) Should 'gradle tasks' use --all or just the regular set?
74-# 2) Should gradlew use the same approach as gradle?
75-# 3) Should only the " - " be replaced with a colon so it can work
76-#     with the richer descriptive method of _arguments?
77-#     gradle tasks | grep "^[a-zA-Z0-9]*\ -\ " | sed "s/ - /\:/"
78-#############################################################################