Add first version of properties support
This commit is contained in:
parent
0256449d3a
commit
2ee6fa1a32
175
_mvn
175
_mvn
|
@ -72,9 +72,11 @@
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
_mvn()
|
typeset -A opt_args
|
||||||
{
|
local context state line
|
||||||
local curcontext="$curcontext" state line cmds ret=1 maven_version excl_opts
|
|
||||||
|
_mvn() {
|
||||||
|
local curcontext="$curcontext" maven_version excl_opts
|
||||||
|
|
||||||
excl_opts=(-h --help -v --version -ep --encrypt-password -emp --encrypt-master-password)
|
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'
|
"($excl_opts -r --reactor)"{-r,--reactor}'[dynamically build reactor from subdirectories]:reactor:_mvn_reactors'
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
return ret
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n ${(M)words:#"-pl"} || -n ${(M)words:#"--projects"} ]] && opts+=(
|
[[ -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]'
|
"($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]' \
|
"(- : *)"{-h,--help}'[display help information]' \
|
||||||
"(- : *)"{-v,--version}'[display version information]' \
|
"(- : *)"{-v,--version}'[display version information]' \
|
||||||
"(- : *)"{-emp,--encrypt-master-password}'[encrypt master security password]:master password:_mvn_passwords' \
|
"(- : *)"{-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 -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 -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 -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[@]" \
|
"$opts[@]" \
|
||||||
"($excl_opts)*: :_mvn_args" \
|
"($excl_opts)*: :_mvn_args"
|
||||||
&& ret=0
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_args()
|
(( $+functions[_mvn_args] )) ||
|
||||||
{
|
_mvn_args() {
|
||||||
local ret=1
|
|
||||||
_alternative \
|
_alternative \
|
||||||
'phases:phase:_mvn_phases' \
|
'phases:phase:_mvn_phases' \
|
||||||
'goals:goal:_mvn_plugin_goals' \
|
'goals:goal:_mvn_plugin_goals'
|
||||||
&& ret=0
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_phases()
|
(( $+functions[_mvn_phases] )) ||
|
||||||
{
|
_mvn_phases() {
|
||||||
local ret=1 phases
|
local phases
|
||||||
phases=(
|
phases=(
|
||||||
'clean:remove all files generated by the previous build'
|
'clean:remove all files generated by the previous build'
|
||||||
'compile:compile the source code of the project'
|
'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'
|
'post-site:executes processes needed to finalize the site generation, and to prepare for site deployment'
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
_describe -t 'phases' "phase" phases && ret=0
|
_describe -t 'phases' "phase" phases
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_plugin_goals()
|
(( $+functions[_mvn_plugin_goals] )) ||
|
||||||
{
|
_mvn_plugin_goals() {
|
||||||
local ret=1
|
local ret=1
|
||||||
|
# TODO Plugin goals can also have the form groupId:artifactId:version:goal
|
||||||
if compset -P '*:'; then
|
if compset -P '*:'; then
|
||||||
_mvn_goals "${IPREFIX%:}" && ret=0
|
_mvn_goals "${IPREFIX%:}" && ret=0
|
||||||
else
|
else
|
||||||
|
@ -198,9 +194,9 @@ _mvn_plugin_goals()
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_plugins()
|
(( $+functions[_mvn_plugins] )) ||
|
||||||
{
|
_mvn_plugins() {
|
||||||
local ret=1 plugins
|
local plugins
|
||||||
zstyle -a ":completion:${curcontext}:" plugins plugins
|
zstyle -a ":completion:${curcontext}:" plugins plugins
|
||||||
[[ $#plugins -gt 0 ]] || plugins=(
|
[[ $#plugins -gt 0 ]] || plugins=(
|
||||||
'assembly:create archives of your projects sources, classes, dependencies etc. from flexible assembly descriptors'
|
'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'
|
'archetype:create a Maven project from an existing template called an archetype'
|
||||||
'site:generate a site for the project'
|
'site:generate a site for the project'
|
||||||
)
|
)
|
||||||
_describe -t 'plugin' "plugin" plugins -S ':' && ret=0
|
_describe -t 'plugin' "plugin" plugins -S ':'
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_goals_caching_policy()
|
(( $+functions[_mvn_goals] )) ||
|
||||||
{
|
_mvn_goals() {
|
||||||
# Rebuild if cache is older than one month.
|
|
||||||
local -a oldp
|
|
||||||
oldp=( "$1"(NmM+1) )
|
|
||||||
(( $#oldp ))
|
|
||||||
}
|
|
||||||
|
|
||||||
_mvn_goals()
|
|
||||||
{
|
|
||||||
local ret=1 plugin="$@" update_policy
|
local ret=1 plugin="$@" update_policy
|
||||||
|
|
||||||
zstyle -s ":completion:${curcontext}:" cache-policy 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
|
# 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'
|
_message -e reactors 'reactor'
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_passwords()
|
(( $+functions[_mvn_passwords] )) ||
|
||||||
{
|
_mvn_passwords() {
|
||||||
_message -e passwords 'password'
|
_message -e passwords 'password'
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_thread_counts()
|
(( $+functions[_mvn_thread_counts] )) ||
|
||||||
{
|
_mvn_thread_counts() {
|
||||||
local thread_counts
|
local thread_counts
|
||||||
thread_counts=(
|
thread_counts=(
|
||||||
'1:build with 1 thread' '1C:build with 1 thread per CPU core'
|
'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
|
_describe -t 'thread-counts' "thread count" thread_counts
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_pom_files()
|
(( $+functions[_mvn_pom_files] )) ||
|
||||||
{
|
_mvn_pom_files() {
|
||||||
_files -g '*pom*\.xml*'
|
_files -g '*pom*\.xml*'
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_toolchains_files()
|
(( $+functions[_mvn_toolchains_files] )) ||
|
||||||
{
|
_mvn_toolchains_files() {
|
||||||
_files
|
_files
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_settings_files()
|
(( $+functions[_mvn_settings_files] )) ||
|
||||||
{
|
_mvn_settings_files() {
|
||||||
_files -g '*settings*\.xml*'
|
_files -g '*settings*\.xml*'
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_log_files()
|
(( $+functions[_mvn_log_files] )) ||
|
||||||
{
|
_mvn_log_files() {
|
||||||
_files
|
_files
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_profiles_caching_policy()
|
(( $+functions[_mvn_profiles] )) ||
|
||||||
{
|
_mvn_profiles() {
|
||||||
# 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()
|
|
||||||
{
|
|
||||||
# FIXME Use "mvn help:all-profiles" output instead of parsing...
|
# 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
|
# 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
|
local ret=1 profs update_policy settings_file files parent_pom_file cache_name profiles_section
|
||||||
|
@ -320,8 +288,8 @@ _mvn_profiles()
|
||||||
|
|
||||||
profs=()
|
profs=()
|
||||||
|
|
||||||
|
# Resolve profiles from settings.xml
|
||||||
settings_file=${~opt_args[-s]:-${opt_args[--settings]:-~/.m2/settings.xml}}
|
settings_file=${~opt_args[-s]:-${opt_args[--settings]:-~/.m2/settings.xml}}
|
||||||
|
|
||||||
if [[ -f $settings_file ]]; then
|
if [[ -f $settings_file ]]; then
|
||||||
unset profiles
|
unset profiles
|
||||||
cache_name="mvn/profiles${settings_file:A}"
|
cache_name="mvn/profiles${settings_file:A}"
|
||||||
|
@ -338,9 +306,9 @@ _mvn_profiles()
|
||||||
profs+=($profiles)
|
profs+=($profiles)
|
||||||
fi
|
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
|
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
|
if [[ -f $parent_pom_file ]]; then
|
||||||
unset profiles
|
unset profiles
|
||||||
cache_name="mvn/profiles${parent_pom_file:A}"
|
cache_name="mvn/profiles${parent_pom_file:A}"
|
||||||
|
@ -365,8 +333,8 @@ _mvn_profiles()
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_projects()
|
(( $+functions[_mvn_projects] )) ||
|
||||||
{
|
_mvn_projects() {
|
||||||
# TODO projects can also be given in the form [groupId:]artifactId.
|
# TODO projects can also be given in the form [groupId:]artifactId.
|
||||||
local pom_file ret=1
|
local pom_file ret=1
|
||||||
|
|
||||||
|
@ -383,10 +351,53 @@ _mvn_projects()
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
_mvn_properties()
|
(( $+functions[_mvn_properties] )) ||
|
||||||
{
|
_mvn_properties() {
|
||||||
# TODO Complete some very common props like -DskipTests, etc.
|
local ret=1
|
||||||
_message -e property-names 'property name'
|
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 "$@"
|
_mvn "$@"
|
||||||
|
|
Loading…
Reference in New Issue