diff --git a/_mvn b/_mvn index 095720c..cfe9a4c 100644 --- a/_mvn +++ b/_mvn @@ -72,9 +72,11 @@ # ------------------------------------------------------------------------------ -_mvn() -{ - local curcontext="$curcontext" state line cmds ret=1 maven_version excl_opts +typeset -A opt_args +local context state line + +_mvn() { + local curcontext="$curcontext" maven_version excl_opts excl_opts=(-h --help -v --version -ep --encrypt-password -emp --encrypt-master-password) @@ -93,7 +95,7 @@ _mvn() "($excl_opts -r --reactor)"{-r,--reactor}'[dynamically build reactor from subdirectories]:reactor:_mvn_reactors' ) else - return ret + return 1 fi [[ -n ${(M)words:#"-pl"} || -n ${(M)words:#"--projects"} ]] && opts+=( @@ -101,7 +103,7 @@ _mvn() "($excl_opts -amd --also-make-dependents)"{-amd,--also-make-dependents}'[if project list is specified, also build projects that depend on projects on the list]' ) - _arguments \ + _arguments -C \ "(- : *)"{-h,--help}'[display help information]' \ "(- : *)"{-v,--version}'[display version information]' \ "(- : *)"{-emp,--encrypt-master-password}'[encrypt master security password]:master password:_mvn_passwords' \ @@ -126,27 +128,21 @@ _mvn() "($excl_opts -o --offline -U --update-snapshots -cpu --check-plugin-updates -up --update-plugins)"{-o,--offline}'[work offline]' \ "($excl_opts -U --update-snapshots -nsu --no-snapshot-updates -o --offline)"{-U,--update-snapshots}'[force a check for updated releases and snapshots on remote repositories]' \ "($excl_opts -nsu --no-snapshot-updates -U --update-snapshots -o --offline)"{-nsu,--no-snapshot-updates}'[Supress SNAPSHOT updates]' \ - "($excl_opts)"{-D-,--define}'[define a system property]:property:_mvn_properties' \ + {-D-,--define}'[define a system property]:property:_mvn_properties' \ "$opts[@]" \ - "($excl_opts)*: :_mvn_args" \ - && ret=0 - - return ret + "($excl_opts)*: :_mvn_args" } -_mvn_args() -{ - local ret=1 +(( $+functions[_mvn_args] )) || +_mvn_args() { _alternative \ 'phases:phase:_mvn_phases' \ - 'goals:goal:_mvn_plugin_goals' \ - && ret=0 - return ret + 'goals:goal:_mvn_plugin_goals' } -_mvn_phases() -{ - local ret=1 phases +(( $+functions[_mvn_phases] )) || +_mvn_phases() { + local phases phases=( 'clean:remove all files generated by the previous build' 'compile:compile the source code of the project' @@ -183,13 +179,13 @@ _mvn_phases() 'post-site:executes processes needed to finalize the site generation, and to prepare for site deployment' ) fi - _describe -t 'phases' "phase" phases && ret=0 - return ret + _describe -t 'phases' "phase" phases } -_mvn_plugin_goals() -{ +(( $+functions[_mvn_plugin_goals] )) || +_mvn_plugin_goals() { local ret=1 + # TODO Plugin goals can also have the form groupId:artifactId:version:goal if compset -P '*:'; then _mvn_goals "${IPREFIX%:}" && ret=0 else @@ -198,9 +194,9 @@ _mvn_plugin_goals() return ret } -_mvn_plugins() -{ - local ret=1 plugins +(( $+functions[_mvn_plugins] )) || +_mvn_plugins() { + local plugins zstyle -a ":completion:${curcontext}:" plugins plugins [[ $#plugins -gt 0 ]] || plugins=( 'assembly:create archives of your projects sources, classes, dependencies etc. from flexible assembly descriptors' @@ -212,20 +208,11 @@ _mvn_plugins() 'archetype:create a Maven project from an existing template called an archetype' 'site:generate a site for the project' ) - _describe -t 'plugin' "plugin" plugins -S ':' && ret=0 - return ret + _describe -t 'plugin' "plugin" plugins -S ':' } -_mvn_goals_caching_policy() -{ - # Rebuild if cache is older than one month. - local -a oldp - oldp=( "$1"(NmM+1) ) - (( $#oldp )) -} - -_mvn_goals() -{ +(( $+functions[_mvn_goals] )) || +_mvn_goals() { local ret=1 plugin="$@" update_policy zstyle -s ":completion:${curcontext}:" cache-policy update_policy @@ -244,18 +231,18 @@ _mvn_goals() } # FIXME No idea what kind of value the "--reactor" option is supposed to take -_mvn_reactors() -{ +(( $+functions[_mvn_reactors] )) || +_mvn_reactors() { _message -e reactors 'reactor' } -_mvn_passwords() -{ +(( $+functions[_mvn_passwords] )) || +_mvn_passwords() { _message -e passwords 'password' } -_mvn_thread_counts() -{ +(( $+functions[_mvn_thread_counts] )) || +_mvn_thread_counts() { local thread_counts thread_counts=( '1:build with 1 thread' '1C:build with 1 thread per CPU core' @@ -270,47 +257,28 @@ _mvn_thread_counts() _describe -t 'thread-counts' "thread count" thread_counts } -_mvn_pom_files() -{ +(( $+functions[_mvn_pom_files] )) || +_mvn_pom_files() { _files -g '*pom*\.xml*' } -_mvn_toolchains_files() -{ +(( $+functions[_mvn_toolchains_files] )) || +_mvn_toolchains_files() { _files } -_mvn_settings_files() -{ +(( $+functions[_mvn_settings_files] )) || +_mvn_settings_files() { _files -g '*settings*\.xml*' } -_mvn_log_files() -{ +(( $+functions[_mvn_log_files] )) || +_mvn_log_files() { _files } -_mvn_profiles_caching_policy() -{ - # Resolve the cache directory. - local cache_dir - zstyle -s ":completion:${curcontext}:" cache-path cache_dir - : ${cache_dir:=${ZDOTDIR:-$HOME}/.zcompcache} - - # Rebuild if cached file more recent than cache. - local cached_file="${1#$cache_dir}" - [[ -f $cached_file && $cached_file -nt "$1" ]] && return 0 - - # Rebuild if cache is older than one week. - local -a oldp - oldp=( "$1"(Nmw+1) ) - (( $#oldp )) && return 0 - - return 1 -} - -_mvn_profiles() -{ +(( $+functions[_mvn_profiles] )) || +_mvn_profiles() { # FIXME Use "mvn help:all-profiles" output instead of parsing... # Blocked on http://jira.codehaus.org/browse/MPH-82 and http://jira.codehaus.org/browse/MPH-83 local ret=1 profs update_policy settings_file files parent_pom_file cache_name profiles_section @@ -320,8 +288,8 @@ _mvn_profiles() profs=() + # Resolve profiles from settings.xml settings_file=${~opt_args[-s]:-${opt_args[--settings]:-~/.m2/settings.xml}} - if [[ -f $settings_file ]]; then unset profiles cache_name="mvn/profiles${settings_file:A}" @@ -338,9 +306,9 @@ _mvn_profiles() profs+=($profiles) fi - parent_pom_file=${~opt_args[-f]:-${opt_args[--file]:pom.xml}} + # Resolve project profiles + parent_pom_file=${~opt_args[-f]:-${opt_args[--file]:-pom.xml}} while [[ -f ${parent_pom_file:a:h:h}/pom.xml ]]; do parent_pom_file=${parent_pom_file:a:h:h}/pom.xml; done - if [[ -f $parent_pom_file ]]; then unset profiles cache_name="mvn/profiles${parent_pom_file:A}" @@ -365,8 +333,8 @@ _mvn_profiles() return ret } -_mvn_projects() -{ +(( $+functions[_mvn_projects] )) || +_mvn_projects() { # TODO projects can also be given in the form [groupId:]artifactId. local pom_file ret=1 @@ -383,10 +351,53 @@ _mvn_projects() return ret } -_mvn_properties() -{ - # TODO Complete some very common props like -DskipTests, etc. - _message -e property-names 'property name' +(( $+functions[_mvn_properties] )) || +_mvn_properties() { + local ret=1 + if compset -P '*='; then + # TODO Add callback for plugin specific handlers + _default && ret=0 + else + # TODO Split in several functions + _alternatives + local properties plugin_colon_goal + properties=( + 'skipTests:skip tests execution' + 'maven.test.skip=:skip tests compilation and execution' + 'gpg.passphrase=:gpg passphrase' + ) + for plugin_colon_goal in ${(M)words:#*:*}; do # FIXME pretty sure this matches more than just plugin:goals + # TODO Extract descriptions too + # FIXME Output seems to be truncated (eg release:prepare) + properties+=(${${${(M)${(f)"$(_call_program goals $words[1] -N org.apache.maven.plugins:maven-help-plugin:2.1.1:describe -Dplugin=${plugin_colon_goal%:*} -Dgoal=${plugin_colon_goal#*:} -Ddetail)"}:#*Expression: *}#*\{}%\}*}"=:$plugin_colon_goal parameter") + done + _describe -t 'property-names' "property name" properties && ret=0 # FIXME Don't add a space prefix + fi + return ret +} + +_mvn_goals_caching_policy() { + # Rebuild if cache is older than one month. + local -a oldp + oldp=( "$1"(NmM+1) ) + (( $#oldp )) +} + +_mvn_profiles_caching_policy() { + # Resolve the cache directory. + local cache_dir + zstyle -s ":completion:${curcontext}:" cache-path cache_dir + : ${cache_dir:=${ZDOTDIR:-$HOME}/.zcompcache} + + # Rebuild if cached file more recent than cache. + local cached_file="${1#$cache_dir}" + [[ -f $cached_file && $cached_file -nt "$1" ]] && return 0 + + # Rebuild if cache is older than one week. + local -a oldp + oldp=( "$1"(Nmw+1) ) + (( $#oldp )) && return 0 + + return 1 } _mvn "$@"