mvn: fix and cleanup dynamic profiles logic
This commit is contained in:
parent
fff756069f
commit
f4b2e460c7
|
@ -68,64 +68,43 @@ alias mvntc='mvn tomcat:run'
|
||||||
alias mvntc7='mvn tomcat7:run'
|
alias mvntc7='mvn tomcat7:run'
|
||||||
alias mvn-updates='mvn versions:display-dependency-updates'
|
alias mvn-updates='mvn versions:display-dependency-updates'
|
||||||
|
|
||||||
#realpath replacement for iOS - not always present
|
|
||||||
function _realpath {
|
function listMavenCompletions {
|
||||||
if [[ -f "$1" ]]
|
local file new_file
|
||||||
then
|
local -a profiles POM_FILES
|
||||||
# file *must* exist
|
|
||||||
if cd "$(echo "${1%/*}")" &>/dev/null
|
# Root POM
|
||||||
then
|
POM_FILES=(~/.m2/settings.xml)
|
||||||
# file *may* not be local
|
|
||||||
# exception is ./file.ext
|
# POM in the current directory
|
||||||
# try 'cd .; cd -;' *works!*
|
if [[ -f pom.xml ]]; then
|
||||||
local tmppwd="$PWD"
|
local file=pom.xml
|
||||||
cd - &>/dev/null
|
POM_FILES+=("${file:A}")
|
||||||
else
|
|
||||||
# file *must* be local
|
|
||||||
local tmppwd="$PWD"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# file *cannot* exist
|
|
||||||
return 1 # failure
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# reassemble realpath
|
# Look for POM files in parent directories
|
||||||
echo "$tmppwd"/"${1##*/}"
|
while [[ -n "$file" ]] && grep -q "<parent>" "$file"; do
|
||||||
return 1 #success
|
# look for a new relativePath for parent pom.xml
|
||||||
}
|
new_file=$(grep -e "<relativePath>.*</relativePath>" "$file" | sed -e 's/.*<relativePath>\(.*\)<\/relativePath>.*/\1/')
|
||||||
|
|
||||||
function __pom_hierarchy {
|
# if <parent> is present but not defined, assume ../pom.xml
|
||||||
local file=`_realpath "pom.xml"`
|
if [[ -z "$new_file" ]]; then
|
||||||
POM_HIERARCHY+=("~/.m2/settings.xml")
|
|
||||||
POM_HIERARCHY+=("$file")
|
|
||||||
while [ -n "$file" ] && grep -q "<parent>" $file; do
|
|
||||||
##look for a new relativePath for parent pom.xml
|
|
||||||
local new_file=`grep -e "<relativePath>.*</relativePath>" $file | sed 's/.*<relativePath>//' | sed 's/<\/relativePath>.*//g'`
|
|
||||||
|
|
||||||
## <parent> is present but not defined. Asume ../pom.xml
|
|
||||||
if [ -z "$new_file" ]; then
|
|
||||||
new_file="../pom.xml"
|
new_file="../pom.xml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## if file exists continue else break
|
# if file doesn't exist break
|
||||||
new_pom=`_realpath "${file%/*}/$new_file"`
|
file="${file:h}/${new_file}"
|
||||||
if [ -n "$new_pom" ]; then
|
if ! [[ -e "$file" ]]; then
|
||||||
file=$new_pom
|
|
||||||
else
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
POM_HIERARCHY+=("$file")
|
|
||||||
|
POM_FILES+=("${file:A}")
|
||||||
done
|
done
|
||||||
}
|
|
||||||
|
|
||||||
function listMavenCompletions {
|
# Get profiles from found files
|
||||||
POM_HIERARCHY=()
|
for file in $POM_FILES; do
|
||||||
__pom_hierarchy
|
[[ -e $file ]] || continue
|
||||||
|
profiles+=($(sed 's/<!--.*-->//' "$file" | sed '/<!--/,/-->/d' | grep -e "<profile>" -A 1 | grep -e "<id>.*</id>" | sed 's?.*<id>\(.*\)<\/id>.*?-P\1?'))
|
||||||
profiles=()
|
|
||||||
#current pom profiles
|
|
||||||
for item in ${POM_HIERARCHY[*]}; do
|
|
||||||
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?'`)
|
|
||||||
done
|
done
|
||||||
|
|
||||||
reply=(
|
reply=(
|
||||||
|
@ -339,9 +318,6 @@ function listMavenCompletions {
|
||||||
|
|
||||||
$profiles
|
$profiles
|
||||||
)
|
)
|
||||||
|
|
||||||
unset POM_HIERARCHY
|
|
||||||
unset profiles
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compctl -K listMavenCompletions mvn mvnw
|
compctl -K listMavenCompletions mvn mvnw
|
||||||
|
|
Loading…
Reference in a new issue