commit 343412e668d97dbe81fdae3655f982aa969b6b17 Author: Mikolaj Izdebski mizdebsk@redhat.com Date: Mon Jul 30 13:44:42 2012 +0200
Implement %pom_add_parent
macros.fjava | 24 ++++++++++++++++++++++++ scripts/pom_editor.sh | 18 +++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) --- diff --git a/macros.fjava b/macros.fjava index 9da36fa..2deef6b 100644 --- a/macros.fjava +++ b/macros.fjava @@ -272,3 +272,27 @@ fi \ # %pom_xpath_inject() %{expand: %{__pom_call}xpath_inject %* } + + +# %pom_add_parent - add parent POM reference to POM file +# +# Usage: %pom_add_parent groupId:artifactId[:version] [POM location] +# +# This macro patches specified POM file adding a reference to parent POM with +# specified groupId, artifactId and version. +# +# groupId and artifactId are identifiers of Maven group and artifact of the POM +# to be referenced as parent POM. They must be specified. If version is not +# specified then default value of "any" is used. +# +# POM location can be either a full path to the POM file, or a path to the +# directory containing pom.xml. If POM location is not given then pom.xml from +# current working directory is used. +# +# Note: If specified POM has already a reference to parent POM this macro will +# not alter or remove it. Instead a second reference will be added. This is +# usually not the expected behavior, so if you want to replace existing parent +# POM reference, consider using %pom_set_parent macro instead. +# +%pom_add_parent() %{expand: %{__pom_call}add_parent %* +} diff --git a/scripts/pom_editor.sh b/scripts/pom_editor.sh index 219e4c2..891731a 100644 --- a/scripts/pom_editor.sh +++ b/scripts/pom_editor.sh @@ -202,12 +202,11 @@ _pom_inject_gaid() BEGIN { FS=":" }
{ - if (!$3) { $3="any" } - if (!$4) { $4="compile" } - print "<groupId>" $1 "</groupId>" + print "<groupId>" $1 "</groupId>" print "<artifactId>" $2 "</artifactId>" - print "<version>" $3 "</version>" - print "<scope>" $4 "</scope>" + if (!$3) { $3="any" } + print "<version>" $3 "</version>" + if ($4) { print "<scope>" $4 "</scope>" } }' <<<"${2}")
_pom_inject_xpath "${3}" "${1}" "<${4}> ${xml} ${5} </${4}>" @@ -257,3 +256,12 @@ pom_xpath_inject() _pom_inject_xpath "${3}" "${1}" "${2}" set -x } + + +pom_add_parent() +{ + set +x + _pom_initialize + _pom_inject_gaid "pom:project" "${1}" "${2}" "parent" "${3}" + set -x +}
java-sig-commits@lists.fedoraproject.org