Continue properties implementation

Cleanup
This commit is contained in:
Julien Nicoulaud 2011-08-03 00:10:52 +02:00
parent fcff9b4572
commit e761e82386
1 changed files with 125 additions and 84 deletions

209
_mvn
View File

@ -72,66 +72,9 @@
# ------------------------------------------------------------------------------
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)
_pick_variant -r maven_version maven3='Maven 3' maven2='Maven 2' unknown --version
if [[ $maven_version == 'maven3' ]]; then
opts=(
"($excl_opts -T --threads)"{-T,--threads}'[thread count, for instance 2.0C where C is core multiplied]:thread count:_mvn_thread_counts'
"($excl_opts -t --toolchains)"{-t,--toolchains}'[alternate path for the user toolchains file]:toolchains file:_mvn_toolchains_files'
"($excl_opts -l --log-file)"{-l,--log-file}'[log file to where all build output will go]:log file:_mvn_log_files'
)
elif [[ $maven_version == 'maven2' ]]; then
opts=(
"($excl_opts -cpu --check-plugin-updates -up --update-plugins -npu --no-plugin-updates -o --offline)"{-cpu,--check-plugin-updates,-up,--update-plugins}'[force upToDate check for any relevant registered plugins]'
"($excl_opts -npr --no-plugin-registry)"{-npr,--no-plugin-registry}'[don'\''t use plugin-registry.xml for plugin versions]'
"($excl_opts -npu --no-plugin-updates -cpu --check-plugin-updates -up --update-plugins)"{-npu,--no-plugin-updates}'[suppress upToDate check for any relevant registered plugins]'
"($excl_opts -r --reactor)"{-r,--reactor}'[dynamically build reactor from subdirectories]:reactor:_mvn_reactors'
)
else
return 1
fi
[[ -n ${(M)words:#"-pl"} || -n ${(M)words:#"--projects"} ]] && opts+=(
"($excl_opts -am --also-make)"{-am,--also-make}'[if project list is specified, also build projects required by the list]'
"($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 -C \
"(- : *)"{-h,--help}'[display help information]' \
"(- : *)"{-v,--version}'[display version information]' \
"(- : *)"{-emp,--encrypt-master-password}'[encrypt master security password]:master password:_mvn_passwords' \
"(- : *)"{-ep,--encrypt-password}'[encrypt server password]:password:_mvn_passwords' \
"($excl_opts -B --batch-mode)"{-B,--batch-mode}'[run in non-interactive (batch) mode]' \
"($excl_opts -V --show-version)"{-V,--show-version}'[display version information without stopping build]' \
"($excl_opts -q --quiet -X --debug)"{-q,--quiet}'[quiet output, only show errors]' \
"($excl_opts -X --debug -q --quiet)"{-X,--debug}'[produce execution debug output]' \
"($excl_opts -N --non-recursive)"{-N,--non-recursive}'[do not recurse into sub-projects]' \
"($excl_opts -C --strict-checksums -c --lax-checksums)"{-C,--strict-checksums}'[fail the build if checksums don'\''t match]' \
"($excl_opts -c --lax-checksums -C --strict-checksums)"{-c,--lax-checksums}'[warn if checksums don'\''t match]' \
"($excl_opts -e --errors)"{-e,--errors}'[produce execution error messages]' \
"($excl_opts -f --file)"{-f,--file}'[force the use of an alternate POM file]:POM file:_mvn_pom_files' \
"($excl_opts -s --settings)"{-s,--settings}'[alternate path for the user settings file]:settings file:_mvn_settings_files' \
"($excl_opts -gs --global-settings)"{-gs,--global-settings}'[alternate path for the global settings file]:global settings file:_mvn_settings_files' \
"($excl_opts -fae --fail-at-end -ff --fail-fast -fn --fail-never)"{-fae,--fail-at-end}'[only fail the build afterwards, allow all non-impacted builds to continue]' \
"($excl_opts -ff --fail-fast -fae --fail-at-end -fn --fail-never)"{-ff,--fail-fast}'[stop at first failure in reactorized builds]' \
"($excl_opts -fn --fail-never -fae --fail-at-end -ff --fail-fast)"{-fn,--fail-never}'[nerver fail the build, regardless of project result]' \
"($excl_opts -P --activate-profiles)"{-P,--activate-profiles}'[comma-delimited list of profiles to activate]:profile:_mvn_profiles' \
"($excl_opts -pl --projects)"{-pl,--projects}'[build specified reactor projects instead of all projects]:project list:_mvn_projects -s ,' \
"($excl_opts -rf --resume-from)"{-rf,--resume-from}'[resume reactor from specified project]:project:_mvn_projects' \
"($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]' \
{-D-,--define}'[define a system property]:property:_mvn_properties' \
"$opts[@]" \
"($excl_opts)*: :_mvn_args"
}
# ------------------------------------------------------------------------------
# Maven commands completers
# ------------------------------------------------------------------------------
(( $+functions[_mvn_args] )) ||
_mvn_args() {
@ -197,6 +140,7 @@ _mvn_plugin_goals() {
(( $+functions[_mvn_plugins] )) ||
_mvn_plugins() {
local plugins
# TODO Add the plugins for which we have a cache
zstyle -a ":completion:${curcontext}:" plugins plugins
[[ $#plugins -gt 0 ]] || plugins=(
'assembly:create archives of your projects sources, classes, dependencies etc. from flexible assembly descriptors'
@ -216,16 +160,16 @@ _mvn_goals() {
local ret=1 plugin="$@" update_policy
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_goals_caching_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_plugin_goals_caching_policy
unset goals
if ( [[ ${+goals} -eq 0 ]] || _cache_invalid "mvn/plugins/$plugin" ) && ! _retrieve_cache "mvn/plugins/$plugin"; then
if ( [[ ${+goals} -eq 0 ]] || _cache_invalid "mvn/plugins/${plugin}/_goals" ) && ! _retrieve_cache "mvn/plugins/${plugin}/_goals"; then
setopt localoptions extendedglob
goals=(${(s:,,,:)${${${(f)${${${(f)${${${${(F)${(S)${(f)"$(_call_program goals $words[1] -N org.apache.maven.plugins:maven-help-plugin:2.1.1:describe -Dplugin=$plugin)"}//#$plugin:/,,,}}:#*BUILD FAILURE*}#*This plugin has*goals#:}%For more information, run \'mvn help:describe*}}//:/\\:}}}// ##/ }// Description\\: /:}})
[[ $#goals -gt 0 ]] && _store_cache "mvn/plugins/$plugin" goals
[[ $#goals -gt 0 ]] && _store_cache "mvn/plugins/${plugin}/_goals" goals
fi
[[ $#goals -gt 0 ]] && _describe -t "plugin-$plugin-goals" "$plugin plugin goal" goals && ret=0
[[ $#goals -gt 0 ]] && _describe -t "plugin-${plugin}-goals" "${plugin} plugin goal" goals && ret=0
return ret
}
@ -358,45 +302,63 @@ _mvn_properties() {
# TODO Add callback for plugin specific handlers
_default && ret=0
else
# FIXME Don't add a space prefix
_alternative \
'maven properties:maven property:_mvn_maven_properties' \
'plugins properties:plugin property:_mvn_plugins_goals_properties' \
&& ret=0
local alternatives; alternatives=(
'maven properties:maven property:_mvn_maven_properties'
)
for plugin_colon_goal in ${(M)words:#*:*}; do # FIXME pretty sure this matches more than just plugin:goals
alternatives+=("plugin properties:plugin property:_mvn_plugin_goal_properties '${plugin_colon_goal%:*}' '${plugin_colon_goal#*:}'")
done
_alternative "${alternatives[@]}" && ret=0
fi
return ret
}
(( $+functions[_mvn_maven_properties] )) ||
_mvn_maven_properties() {
local properties
properties=(
# TODO Split in properties with values/properties without
local properties; properties=(
'skipTests:skip tests execution'
'maven.test.skip=:skip tests compilation and execution'
'gpg.passphrase=:gpg passphrase'
'maven.test.skip:skip tests compilation and execution'
'gpg.passphrase:gpg passphrase'
)
_describe -t 'maven-property-names' "Maven property name" properties
_describe -t 'maven-properties' "Maven property" properties -qS=
}
(( $+functions[_mvn_plugins_goals_properties] )) ||
_mvn_plugins_goals_properties() {
local properties
properties=()
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 property")
done
_describe -t 'plugins-property-names' "Plugins properties names" properties # FIXME Don't add a space prefix
_mvn_plugin_goal_properties() {
local plugin="${(P)$(($# -1))}" goal="${(P)${#}}" update_policy ret=1
zstyle -s ":completion:${curcontext}:" cache-policy update_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_plugin_goal_properties_caching_policy
unset properties
if ( [[ ${+properties} -eq 0 ]] || _cache_invalid "mvn/plugins/${plugin}/${goal}" ) && ! _retrieve_cache "mvn/plugins/${plugin}/${goal}"; then
# TODO Extract property description too
properties=(${${${(M)${(f)"$(_call_program goals $words[1] -N org.apache.maven.plugins:maven-help-plugin:2.1.1:describe -Dplugin=$plugin -Dgoal=$goal -Ddetail)"}:#*Expression: *}#*\{}%\}*})
[[ $#properties -gt 0 ]] && _store_cache "mvn/plugins/${plugin}/${goal}" properties
fi
[[ $#properties -gt 0 ]] && _describe -t "plugin-${plugin}-${goal}-properties" "${plugin}:${goal} property" properties -qS= && ret=0
return ret
}
_mvn_goals_caching_policy() {
# ------------------------------------------------------------------------------
# Default caching policies
# ------------------------------------------------------------------------------
_mvn_plugin_goals_caching_policy() {
# Rebuild if cache is older than one month.
local -a oldp
oldp=( "$1"(NmM+1) )
(( $#oldp ))
}
_mvn_plugin_goal_properties_caching_policy() {
_mvn_plugin_goals_caching_policy
}
_mvn_profiles_caching_policy() {
# Resolve the cache directory.
local cache_dir
@ -415,4 +377,83 @@ _mvn_profiles_caching_policy() {
return 1
}
# ------------------------------------------------------------------------------
# Plugin specific completions
# ------------------------------------------------------------------------------
# TODO Add completion handlers for commonly used command line goals:
# * help:describe
# * release:prepare
# * release:perform
# * gpg:sign
# * deploy:deploy-file
# * install:install-file
# ------------------------------------------------------------------------------
# Core mvn command completion
# ------------------------------------------------------------------------------
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)
_pick_variant -r maven_version maven3='Maven 3' maven2='Maven 2' unknown --version
if [[ $maven_version == 'maven3' ]]; then
opts=(
"($excl_opts -T --threads)"{-T,--threads}'[thread count, for instance 2.0C where C is core multiplied]:thread count:_mvn_thread_counts'
"($excl_opts -t --toolchains)"{-t,--toolchains}'[alternate path for the user toolchains file]:toolchains file:_mvn_toolchains_files'
"($excl_opts -l --log-file)"{-l,--log-file}'[log file to where all build output will go]:log file:_mvn_log_files'
)
elif [[ $maven_version == 'maven2' ]]; then
opts=(
"($excl_opts -cpu --check-plugin-updates -up --update-plugins -npu --no-plugin-updates -o --offline)"{-cpu,--check-plugin-updates,-up,--update-plugins}'[force upToDate check for any relevant registered plugins]'
"($excl_opts -npr --no-plugin-registry)"{-npr,--no-plugin-registry}'[don'\''t use plugin-registry.xml for plugin versions]'
"($excl_opts -npu --no-plugin-updates -cpu --check-plugin-updates -up --update-plugins)"{-npu,--no-plugin-updates}'[suppress upToDate check for any relevant registered plugins]'
"($excl_opts -r --reactor)"{-r,--reactor}'[dynamically build reactor from subdirectories]:reactor:_mvn_reactors'
)
else
return 1
fi
[[ -n ${(M)words:#"-pl"} || -n ${(M)words:#"--projects"} ]] && opts+=(
"($excl_opts -am --also-make)"{-am,--also-make}'[if project list is specified, also build projects required by the list]'
"($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 -C \
"(- : *)"{-h,--help}'[display help information]' \
"(- : *)"{-v,--version}'[display version information]' \
"(- : *)"{-emp,--encrypt-master-password}'[encrypt master security password]:master password:_mvn_passwords' \
"(- : *)"{-ep,--encrypt-password}'[encrypt server password]:password:_mvn_passwords' \
"($excl_opts -B --batch-mode)"{-B,--batch-mode}'[run in non-interactive (batch) mode]' \
"($excl_opts -V --show-version)"{-V,--show-version}'[display version information without stopping build]' \
"($excl_opts -q --quiet -X --debug)"{-q,--quiet}'[quiet output, only show errors]' \
"($excl_opts -X --debug -q --quiet)"{-X,--debug}'[produce execution debug output]' \
"($excl_opts -N --non-recursive)"{-N,--non-recursive}'[do not recurse into sub-projects]' \
"($excl_opts -C --strict-checksums -c --lax-checksums)"{-C,--strict-checksums}'[fail the build if checksums don'\''t match]' \
"($excl_opts -c --lax-checksums -C --strict-checksums)"{-c,--lax-checksums}'[warn if checksums don'\''t match]' \
"($excl_opts -e --errors)"{-e,--errors}'[produce execution error messages]' \
"($excl_opts -f --file)"{-f,--file}'[force the use of an alternate POM file]:POM file:_mvn_pom_files' \
"($excl_opts -s --settings)"{-s,--settings}'[alternate path for the user settings file]:settings file:_mvn_settings_files' \
"($excl_opts -gs --global-settings)"{-gs,--global-settings}'[alternate path for the global settings file]:global settings file:_mvn_settings_files' \
"($excl_opts -fae --fail-at-end -ff --fail-fast -fn --fail-never)"{-fae,--fail-at-end}'[only fail the build afterwards, allow all non-impacted builds to continue]' \
"($excl_opts -ff --fail-fast -fae --fail-at-end -fn --fail-never)"{-ff,--fail-fast}'[stop at first failure in reactorized builds]' \
"($excl_opts -fn --fail-never -fae --fail-at-end -ff --fail-fast)"{-fn,--fail-never}'[nerver fail the build, regardless of project result]' \
"($excl_opts -P --activate-profiles)"{-P,--activate-profiles}'[comma-delimited list of profiles to activate]:profile:_mvn_profiles' \
"($excl_opts -pl --projects)"{-pl,--projects}'[build specified reactor projects instead of all projects]:project list:_mvn_projects -s ,' \
"($excl_opts -rf --resume-from)"{-rf,--resume-from}'[resume reactor from specified project]:project:_mvn_projects' \
"($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]' \
{-D-,--define}'[define a system property]:property:_mvn_properties' \
"$opts[@]" \
"($excl_opts)*: :_mvn_args"
}
_mvn "$@"