e1a8d7c9772db760a77b83cf945fcd8b1fc08129

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

Message

gradle: use upstream completion and fix some other stuff

Fixes #6239
Fixes #7946
Fixes #8017
Fixes #8717
Closes #7987
Closes #8718

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/gradle/README.md b/plugins/gradle/README.md
  2index 215503c81458d0979c00125a9e808bc7af26309f..a94ac3d0de76df014f74bc5368cd574fbf6338f5 100644
  3--- a/plugins/gradle/README.md
  4+++ b/plugins/gradle/README.md
  5@@ -1,4 +1,4 @@
  6-## Gradle Plugin
  7+# Gradle plugin
  8 
  9 This plugin adds completions and aliases for [Gradle](https://gradle.org/).
 10 
 11@@ -10,7 +10,12 @@ plugins=(... gradle)
 12 
 13 ## Usage
 14 
 15diff --git a/plugins/gradle/_gradle b/plugins/gradle/_gradle
 16deleted file mode 120000
 17index 80723f2fc07b3da179693654769fe549a3deca41..0000000000000000000000000000000000000000
 18--- a/plugins/gradle/_gradle
 19+++ /dev/null
 20@@ -1 +0,0 @@
 21-gradle.plugin.zsh
 22diff --git a/plugins/gradle/_gradle b/plugins/gradle/_gradle
 23new file mode 100644
 24index 0000000000000000000000000000000000000000..64762661577a5085782eee9ac813238e504916ec
 25--- /dev/null
 26+++ b/plugins/gradle/_gradle
 27@@ -0,0 +1,420 @@
 28+#compdef gradle gradlew gw
 29+#
 30+# Taken from https://github.com/gradle/gradle-completion
 31+# Copyright (c) 2017 Eric Wendelin
 32+#
 33+# Permission is hereby granted, free of charge, to any person obtaining a copy of
 34+# this software and associated documentation files (the "Software"), to deal in
 35+# the Software without restriction, including without limitation the rights to
 36+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 37+# of the Software, and to permit persons to whom the Software is furnished to do
 38+# so, subject to the following conditions:
 39+#
 40+# The above copyright notice and this permission notice shall be included in all
 41+# copies or substantial portions of the Software.
 42+#
 43+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 44+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 45+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 46+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 47+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 48+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 49+# SOFTWARE.
 50+# Terms
 51+
 52+__gradle-set-project-root-dir() {
 53+    local dir=`pwd`
 54+    project_root_dir=`pwd`
 55+    while [[ $dir != '/' ]]; do
 56+        if [[ -f "$dir/settings.gradle" || -f "$dir/settings.gradle.kts" || -f "$dir/gradlew" ]]; then
 57+            project_root_dir=$dir
 58+            return 0
 59+        fi
 60+        dir="$(dirname "$dir")"
 61+    done
 62+    return 1
 63+}
 64+
 65+__gradle-init-cache-dir() {
 66+    cache_dir="$HOME/.gradle/completion"
 67+    mkdir -p $cache_dir
 68+}
 69+
 70+__gradle-set-settings-file() {
 71+    # In order of precedence: --settings-file=filename, settings.gradle, settings.gradle.kts
 72+
 73+    local default_gradle_settings_file="$project_root_dir/settings.gradle"
 74+    if [[ ! -f $default_gradle_settings_file ]]; then
 75+      default_gradle_settings_file="$project_root_dir/settings.gradle.kts"
 76+    fi
 77+    gradle_settings_file=${${(v)opt_args[(i)-c|--settings-file]}:-$default_gradle_settings_file}
 78+}
 79+
 80+__gradle-set-build-file() {
 81+    __gradle-set-settings-file
 82+    # In order of precedence: --build-file=filename, rootProject.buildFileName, build.gradle, build.gradle.kts
 83+
 84+    local default_gradle_build_file_name="build.gradle"
 85+    if [[ -r $gradle_settings_file ]]; then
 86+        default_gradle_build_file_name=${$(grep "^rootProject\.buildFileName" $gradle_settings_file | \
 87+            sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p")}
 88+
 89+        default_gradle_build_file_name="${default_gradle_build_file:-build.gradle}"
 90+    fi
 91+
 92+    local default_gradle_build_file="$project_root_dir/$default_gradle_build_file_name"
 93+    if [[ ! -f $default_gradle_build_file ]]; then
 94+        default_gradle_build_file="$project_root_dir/build.gradle.kts"
 95+    fi
 96+
 97+    # If a build file is specified after '-b' or '--build-file', use this file.
 98+    gradle_build_file=${${(v)opt_args[(i)-b|--build-file]}:-$default_gradle_build_file}
 99+}
100+
101+__gradle-set-cache-name() {
102+    # Cache name is constructed from the absolute path of the build file.
103+    cache_name=${${gradle_build_file:a}//[^[:alnum:]]/_}
104+}
105+
106+__gradle-set-files-checksum() {
107+    # Cache MD5 sum of all Gradle scripts and modified timestamps
108+    if builtin command -v md5 > /dev/null; then
109+        gradle_files_checksum=( $(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)") )
110+    elif builtin command -v md5sum > /dev/null; then
111+        gradle_files_checksum=( $(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}') )
112+    else
113+        _message 'Cannot generate completions as neither md5 nor md5sum exist on \$PATH'
114+        return 1
115+    fi
116+}
117+
118+__gradle-generate-script-cache() {
119+    # Invalidate cache after 3 weeks by default
120+    local cache_ttl_mins=${$(echo $GRADLE_CACHE_TTL_MINUTES):-30240}
121+    local script_exclude_pattern=${$(echo $GRADLE_COMPLETION_EXCLUDE_PATTERN):-"/(.git|build|integTest|samples|templates|smokeTest|testFixtures|out)/"}
122+    if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then
123+        zle -R "Generating Gradle build script cache"
124+        # Cache all Gradle scripts
125+        local -a gradle_build_scripts
126+        gradle_build_scripts=( $(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | egrep -v "$script_exclude_pattern") )
127diff --git a/plugins/gradle/_gradlew b/plugins/gradle/_gradlew
128deleted file mode 120000
129index 80723f2fc07b3da179693654769fe549a3deca41..0000000000000000000000000000000000000000
130--- a/plugins/gradle/_gradlew
131+++ /dev/null
132@@ -1 +0,0 @@
133-gradle.plugin.zsh
134diff --git a/plugins/gradle/gradle.plugin.zsh b/plugins/gradle/gradle.plugin.zsh
135index bba6ad4e9b4e55619a97ca85017de046faed3aba..5bca364d19c1907ac5f7ff3891aed6ad2a3fb438 100644
136--- a/plugins/gradle/gradle.plugin.zsh
137+++ b/plugins/gradle/gradle.plugin.zsh
138@@ -1,184 +1,26 @@
139-##############################################################################
140-# A descriptive listing of core Gradle commands
141-############################################################################
142-
143-gradle-or-gradlew() {
144-	if [ -f ./gradlew ] ; then
145-		echo "executing gradlew instead of gradle";
146-		./gradlew "$@";
147-	else
148-		command gradle "$@";
149-	fi
150-}
151-
152-alias gradle=gradle-or-gradlew;
153-
154-function _gradle_core_commands() {
155-    local ret=1 state
156-    _arguments ':subcommand:->subcommand' && ret=0
157-
158-    case $state in
159-      subcommand)
160-        subcommands=(
161-          "properties:Display all project properties"
162-          "tasks:Calculate and display all tasks"
163-          "dependencies:Calculate and display all dependencies"
164-          "projects:Discover and display all sub-projects"
165-          "build:Build the project"
166-          "help:Display help"
167-        )
168-        _describe -t subcommands 'gradle subcommands' subcommands && ret=0
169-    esac
170-
171-    return ret
172-}
173-
174-function _gradle_arguments() {
175-    _arguments -C \
176-    '-a[Do not rebuild project dependencies]' \
177-    '-b[Specifies the build file]' \
178-    '-c[Specifies the settings file]' \
179-    '-d[Log at the debug level]' \
180-    '-g[Specifies the Gradle user home directory]' \
181-    '-h[Shows a help message]' \
182-    '-i[Set log level to INFO]' \
183-    '-m[Runs the build with all task actions disabled]' \
184-    '-p[Specifies the start directory for Gradle]' \
185-    '-q[Log errors only]' \
186-    '-s[Print out the stacktrace also for user exceptions]' \
187-    '-t[Continuous mode. Automatically re-run build after changes]' \
188-    '-u[Don''t search in parent directories for a settings.gradle file]' \
189-    '-v[Prints Gradle version info]' \
190-    '-x[Specify a task to be excluded]' \
191-    '-D[Set a system property]' \
192-    '-I[Specifies an initialization script]' \
193-    '-P[Sets a project property of the root project]' \
194-    '-S[Print out the full (very verbose) stacktrace]' \
195-    '--build-file[Specifies the build file]' \
196-    '--configure-on-demand[Only relevant projects are configured]' \
197-    '--console[Type of console output to generate (plain, auto, or rich)]' \
198-    '--continue[Continues task execution after a task failure]' \
199-    '--continuous[Continuous mode. Automatically re-run build after changes]' \
200-    '--daemon[Use the Gradle Daemon]' \
201-    '--debug[Log at the debug level]' \
202-    '--dry-run[Runs the build with all task actions disabled]' \
203-    '--exclude-task[Specify a task to be excluded]' \
204-    '--full-stacktrace[Print out the full (very verbose) stacktrace]' \
205-    '--gradle-user-home[Specifies the Gradle user home directory]' \
206-    '--gui[Launches the Gradle GUI app (Deprecated)]' \
207-    '--help[Shows a help message]' \
208-    '--include-build[Run the build as a composite, including the specified build]' \
209-    '--info[Set log level to INFO]' \
210-    '--init-script[Specifies an initialization script]' \
211-    '--max-workers[Set the maximum number of workers that Gradle may use]' \
212-    '--no-daemon[Do not use the Gradle Daemon]' \
213-    '--no-rebuild[Do not rebuild project dependencies]' \
214-    '--no-search-upwards[Don''t search in parent directories for a settings.gradle file]' \
215-    '--offline[Build without accessing network resources]' \
216-    '--parallel[Build projects in parallel]' \
217-    '--profile[Profile build time and create report]' \
218-    '--project-cache-dir[Specifies the project-specific cache directory]' \
219-    '--project-dir[Specifies the start directory for Gradle]' \
220-    '--project-prop[Sets a project property of the root project]' \
221-    '--quiet[Log errors only]' \
222-    '--recompile-scripts[Forces scripts to be recompiled, bypassing caching]' \
223-    '--refresh-dependencies[Refresh the state of dependencies]' \
224-    '--rerun-tasks[Specifies that any task optimization is ignored]' \
225-    '--settings-file[Specifies the settings file]' \
226-    '--stacktrace[Print out the stacktrace also for user exceptions]' \
227-    '--status[Print Gradle Daemon status]' \
228-    '--stop[Stop all Gradle Daemons]' \
229-    '--system-prop[Set a system property]' \
230-    '--version[Prints Gradle version info]' \
231-    '*::command:->command' \
232-    && return 0
233-}
234-
235-
236-##############################################################################
237-# Examine the build.gradle file to see if its timestamp has changed;