fff756069f678ceda0b7c760b843c09bbc2bc72d

Author
kubamarchwicki <kuba@marchwicki.pl>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

mvn: add dynamic profile support to mvn completion

* Maven profiles for current pom.xml file
* Maven profiles for pom hierarchy
* Ommiting comments in profiles

Diff

 1diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh
 2index 66ea548ad196341ae27eb87a4f9c6499fbd53d70..71bba454c98a919ca27731cdc62f0614e121bbc6 100644
 3--- a/plugins/mvn/mvn.plugin.zsh
 4+++ b/plugins/mvn/mvn.plugin.zsh
 5@@ -68,8 +68,66 @@ alias mvntc='mvn tomcat:run'
 6 alias mvntc7='mvn tomcat7:run'
 7 alias mvn-updates='mvn versions:display-dependency-updates'
 8 
 9+#realpath replacement for iOS - not always present
10+function _realpath {
11+	if [[ -f "$1" ]]
12+	then
13+		# file *must* exist
14+		if cd "$(echo "${1%/*}")" &>/dev/null
15+		then
16+			# file *may* not be local
17+			# exception is ./file.ext
18+			# try 'cd .; cd -;' *works!*
19+			local tmppwd="$PWD"
20+			cd - &>/dev/null
21+		else
22+			# file *must* be local
23+			local tmppwd="$PWD"
24+		fi
25+	else
26+		# file *cannot* exist
27+		return 1 # failure
28+	fi
29+
30+	# reassemble realpath
31+	echo "$tmppwd"/"${1##*/}"
32+	return 1 #success
33+}
34+
35+function __pom_hierarchy {
36+	local file=`_realpath "pom.xml"`
37+	POM_HIERARCHY+=("~/.m2/settings.xml")
38+	POM_HIERARCHY+=("$file")
39+	while [ -n "$file" ] && grep -q "<parent>" $file; do
40+		##look for a new relativePath for parent pom.xml
41+		local new_file=`grep -e "<relativePath>.*</relativePath>" $file | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g'`
42+
43+		## <parent> is present but not defined. Asume ../pom.xml
44+		if [ -z "$new_file" ]; then
45+			new_file="../pom.xml"
46+		fi
47+
48+		## if file exists continue else break
49+		new_pom=`_realpath "${file%/*}/$new_file"`
50+		if [ -n "$new_pom" ]; then
51+			file=$new_pom
52+		else
53+			break
54+		fi
55+		POM_HIERARCHY+=("$file")
56+	done
57+}
58 
59 function listMavenCompletions {
60+	POM_HIERARCHY=()
61+	__pom_hierarchy
62+
63+	profiles=()
64+	#current pom profiles
65+	for item in ${POM_HIERARCHY[*]}; do
66+		profiles=($profiles `[ -e $item ] && cat $item | sed 's/<!--.*-->//' | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'`)
67+	done
68+
69 	reply=(
70 		# common lifecycle
71 		clean initialize process-resources compile process-test-resources test-compile test package verify install deploy site
72@@ -278,7 +336,12 @@ function listMavenCompletions {
73 		cobertura:cobertura
74 		-Dtest=$(if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi)
75 		-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)
76+
77+		$profiles
78 	)
79+
80+	unset POM_HIERARCHY
81+	unset profiles
82 }
83 
84 compctl -K listMavenCompletions mvn mvnw