From fff756069f678ceda0b7c760b843c09bbc2bc72d Mon Sep 17 00:00:00 2001 From: kubamarchwicki Date: Sun, 1 Jun 2014 21:01:01 +0200 Subject: [PATCH] mvn: add dynamic profile support to mvn completion * Maven profiles for current pom.xml file * Maven profiles for pom hierarchy * Ommiting comments in profiles --- plugins/mvn/mvn.plugin.zsh | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index 66ea548ad..71bba454c 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -68,8 +68,66 @@ alias mvntc='mvn tomcat:run' alias mvntc7='mvn tomcat7:run' alias mvn-updates='mvn versions:display-dependency-updates' +#realpath replacement for iOS - not always present +function _realpath { + if [[ -f "$1" ]] + then + # file *must* exist + if cd "$(echo "${1%/*}")" &>/dev/null + then + # file *may* not be local + # exception is ./file.ext + # try 'cd .; cd -;' *works!* + local tmppwd="$PWD" + cd - &>/dev/null + else + # file *must* be local + local tmppwd="$PWD" + fi + else + # file *cannot* exist + return 1 # failure + fi + + # reassemble realpath + echo "$tmppwd"/"${1##*/}" + return 1 #success +} + +function __pom_hierarchy { + local file=`_realpath "pom.xml"` + POM_HIERARCHY+=("~/.m2/settings.xml") + POM_HIERARCHY+=("$file") + while [ -n "$file" ] && grep -q "" $file; do + ##look for a new relativePath for parent pom.xml + local new_file=`grep -e ".*" $file | sed 's/.*//' | sed 's/<\/relativePath>.*//g'` + + ## is present but not defined. Asume ../pom.xml + if [ -z "$new_file" ]; then + new_file="../pom.xml" + fi + + ## if file exists continue else break + new_pom=`_realpath "${file%/*}/$new_file"` + if [ -n "$new_pom" ]; then + file=$new_pom + else + break + fi + POM_HIERARCHY+=("$file") + done +} function listMavenCompletions { + POM_HIERARCHY=() + __pom_hierarchy + + profiles=() + #current pom profiles + for item in ${POM_HIERARCHY[*]}; do + profiles=($profiles `[ -e $item ] && cat $item | sed 's///' | sed '//d' | grep -e "" -A 1 | grep -e ".*" | sed 's?.*\(.*\)<\/id>.*?-P\1?'`) + done + reply=( # common lifecycle clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site @@ -278,7 +336,12 @@ function listMavenCompletions { cobertura:cobertura -Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi) -Dit.test=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi) + + $profiles ) + + unset POM_HIERARCHY + unset profiles } compctl -K listMavenCompletions mvn mvnw