support des fichiers pom.xml

This commit is contained in:
2015-03-23 13:21:56 +04:00
parent 6d853303b9
commit 4f0a746d04
2 changed files with 72 additions and 4 deletions

View File

@@ -85,8 +85,48 @@ function list_feature_branches() {
################################################################################
# Outils de haut niveau
function __pom_get_version() {
# obtenir la version dans le pom $1(=pom.xml)
local pom="${1:-pom.xml}"
awk <"$pom" '/^[ \t]*<version>/ {
sub(/^.*<version>/, "")
sub(/<\/version>.*$/, "")
print
exit
}'
}
function __pom_set_version() {
# modifier la version du le fichier $1(=pom.xml) à la valeur
# $2(=1.0.0-SNAPSHOT)
local pom="${1:-pom.xml}"
local version="${2:-1.0.0-SNAPSHOT}"
local tmpfile; ac_set_tmpfile tmpfile
awk <"$pom" >"$tmpfile" '
BEGIN {
version = '"$(qawk "$version")"'
found = 0
}
!found && $0 ~ /^[ \t]*<version>/ {
prefix = "<version>"
if (match($0, /^.*<version>/)) {
prefix = substr($0, RSTART, RLENGTH)
}
suffix = "</version>"
if (match($0, /<\/version>.*$/)) {
suffix = substr($0, RSTART, RLENGTH)
}
print prefix version suffix
found = 1
next
}
{ print }'
cat "$tmpfile" >"$pom"
ac_clean "$tmpfile"
}
function pver() {
local DEFAULT_FILE=VERSION.txt
local DEFAULT_POM=pom.xml
local -a args
local action=auto
@@ -109,6 +149,7 @@ function pver() {
parse_opts "${PRETTYOPTS[@]}" \
--help '$exit_with pver_display_help' \
-f:,--file: '$set@ file; source=file' \
-e:,--maven:,--pom: '$set@ file; source=pom' \
-F:,--file-string: '$set@ file; source=file-string' \
-g:,--git-string: '$set@ git; source=git-string' \
-s:,--string: '$set@ version; source=string' \
@@ -140,21 +181,38 @@ function pver() {
# Calculer la source
if [ "$source" == auto ]; then
source=file
for i in "$DEFAULT_FILE" version.txt; do
for i in "$DEFAULT_FILE" version.txt "$DEFAULT_POM"; do
if [ -f "$i" ]; then
file="$i"
break
case "$i" in
"$DEFAULT_POM")
source=pom
file="$i"
break
;;
*)
source=file
file="$i"
break
;;
esac
fi
done
elif [ "$source" == file ]; then
[ "$action" == auto ] && action=update
fi
[ "$source" == file -a -z "$file" ] && file="$DEFAULT_FILE"
[ "$source" == pom -a -z "$file" ] && file="$DEFAULT_POM"
[ "$action" == auto ] && action=show
# Lire la version
if [ "$source" == file ]; then
[ -f "$file" ] && version="$(<"$file")"
elif [ "$source" == pom ]; then
[ -f "$file" ] || {
eerror "$file: fichier introuvable"
return 1
}
version="$(__pom_get_version "$file")"
elif [ "$source" == file-string ]; then
if [ -z "$file" ]; then
file="$DEFAULT_FILE"
@@ -319,6 +377,9 @@ BEGIN {
if isatty; then
estepi "La version actuelle est $version"
fi
elif [ "$source" == pom ]; then
eerror "$file: fichier introuvable"
return 1
else
if isatty; then
ask_yesno "Le fichier $(ppath "$file") n'existe pas. Faut-il le créer?" O || return 1
@@ -399,7 +460,10 @@ BEGIN {
# afficher le résultat final
psemver_setvar version
if [ -n "$file" ]; then
echo "$version" >"$file"
case "$source" in
file) echo "$version" >"$file";;
pom) __pom_set_version "$file" "$version";;
esac
fi
if isatty; then
estepn "La nouvelle version est $version"