Merge pull request #1250 from zsh-users/refactor_mvn

Refactor mvn completion
This commit is contained in:
Shohei YOSHIDA 2026-03-26 23:58:22 +09:00 committed by GitHub
commit 109a9c809d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 51 additions and 28 deletions

View File

@ -266,14 +266,19 @@ _mvn_groupIds() {
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_groupIds_caching_policy [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_groupIds_caching_policy
if [[ -d $repository_location ]]; then if [[ -d $repository_location ]]; then
unset _groupIds local -a groupIds
if ( [[ ${+_groupIds} -eq 0 ]] || _cache_invalid "mvn/repositories/${repository_location}/groupIds" ) && ! _retrieve_cache "mvn/repositories/${repository_location}/groupIds"; then local cache_key="mvn/repositories/${repository_location}/groupIds"
_groupIds=($repository_location/**/) if ( _cache_invalid $cache_key ) && ! _retrieve_cache $cache_key; then
_groupIds=(${${${(u)_groupIds:h:h}#"$repository_location/"}//\//.}) groupIds=($repository_location/**/)
[[ $#_groupIds -gt 0 ]] && _store_cache "mvn/repositories/${repository_location}/groupIds" _groupIds groupIds=(${${${(u)_groupIds:h:h}#"$repository_location/"}//\//.})
if (( $#groupIds > 0 )); then
_store_cache $cache_key groupIds
fi
fi fi
[[ $#_groupIds -gt 0 ]] && _multi_parts $@ . _groupIds && ret=0 if (( $#groupIds > 0 )); then
_multi_parts $@ . groupIds && ret=0
fi
fi fi
return ret return ret
@ -310,14 +315,19 @@ _mvn_plugin_goals() {
zstyle -s ":completion:${curcontext}:" cache-policy 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_goals_caching_policy
unset _goals local -a goals
if ( [[ ${+_goals} -eq 0 ]] || _cache_invalid "mvn/plugins/${plugin}" ) && ! _retrieve_cache "mvn/plugins/${plugin}"; then local cache_key="mvn/plugins/${plugin}"
if _cache_invalid $cache_key && ! _retrieve_cache $cache_key; then
setopt localoptions extendedglob 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)"}//#$(__mvn_get_plugin_prefix $plugin):/,,,}}:#*BUILD FAILURE*}#*This plugin has*goals#:}%For more information, run \'mvn help:describe*}}//:/\\:}}}// ##/ }// Description\\: /:}}) _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)"}//#$(__mvn_get_plugin_prefix $plugin):/,,,}}:#*BUILD FAILURE*}#*This plugin has*goals#:}%For more information, run \'mvn help:describe*}}//:/\\:}}}// ##/ }// Description\\: /:}})
[[ $#_goals -gt 0 ]] && _store_cache "mvn/plugins/${plugin}" _goals if (( $#goals > 0 )); then
_store_cache "mvn/plugins/${plugin}" goals
fi
fi fi
[[ $#_goals -gt 0 ]] && _describe -t "goals" "${plugin} goal" _goals $@[0,-2] && ret=0 if (( $#goals > 0 )); then
_describe -t "goals" "${plugin} goal" goals $@[0,-2] && ret=0
fi
return ret return ret
} }
@ -338,44 +348,52 @@ _mvn_profiles() {
# Resolve profiles from settings.xml # Resolve profiles from settings.xml
if [[ -f $settings_file ]]; then if [[ -f $settings_file ]]; then
unset _profiles local -a profiles
cache_name="mvn/profiles${settings_file:A}" # FIXME Don't use A modifier, it is only available on Zsh >= 4.3.10 cache_name="mvn/profiles${settings_file:A}" # FIXME Don't use A modifier, it is only available on Zsh >= 4.3.10
if ( [[ ${+_profiles} -eq 0 ]] || _cache_invalid "$cache_name" ) && ! _retrieve_cache "$cache_name"; then if _cache_invalid "$cache_name" && ! _retrieve_cache "$cache_name"; then
_profiles=() profiles=()
profiles_section="${(M)${(f)$(<$settings_file)}:#*<profiles>*}" profiles_section="${(M)${(f)$(<$settings_file)}:#*<profiles>*}"
if [[ -n "$profiles_section" ]]; then if [[ -n "$profiles_section" ]]; then
for profile in ${(s:,,,:)${${${(S)${(S)${(S)${(S)${${profiles_section#*<profile>}%</profile>*}//<repositories>*<\/repositories>}//<pluginRepositories>*<\/pluginRepositories>}//<build>*<\/build>}//<\/id>*<id>/,,,}##*<id>}%%</id>*}}; do for profile in ${(s:,,,:)${${${(S)${(S)${(S)${(S)${${profiles_section#*<profile>}%</profile>*}//<repositories>*<\/repositories>}//<pluginRepositories>*<\/pluginRepositories>}//<build>*<\/build>}//<\/id>*<id>/,,,}##*<id>}%%</id>*}}; do
[[ -z ${(M)profiles:#"$profile"*} ]] && _profiles+=("$profile"'['"in settings file"']') [[ -z ${(M)profiles:#"$profile"*} ]] && profiles+=("$profile"'['"in settings file"']')
done done
fi fi
[[ $#_profiles -gt 0 ]] && _store_cache "$cache_name" _profiles
if (( $#profiles > 0 )); then
_store_cache "$cache_name" profiles
fi fi
profs+=($_profiles) fi
profs+=($profiles)
fi fi
# Resolve project profiles # Resolve project profiles
if [[ -f $parent_pom_file ]]; then if [[ -f $parent_pom_file ]]; then
unset _profiles local -a profiles
cache_name="mvn/profiles${parent_pom_file:A}" # FIXME Don't use A modifier, it is only available on Zsh >= 4.3.10 cache_name="mvn/profiles${parent_pom_file:A}" # FIXME Don't use A modifier, it is only available on Zsh >= 4.3.10
if ( [[ ${+_profiles} -eq 0 ]] || _cache_invalid "$cache_name" ) && ! _retrieve_cache "$cache_name"; then if _cache_invalid "$cache_name" && ! _retrieve_cache "$cache_name"; then
_profiles=() profiles=()
setopt localoptions extendedglob setopt localoptions extendedglob
for file in ${parent_pom_file:h}/**/pom.xml~*target\/*; do # FIXME project.build.directory is not always target/ for file in ${parent_pom_file:h}/**/pom.xml~*target\/*; do # FIXME project.build.directory is not always target/
profiles_section="${(M)${(f)$(<$file)}:#*<profiles>*}" profiles_section="${(M)${(f)$(<$file)}:#*<profiles>*}"
if [[ -n "$profiles_section" ]]; then if [[ -n "$profiles_section" ]]; then
for profile in ${(s:,,,:)${${${(S)${(S)${(S)${(S)${${profiles_section#*<profile>}%</profile>*}//<repositories>*<\/repositories>}//<pluginRepositories>*<\/pluginRepositories>}//<build>*<\/build>}//<\/id>*<id>/,,,}##*<id>}%%</id>*}}; do for profile in ${(s:,,,:)${${${(S)${(S)${(S)${(S)${${profiles_section#*<profile>}%</profile>*}//<repositories>*<\/repositories>}//<pluginRepositories>*<\/pluginRepositories>}//<build>*<\/build>}//<\/id>*<id>/,,,}##*<id>}%%</id>*}}; do
[[ -z ${(M)profiles:#"$profile"*} ]] && _profiles+=("$profile"'['"in ${file#${parent_pom_file:h}\/}"']') [[ -z ${(M)profiles:#"$profile"*} ]] && profiles+=("$profile"'['"in ${file#${parent_pom_file:h}\/}"']')
done done
fi fi
done done
[[ $#_profiles -gt 0 ]] && _store_cache "$cache_name" _profiles
if (( $#profiles > 0)); then
_store_cache "$cache_name" profiles
fi fi
profs+=($_profiles) fi
profs+=($profiles)
fi fi
compset -P '-'; compset -P '+'; compset -P '!' # FIXME Only works for the first profile compset -P '-'; compset -P '+'; compset -P '!' # FIXME Only works for the first profile
[[ $#profs -gt 0 ]] && _values $@ 'profile' "${profs[@]}" && ret=0 if (( $profs > 0 )); then
_values $@ 'profile' "${profs[@]}" && ret=0
fi
return ret return ret
} }
@ -437,16 +455,21 @@ _mvn_plugin_goal_property_names() {
zstyle -s ":completion:${curcontext}:" cache-policy update_policy zstyle -s ":completion:${curcontext}:" cache-policy update_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_properties_caching_policy [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _mvn_properties_caching_policy
unset _properties local -a properties
if ( [[ ${+_properties} -eq 0 ]] || _cache_invalid "mvn/plugins/${plugin_colon_goal}" ) && ! _retrieve_cache "mvn/plugins/${plugin_colon_goal}"; then local cache_key="mvn/plugins/${plugin_colon_goal}"
if _cache_invalid $cache_key && ! _retrieve_cache $cache_key; then
# FIXME Does not work for: # FIXME Does not work for:
# android:apk (new line before expression) # android:apk (new line before expression)
# ear:ear (unknown cause) # ear:ear (unknown cause)
_properties=(${(M)${(ps:,,,:)${${${${(pj: :)${${${(f)${"$(_call_program properties $words[1] -N org.apache.maven.plugins:maven-help-plugin:2.1.1:describe -Dplugin=${plugin_colon_goal%:*} -Dgoal=${plugin_colon_goal##*:} -Ddetail)"#*Available parameters:}%%\[INFO\]*}//# [a-z]*/,,,}##*Expression: \$\{}}//\}[[:space:]]##/:}//[[:space:]]##/ }//[[:space:]]#,,,[[:space:]]#/,,,}}:#[a-zA-Z]##:*}) properties=(${(M)${(ps:,,,:)${${${${(pj: :)${${${(f)${"$(_call_program properties $words[1] -N org.apache.maven.plugins:maven-help-plugin:2.1.1:describe -Dplugin=${plugin_colon_goal%:*} -Dgoal=${plugin_colon_goal##*:} -Ddetail)"#*Available parameters:}%%\[INFO\]*}//# [a-z]*/,,,}##*Expression: \$\{}}//\}[[:space:]]##/:}//[[:space:]]##/ }//[[:space:]]#,,,[[:space:]]#/,,,}}:#[a-zA-Z]##:*})
[[ $#_properties -gt 0 ]] && _store_cache "mvn/plugins/${plugin_colon_goal}" _properties if (( $#properties > 0 )); then
_store_cache $cache_key properties
fi
fi fi
[[ $#_properties -gt 0 ]] && _describe -t "${plugin_colon_goal//:/-}-property-names" "${plugin_colon_goal} property name" _properties $@[0,-2] && ret=0 if (( $#properties > 0 )); then
_describe -t "${plugin_colon_goal//:/-}-property-names" "${plugin_colon_goal} property name" properties $@[0,-2] && ret=0
fi
return ret return ret
} }