zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Add _gradle for gradle and gradlew completion.
@ 2012-03-24 10:28 Jesper Nygårds
  2012-03-24 10:39 ` Mikael Magnusson
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Nygårds @ 2012-03-24 10:28 UTC (permalink / raw)
  To: zsh-workers

Please consider applying this patch for adding completion to gradle
and gradlew. Gradle is a build tool for java, scala and groovy.


diff -u -N --recursive a/Completion/Unix/Command/.distfiles
b/Completion/Unix/Command/.distfiles
--- a/Completion/Unix/Command/.distfiles	2012-03-24 10:43:55.425469198 +0100
+++ b/Completion/Unix/Command/.distfiles	2012-03-24 11:17:49.881397396 +0100
@@ -83,6 +83,7 @@
 _gpg
 _gphoto2
 _gprof
+_gradle
 _graphicsmagick
 _grep
 _groff
diff -u -N --recursive a/Completion/Unix/Command/_gradle
b/Completion/Unix/Command/_gradle
--- a/Completion/Unix/Command/_gradle	1970-01-01 01:00:00.000000000 +0100
+++ b/Completion/Unix/Command/_gradle	2012-03-24 11:17:18.489398504 +0100
@@ -0,0 +1,120 @@
+#compdef gradle gradlew
+
+_gradle() {
+    local curcontext="$curcontext" ret=1 state state_descr line
+    local gradle_inspect=yes cache_policy tag_order
+    local -A opt_args
+    local -a gradle_group_tasks gradle_all_tasks
+
+    zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy || \
+        zstyle ":completion:*:*:$service:*" cache-policy _gradle_caching_policy
+
+    # By default, we only complete main tasks (belonging to a group).
Secondary tasks are
+    # completed if no main tasks are found.
+    zstyle -a ":completion:*:*:$service:*" tag-order tag_order || \
+        zstyle ":completion:*:*:$service:*" tag-order 'gradle_group'
'gradle_all'
+
+    # The completion inspects the current build file to find tasks to
complete. Setting
+    # this style to 'no' or 'false' turns off inspection. In that
case only the built-in tasks
+    # are completed.
+    zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
+
+    _arguments -C \
+        '(-)'{-?,-h,--help}'[Shows this help message.]' \
+        {-a,--no-rebuild}'[Do not rebuild project dependencies.]' \
+        {-b,--build-file}'[Specifies the build file.]:build
file:_files -g "*.gradle(-.)"' \
+        {-C,--cache}'[Specifies how compiled build scripts should be
cached.]:cache policy:(on rebuild)' \
+        {-c,--settings-file}'[Specifies the settings file.]:settings
file:_files -g "*.properties(-.)"' \
+        '--continue[Continues task execution after a task failure.]' \
+        '*--system-prop[Set system property of the JVM (e.g.
-Dmyprop=myvalue).]:system property (prop=val):' \
+        '*-D+[Set system property of the JVM (e.g.
-Dmyprop=myvalue).]:system property (prop=val):' \
+        '(-i --info -q --quiet)'{-d,--debug}'[Log in debug mode
(includes normal stacktrace).]' \
+        '(--nodaemon)--daemon[Uses the Gradle daemon to run the
build. Starts the daemon if not running.]' \
+        '--foreground[Starts the Gradle daemon in the foreground.]' \
+        {-g,--gradle-user-home}'[Specifies the gradle user home
directory.]:home directory:_directories' \
+        '(-)--gui[Launches the Gradle GUI.]' \
+        {-I,--init-script}'[Specifies an initialization script.]:init
script:_files -g "*.gradle(-.)"' \
+        '(-d --debug -q --quiet)'{-i,--info}'[Set log level to info.]' \
+        {-m,--dry-run}'[Runs the builds with all task actions disabled.]' \
+        '--no-color[Do not use color in the console output.]' \
+        '(--daemon)--no-daemon[Do not use the Gradle daemon to run
the build.]' \
+        '--no-opt[Ignore any task optimization.]' \
+        '--offline[The build should operate without accessing network
resources.]' \
+        '*--project-prop[Set project property for the build script
(e.g. -Pmyprop=myvalue).]:project property (prop=val):' \
+        '*-P+[Set project property for the build script (e.g.
-Pmyprop=myvalue).]:project property (prop=val):' \
+        {-p,--project-dir}'[Specifies the start directory for
Gradle.]:start directory:_directories' \
+        '--profile[Profiles build execution time and generates a
report in the <build_dir>/reports/profile directory.]' \
+        '--project-cache-dir[Specifies the project-specific cache
directory.]:cache directory:_directories' \
+        '(-d --debug -i --info)'{-q,--quiet}'[Log errors only.]' \
+        "--refresh[Refresh the state of resources of the type(s)
specified.]:refresh policy:(dependencies)" \
+        '(-s --stacktrace)'{-S,--full-stacktrace}'[Print out the full
(very verbose) stacktrace for all exceptions.]' \
+        '(-S --full-stacktrace)'{-s,--stacktrace}'[Print out the
stacktrace for all exceptions.]' \
+        '(-)--stop[Stops the Gradle daemon if it is running.]' \
+        {-u,--no-search-upward}"[Don't search in parent folders for a
settings.gradle file.]" \
+        '(-)'{-v,--version}'[Print version info.]' \
+        {-x,--exclude-task}'[Specify a task to be excluded from
execution.]:task to exclude:->alltask' \
+        '*:task:->task' \
+        && ret=0
+
+    if [[ -n $state ]]; then
+        if [[ $gradle_inspect = yes ]]; then
+            # If a build file is specified after '-b' or
'--build-file', use this file. Otherwise,
+            # default is the file 'build.gradle' in the current directory.
+            local buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
+
+            if [[ -f $buildfile ]]; then
+                # Set the caching policy to invalidate cache if the
build file is newer than the cache.
+                _gradle_caching_policy() {
+                    [[ $buildfile -nt $1 ]]
+                }
+
+                # Cache name is constructed from the absolute path of
the build file.
+                local cache_name=${${buildfile:a}//[^[:alnum:]]/_}
+                if _cache_invalid $cache_name || ! _retrieve_cache
$cache_name; then
+                    zle -R "Generating cache from $buildfile"
+                    local outputline
+                    local -a match mbegin mend
+                    # Run gradle/gradlew and retrieve possible tasks.
+                    for outputline in ${(f)"$($service --build-file
$buildfile -q tasks --all)"}; do
+                        if [[ $outputline =
[[:blank:]]#(#b)([[:alnum:]]##)' - '(*) ]]; then
+                            # The descriptions of main tasks start at
beginning of line, descriptions of
+                            # secondary tasks are indented.
+                            if [[ $outputline = [[:alnum:]]* ]]; then
+                                gradle_group_tasks+=( "$match[1]:$match[2]" )
+                            else
+                                gradle_all_tasks+=( "$match[1]:$match[2]" )
+                            fi
+                        fi
+                    done
+                    _store_cache $cache_name gradle_group_tasks
gradle_all_tasks
+                fi
+
+                if [[ $state == task ]]; then
+                    _tags gradle_group gradle_all
+                    while _tags; do
+                        # Offer main tasks and secondary tasks in
different tags.
+                        _requested gradle_group && _describe 'group
tasks' gradle_group_tasks && ret=0
+                        _requested gradle_all && _describe 'all
tasks' gradle_all_tasks && ret=0
+                        (( ret )) || break
+                    done
+                elif [[ $state == alltask ]]; then
+                    # After '--exclude-task', we don't make a
distinction between main tasks and
+                    # secondary tasks.
+                    _describe 'all tasks' gradle_group_tasks --
gradle_all_tasks && ret=0
+                fi
+            fi
+        else
+            _describe 'built-in tasks' '(
+                "dependencies:Displays the dependencies of root project."
+                "help:Displays a help message."
+                "projects:Displays the sub-projects of root project."
+                "properties:Displays the properties of root project."
+                "tasks:Displays the tasks runnable from root project."
+                )' && ret=0
+        fi
+    fi
+
+    return ret
+}
+
+_gradle "$@"


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-24 10:28 [PATCH] Add _gradle for gradle and gradlew completion Jesper Nygårds
@ 2012-03-24 10:39 ` Mikael Magnusson
  2012-03-24 10:55   ` Jesper Nygårds
  0 siblings, 1 reply; 9+ messages in thread
From: Mikael Magnusson @ 2012-03-24 10:39 UTC (permalink / raw)
  To: Jesper Nygårds; +Cc: zsh-workers

On 24 March 2012 11:28, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> Please consider applying this patch for adding completion to gradle
> and gradlew. Gradle is a build tool for java, scala and groovy.

The patch seems (extensively) mangled, you can't post patches by
pasting them in the gmail web interface. You can either attach the
patch, or use git send-email.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-24 10:39 ` Mikael Magnusson
@ 2012-03-24 10:55   ` Jesper Nygårds
  2012-03-24 11:14     ` Mikael Magnusson
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Nygårds @ 2012-03-24 10:55 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

2012/3/24 Mikael Magnusson <mikachu@gmail.com>:
> The patch seems (extensively) mangled, you can't post patches by
> pasting them in the gmail web interface. You can either attach the
> patch, or use git send-email.

OK, I try again, with the patch attached.

[-- Attachment #2: zsh_gradle_patch --]
[-- Type: application/octet-stream, Size: 7792 bytes --]

diff -u -N --recursive a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
--- a/Completion/Unix/Command/.distfiles	2012-03-24 10:43:55.425469198 +0100
+++ b/Completion/Unix/Command/.distfiles	2012-03-24 11:17:49.881397396 +0100
@@ -83,6 +83,7 @@
 _gpg
 _gphoto2
 _gprof
+_gradle
 _graphicsmagick
 _grep
 _groff
diff -u -N --recursive a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
--- a/Completion/Unix/Command/_gradle	1970-01-01 01:00:00.000000000 +0100
+++ b/Completion/Unix/Command/_gradle	2012-03-24 11:17:18.489398504 +0100
@@ -0,0 +1,120 @@
+#compdef gradle gradlew
+
+_gradle() {
+    local curcontext="$curcontext" ret=1 state state_descr line
+    local gradle_inspect=yes cache_policy tag_order
+    local -A opt_args
+    local -a gradle_group_tasks gradle_all_tasks
+
+    zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy || \
+        zstyle ":completion:*:*:$service:*" cache-policy _gradle_caching_policy
+
+    # By default, we only complete main tasks (belonging to a group). Secondary tasks are
+    # completed if no main tasks are found.
+    zstyle -a ":completion:*:*:$service:*" tag-order tag_order || \
+        zstyle ":completion:*:*:$service:*" tag-order 'gradle_group' 'gradle_all'
+
+    # The completion inspects the current build file to find tasks to complete. Setting
+    # this style to 'no' or 'false' turns off inspection. In that case only the built-in tasks
+    # are completed.
+    zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
+
+    _arguments -C \
+        '(-)'{-?,-h,--help}'[Shows this help message.]' \
+        {-a,--no-rebuild}'[Do not rebuild project dependencies.]' \
+        {-b,--build-file}'[Specifies the build file.]:build file:_files -g "*.gradle(-.)"' \
+        {-C,--cache}'[Specifies how compiled build scripts should be cached.]:cache policy:(on rebuild)' \
+        {-c,--settings-file}'[Specifies the settings file.]:settings file:_files -g "*.properties(-.)"' \
+        '--continue[Continues task execution after a task failure.]' \
+        '*--system-prop[Set system property of the JVM (e.g. -Dmyprop=myvalue).]:system property (prop=val):' \
+        '*-D+[Set system property of the JVM (e.g. -Dmyprop=myvalue).]:system property (prop=val):' \
+        '(-i --info -q --quiet)'{-d,--debug}'[Log in debug mode (includes normal stacktrace).]' \
+        '(--nodaemon)--daemon[Uses the Gradle daemon to run the build. Starts the daemon if not running.]' \
+        '--foreground[Starts the Gradle daemon in the foreground.]' \
+        {-g,--gradle-user-home}'[Specifies the gradle user home directory.]:home directory:_directories' \
+        '(-)--gui[Launches the Gradle GUI.]' \
+        {-I,--init-script}'[Specifies an initialization script.]:init script:_files -g "*.gradle(-.)"' \
+        '(-d --debug -q --quiet)'{-i,--info}'[Set log level to info.]' \
+        {-m,--dry-run}'[Runs the builds with all task actions disabled.]' \
+        '--no-color[Do not use color in the console output.]' \
+        '(--daemon)--no-daemon[Do not use the Gradle daemon to run the build.]' \
+        '--no-opt[Ignore any task optimization.]' \
+        '--offline[The build should operate without accessing network resources.]' \
+        '*--project-prop[Set project property for the build script (e.g. -Pmyprop=myvalue).]:project property (prop=val):' \
+        '*-P+[Set project property for the build script (e.g. -Pmyprop=myvalue).]:project property (prop=val):' \
+        {-p,--project-dir}'[Specifies the start directory for Gradle.]:start directory:_directories' \
+        '--profile[Profiles build execution time and generates a report in the <build_dir>/reports/profile directory.]' \
+        '--project-cache-dir[Specifies the project-specific cache directory.]:cache directory:_directories' \
+        '(-d --debug -i --info)'{-q,--quiet}'[Log errors only.]' \
+        "--refresh[Refresh the state of resources of the type(s) specified.]:refresh policy:(dependencies)" \
+        '(-s --stacktrace)'{-S,--full-stacktrace}'[Print out the full (very verbose) stacktrace for all exceptions.]' \
+        '(-S --full-stacktrace)'{-s,--stacktrace}'[Print out the stacktrace for all exceptions.]' \
+        '(-)--stop[Stops the Gradle daemon if it is running.]' \
+        {-u,--no-search-upward}"[Don't search in parent folders for a settings.gradle file.]" \
+        '(-)'{-v,--version}'[Print version info.]' \
+        {-x,--exclude-task}'[Specify a task to be excluded from execution.]:task to exclude:->alltask' \
+        '*:task:->task' \
+        && ret=0
+
+    if [[ -n $state ]]; then
+        if [[ $gradle_inspect = yes ]]; then
+            # If a build file is specified after '-b' or '--build-file', use this file. Otherwise,
+            # default is the file 'build.gradle' in the current directory.
+            local buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
+
+            if [[ -f $buildfile ]]; then
+                # Set the caching policy to invalidate cache if the build file is newer than the cache.
+                _gradle_caching_policy() {
+                    [[ $buildfile -nt $1 ]]
+                }
+
+                # Cache name is constructed from the absolute path of the build file.
+                local cache_name=${${buildfile:a}//[^[:alnum:]]/_}
+                if _cache_invalid $cache_name || ! _retrieve_cache $cache_name; then
+                    zle -R "Generating cache from $buildfile"
+                    local outputline
+                    local -a match mbegin mend
+                    # Run gradle/gradlew and retrieve possible tasks.
+                    for outputline in ${(f)"$($service --build-file $buildfile -q tasks --all)"}; do
+                        if [[ $outputline = [[:blank:]]#(#b)([[:alnum:]]##)' - '(*) ]]; then
+                            # The descriptions of main tasks start at beginning of line, descriptions of
+                            # secondary tasks are indented.
+                            if [[ $outputline = [[:alnum:]]* ]]; then
+                                gradle_group_tasks+=( "$match[1]:$match[2]" )
+                            else
+                                gradle_all_tasks+=( "$match[1]:$match[2]" )
+                            fi
+                        fi
+                    done
+                    _store_cache $cache_name gradle_group_tasks gradle_all_tasks
+                fi
+
+                if [[ $state == task ]]; then
+                    _tags gradle_group gradle_all
+                    while _tags; do
+                        # Offer main tasks and secondary tasks in different tags.
+                        _requested gradle_group && _describe 'group tasks' gradle_group_tasks && ret=0
+                        _requested gradle_all && _describe 'all tasks' gradle_all_tasks && ret=0
+                        (( ret )) || break
+                    done
+                elif [[ $state == alltask ]]; then
+                    # After '--exclude-task', we don't make a distinction between main tasks and
+                    # secondary tasks.
+                    _describe 'all tasks' gradle_group_tasks -- gradle_all_tasks && ret=0
+                fi
+            fi
+        else
+            _describe 'built-in tasks' '(
+                "dependencies:Displays the dependencies of root project."
+                "help:Displays a help message."
+                "projects:Displays the sub-projects of root project."
+                "properties:Displays the properties of root project."
+                "tasks:Displays the tasks runnable from root project."
+                )' && ret=0
+        fi
+    fi
+
+    return ret
+}
+
+_gradle "$@"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-24 10:55   ` Jesper Nygårds
@ 2012-03-24 11:14     ` Mikael Magnusson
       [not found]       ` <CABZhJg9xgaM7mr4dy8GYKHopAofnVRCzZmxfOsEca1VNugv6Cw@mail.gmail.com>
  0 siblings, 1 reply; 9+ messages in thread
From: Mikael Magnusson @ 2012-03-24 11:14 UTC (permalink / raw)
  To: Jesper Nygårds; +Cc: zsh-workers

On 24 March 2012 11:55, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> 2012/3/24 Mikael Magnusson <mikachu@gmail.com>:
>> The patch seems (extensively) mangled, you can't post patches by
>> pasting them in the gmail web interface. You can either attach the
>> patch, or use git send-email.
>
> OK, I try again, with the patch attached.

You're defining a single function with the same name as the autoloaded
function, and then calling it, that serves no purpose so you can just
remove that indirection. (It's used in completers that want to define
extra helper functions). You could move the _gradle_caching_policy to
the toplevel and then this pattern would make sense. (There's no
namespaces for functions, so even though you define it inside _gradle
now, it stays around after _gradle returns.)

zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
can probably be
zstyle -b ":completion:*:*:$service:*" gradle-inspect gradle_inspect
but I didn't test. :)

You need to quote the ? in -?,-h,--help. (The completion system sets
the nullglob option, so the whole argument just disappears without
errors).

Other than that it looks pretty good to me.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
       [not found]       ` <CABZhJg9xgaM7mr4dy8GYKHopAofnVRCzZmxfOsEca1VNugv6Cw@mail.gmail.com>
@ 2012-03-24 22:04         ` Jesper Nygårds
  2012-03-24 22:16           ` Mikael Magnusson
  0 siblings, 1 reply; 9+ messages in thread
From: Jesper Nygårds @ 2012-03-24 22:04 UTC (permalink / raw)
  To: zsh-workers

2012/3/24 Mikael Magnusson <mikachu@gmail.com>:
> You're defining a single function with the same name as the autoloaded
> function, and then calling it, that serves no purpose so you can just
> remove that indirection.

Good call. I'll just remove it.

> You could move the _gradle_caching_policy to
> the toplevel and then this pattern would make sense. (There's no
> namespaces for functions, so even though you define it inside _gradle
> now, it stays around after _gradle returns.)

I did know that functions are global, but I must define the function
where I do, because I can only set it once I know what build file is
to be parsed, i.e. the $build_file is a local variable, but the
_gradle_caching_policy needs to know its value. In some other
languages, I would call this a closure.

> zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
> can probably be
> zstyle -b ":completion:*:*:$service:*" gradle-inspect gradle_inspect
> but I didn't test. :)

Unless I misunderstand something, this doesn't seem to work as I'd
like it to. It works if the style is set, but I want the
gradle_inspect variable to default to be true if the gradle-inspect
style is unset, and this doesn't seem to happen with your suggestion.

> You need to quote the ? in -?,-h,--help. (The completion system sets
> the nullglob option, so the whole argument just disappears without
> errors).

Thanks, I had overlooked that one.

> Other than that it looks pretty good to me.

Great. I'll submit a new patch tomorrow, unless I have any other
errors pointed out by you or someone else.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-24 22:04         ` Jesper Nygårds
@ 2012-03-24 22:16           ` Mikael Magnusson
       [not found]             ` <CABZhJg_Aamsf57nhBFEvc0LX-pmOkrfRtGMccJo_Uwt=hoNQ6w@mail.gmail.com>
  2012-03-25 14:25             ` Jesper Nygårds
  0 siblings, 2 replies; 9+ messages in thread
From: Mikael Magnusson @ 2012-03-24 22:16 UTC (permalink / raw)
  To: Jesper Nygårds; +Cc: zsh-workers

On 24 March 2012 23:04, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> 2012/3/24 Mikael Magnusson <mikachu@gmail.com>:
>> You're defining a single function with the same name as the autoloaded
>> function, and then calling it, that serves no purpose so you can just
>> remove that indirection.
>
> Good call. I'll just remove it.
>
>> You could move the _gradle_caching_policy to
>> the toplevel and then this pattern would make sense. (There's no
>> namespaces for functions, so even though you define it inside _gradle
>> now, it stays around after _gradle returns.)
>
> I did know that functions are global, but I must define the function
> where I do, because I can only set it once I know what build file is
> to be parsed, i.e. the $build_file is a local variable, but the
> _gradle_caching_policy needs to know its value. In some other
> languages, I would call this a closure.

There is no such thing as closures in zsh, you can define it anywhere
you want using a variable called $build_file and it will use the
definition of the variable at the call site, not the definition site.
Ie, the body of a function is completely ignored by zsh until you
invoke the function (but the syntax has to be correct of course).

>> zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
>> can probably be
>> zstyle -b ":completion:*:*:$service:*" gradle-inspect gradle_inspect
>> but I didn't test. :)
>
> Unless I misunderstand something, this doesn't seem to work as I'd
> like it to. It works if the style is set, but I want the
> gradle_inspect variable to default to be true if the gradle-inspect
> style is unset, and this doesn't seem to happen with your suggestion.

Okay, never mind that then :).

>> You need to quote the ? in -?,-h,--help. (The completion system sets
>> the nullglob option, so the whole argument just disappears without
>> errors).
>
> Thanks, I had overlooked that one.
>
>> Other than that it looks pretty good to me.
>
> Great. I'll submit a new patch tomorrow, unless I have any other
> errors pointed out by you or someone else.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
       [not found]             ` <CABZhJg_Aamsf57nhBFEvc0LX-pmOkrfRtGMccJo_Uwt=hoNQ6w@mail.gmail.com>
@ 2012-03-25 14:23               ` Jesper Nygårds
  0 siblings, 0 replies; 9+ messages in thread
From: Jesper Nygårds @ 2012-03-25 14:23 UTC (permalink / raw)
  To: zsh-workers

2012/3/24 Mikael Magnusson <mikachu@gmail.com>:
> There is no such thing as closures in zsh, you can define it anywhere
> you want using a variable called $build_file and it will use the
> definition of the variable at the call site, not the definition site.
> Ie, the body of a function is completely ignored by zsh until you
> invoke the function (but the syntax has to be correct of course).

Ah, I finally understood. I'm too influenced by other languages,
obviously. I'll change according to your comment.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-24 22:16           ` Mikael Magnusson
       [not found]             ` <CABZhJg_Aamsf57nhBFEvc0LX-pmOkrfRtGMccJo_Uwt=hoNQ6w@mail.gmail.com>
@ 2012-03-25 14:25             ` Jesper Nygårds
  2012-03-25 14:51               ` Mikael Magnusson
  1 sibling, 1 reply; 9+ messages in thread
From: Jesper Nygårds @ 2012-03-25 14:25 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 88 bytes --]

Here's a new version of my original patch, with changes after the
feedback from Magnus.

[-- Attachment #2: zsh_gradle_patch2 --]
[-- Type: application/octet-stream, Size: 7148 bytes --]

diff -u -N --recursive a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
--- a/Completion/Unix/Command/.distfiles	2012-03-24 10:43:55.425469198 +0100
+++ b/Completion/Unix/Command/.distfiles	2012-03-24 11:17:49.881397396 +0100
@@ -83,6 +83,7 @@
 _gpg
 _gphoto2
 _gprof
+_gradle
 _graphicsmagick
 _grep
 _groff
diff -u -N --recursive a/Completion/Unix/Command/_gradle b/Completion/Unix/Command/_gradle
--- a/Completion/Unix/Command/_gradle	1970-01-01 01:00:00.000000000 +0100
+++ b/Completion/Unix/Command/_gradle	2012-03-25 16:21:37.392415846 +0200
@@ -0,0 +1,114 @@
+#compdef gradle gradlew
+
+local curcontext="$curcontext" ret=1 state state_descr line
+local gradle_inspect=yes cache_policy tag_order
+local -A opt_args
+local -a gradle_group_tasks gradle_all_tasks
+
+# Set the caching policy to invalidate cache if the build file is newer than the cache.
+_gradle_caching_policy() {
+    [[ $gradle_buildfile -nt $1 ]]
+}
+
+zstyle -s ":completion:*:*:$service:*" cache-policy cache_policy || \
+    zstyle ":completion:*:*:$service:*" cache-policy _gradle_caching_policy
+
+# By default, we only complete main tasks (belonging to a group). Secondary tasks are
+# completed if no main tasks are found.
+zstyle -a ":completion:*:*:$service:*" tag-order tag_order || \
+    zstyle ":completion:*:*:$service:*" tag-order 'gradle_group' 'gradle_all'
+
+# The completion inspects the current build file to find tasks to complete. Setting
+# this style to 'no' or 'false' turns off inspection. In that case only the built-in tasks
+# are completed.
+zstyle -T ":completion:*:*:$service:*" gradle-inspect || gradle_inspect=no
+
+_arguments -C \
+    '(-)'{-\?,-h,--help}'[Shows this help message.]' \
+    {-a,--no-rebuild}'[Do not rebuild project dependencies.]' \
+    {-b,--build-file}'[Specifies the build file.]:build file:_files -g "*.gradle(-.)"' \
+    {-C,--cache}'[Specifies how compiled build scripts should be cached.]:cache policy:(on rebuild)' \
+    {-c,--settings-file}'[Specifies the settings file.]:settings file:_files -g "*.properties(-.)"' \
+    '--continue[Continues task execution after a task failure.]' \
+    \*{-D+,--system-prop}'[Set system property of the JVM (e.g. -Dmyprop=myvalue).]:system property (prop=val):' \
+    '(-i --info -q --quiet)'{-d,--debug}'[Log in debug mode (includes normal stacktrace).]' \
+    '(--nodaemon)--daemon[Uses the Gradle daemon to run the build. Starts the daemon if not running.]' \
+    '--foreground[Starts the Gradle daemon in the foreground.]' \
+    {-g,--gradle-user-home}'[Specifies the gradle user home directory.]:home directory:_directories' \
+    '(-)--gui[Launches the Gradle GUI.]' \
+    {-I,--init-script}'[Specifies an initialization script.]:init script:_files -g "*.gradle(-.)"' \
+    '(-d --debug -q --quiet)'{-i,--info}'[Set log level to info.]' \
+    {-m,--dry-run}'[Runs the builds with all task actions disabled.]' \
+    '--no-color[Do not use color in the console output.]' \
+    '(--daemon)--no-daemon[Do not use the Gradle daemon to run the build.]' \
+    '--no-opt[Ignore any task optimization.]' \
+    '--offline[The build should operate without accessing network resources.]' \
+    \*{-P+,--project-prop}'[Set project property for the build script (e.g. -Pmyprop=myvalue).]:project property (prop=val):' \
+    {-p,--project-dir}'[Specifies the start directory for Gradle.]:start directory:_directories' \
+    '--profile[Profiles build execution time and generates a report in the <build_dir>/reports/profile directory.]' \
+    '--project-cache-dir[Specifies the project-specific cache directory.]:cache directory:_directories' \
+    '(-d --debug -i --info)'{-q,--quiet}'[Log errors only.]' \
+    "--refresh[Refresh the state of resources of the type(s) specified.]:refresh policy:(dependencies)" \
+    '(-s --stacktrace)'{-S,--full-stacktrace}'[Print out the full (very verbose) stacktrace for all exceptions.]' \
+    '(-S --full-stacktrace)'{-s,--stacktrace}'[Print out the stacktrace for all exceptions.]' \
+    '(-)--stop[Stops the Gradle daemon if it is running.]' \
+    {-u,--no-search-upward}"[Don't search in parent folders for a settings.gradle file.]" \
+    '(-)'{-v,--version}'[Print version info.]' \
+    {-x,--exclude-task}'[Specify a task to be excluded from execution.]:task to exclude:->alltask' \
+    '*:task:->task' \
+    && ret=0
+
+if [[ -n $state ]]; then
+    if [[ $gradle_inspect == yes ]]; then
+        # If a build file is specified after '-b' or '--build-file', use this file. Otherwise,
+        # default is the file 'build.gradle' in the current directory.
+        local gradle_buildfile=${${(v)opt_args[(i)-b|--build-file]}:-build.gradle}
+
+        if [[ -f $gradle_buildfile ]]; then
+            # Cache name is constructed from the absolute path of the build file.
+            local cache_name=${${gradle_buildfile:a}//[^[:alnum:]]/_}
+            if _cache_invalid $cache_name || ! _retrieve_cache $cache_name; then
+                zle -R "Generating cache from $gradle_buildfile"
+                local outputline
+                local -a match mbegin mend
+                # Run gradle/gradlew and retrieve possible tasks.
+                for outputline in ${(f)"$($service --build-file $gradle_buildfile -q tasks --all)"}; do
+                    if [[ $outputline == [[:blank:]]#(#b)([[:alnum:]]##)' - '(*) ]]; then
+                        # The descriptions of main tasks start at beginning of line, descriptions of
+                        # secondary tasks are indented.
+                        if [[ $outputline == [[:alnum:]]* ]]; then
+                            gradle_group_tasks+=( "$match[1]:$match[2]" )
+                        else
+                            gradle_all_tasks+=( "$match[1]:$match[2]" )
+                        fi
+                    fi
+                done
+                _store_cache $cache_name gradle_group_tasks gradle_all_tasks
+            fi
+
+            if [[ $state == task ]]; then
+                _tags gradle_group gradle_all
+                while _tags; do
+                    # Offer main tasks and secondary tasks in different tags.
+                    _requested gradle_group && _describe 'group tasks' gradle_group_tasks && ret=0
+                    _requested gradle_all && _describe 'secondary tasks' gradle_all_tasks && ret=0
+                    (( ret )) || break
+                done
+            elif [[ $state == alltask ]]; then
+                # After '--exclude-task', we don't make a distinction between main tasks and
+                # secondary tasks.
+                _describe 'all tasks' gradle_group_tasks -- gradle_all_tasks && ret=0
+            fi
+        fi
+    else
+        _describe 'built-in tasks' '(
+            "dependencies:Displays the dependencies of root project."
+            "help:Displays a help message."
+            "projects:Displays the sub-projects of root project."
+            "properties:Displays the properties of root project."
+            "tasks:Displays the tasks runnable from root project."
+            )' && ret=0
+    fi
+fi
+
+return ret

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add _gradle for gradle and gradlew completion.
  2012-03-25 14:25             ` Jesper Nygårds
@ 2012-03-25 14:51               ` Mikael Magnusson
  0 siblings, 0 replies; 9+ messages in thread
From: Mikael Magnusson @ 2012-03-25 14:51 UTC (permalink / raw)
  To: Jesper Nygårds; +Cc: zsh-workers

On 25 March 2012 16:25, Jesper Nygårds <jesper.nygards@gmail.com> wrote:
> Here's a new version of my original patch, with changes after the
> feedback from Magnus.

Thanks, I've committed the patch.

-- 
Mikael Magnusson
^^^^^^


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-03-25 14:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-24 10:28 [PATCH] Add _gradle for gradle and gradlew completion Jesper Nygårds
2012-03-24 10:39 ` Mikael Magnusson
2012-03-24 10:55   ` Jesper Nygårds
2012-03-24 11:14     ` Mikael Magnusson
     [not found]       ` <CABZhJg9xgaM7mr4dy8GYKHopAofnVRCzZmxfOsEca1VNugv6Cw@mail.gmail.com>
2012-03-24 22:04         ` Jesper Nygårds
2012-03-24 22:16           ` Mikael Magnusson
     [not found]             ` <CABZhJg_Aamsf57nhBFEvc0LX-pmOkrfRtGMccJo_Uwt=hoNQ6w@mail.gmail.com>
2012-03-25 14:23               ` Jesper Nygårds
2012-03-25 14:25             ` Jesper Nygårds
2012-03-25 14:51               ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).