support for invalid pom

This commit is contained in:
Paweł Płazieński 2015-12-22 13:27:05 +01:00
parent 3f86fb964e
commit f1e18348d4

16
.zshrc
View File

@ -175,8 +175,8 @@ prompt_vcs() {
# Dir: current working directory # Dir: current working directory
prompt_mvn() { prompt_mvn() {
if [[ -n "$MAVEN_PROJECT_ARTIFACT" ]]; then if [[ -n "$MAVEN_PROJECT" ]]; then
prompt_segment magenta $PRIMARY_FG " $MAVEN_PROJECT_ARTIFACT@$MAVEN_PROJECT_VERSION " prompt_segment magenta $PRIMARY_FG " $MAVEN_PROJECT "
fi fi
} }
@ -421,19 +421,21 @@ maven_read_project() {
local location parts local location parts
location=$(find_up pom.xml) location=$(find_up pom.xml)
if [[ ! -r "$location" || -z $commands[xmllint] ]]; then if [[ ! -r "$location" || -z $commands[xmllint] ]]; then
MAVEN_PROJECT_ARTIFACT="" MAVEN_PROJECT=""
MAVEN_PROJECT_VERSION=""
return 1; return 1;
fi fi
# executing xmllint takes some time, so this does it in single execution # executing xmllint takes some time, so this does it in single execution
parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \ parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \
"cat /*[local-name()='project']/*[local-name()='version']/text()\n" \ "cat /*[local-name()='project']/*[local-name()='version']/text()\n" \
"cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" | \ "cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" | \
xmllint --shell $location | \ xmllint --shell $location 2>/dev/null | \
sed '/^\/ >/d' | \ sed '/^\/ >/d' | \
sed '/^ -------/d')) sed '/^ -------/d'))
MAVEN_PROJECT_ARTIFACT=${parts[1]} if [[ "${#parts}" > 1 ]]; then
MAVEN_PROJECT_VERSION=${parts[2]} MAVEN_PROJECT="${parts[1]}@${parts[2]}"
else
MAVEN_PROJECT="pom!"
fi;
} }
add-zsh-hook chpwd maven_read_project add-zsh-hook chpwd maven_read_project