[jpackage-utils/f17] Backport macros for pom file modificaiton
Stanislav Ochotnicky
sochotni at fedoraproject.org
Mon Jul 9 14:26:34 UTC 2012
commit 9e425dc689c8fc5492a5cca2da7c694dae856983
Author: Stanislav Ochotnicky <sochotnicky at redhat.com>
Date: Mon Jul 9 16:03:00 2012 +0200
Backport macros for pom file modificaiton
- Fix build-classpath ignoring symlinks in subdirs
0003-Add-POM-macros-to-macros.fjava.patch | 373 ++++++++++++++++++++++
jpackage-utils-build-classpath-symlink-fix.patch | 13 +
jpackage-utils.spec | 12 +-
3 files changed, 397 insertions(+), 1 deletions(-)
---
diff --git a/0003-Add-POM-macros-to-macros.fjava.patch b/0003-Add-POM-macros-to-macros.fjava.patch
new file mode 100644
index 0000000..f8fbf0d
--- /dev/null
+++ b/0003-Add-POM-macros-to-macros.fjava.patch
@@ -0,0 +1,373 @@
+From 2c2c470c6e306ede93702c4f1417e562e2e383ad Mon Sep 17 00:00:00 2001
+From: Stanislav Ochotnicky <sochotnicky at redhat.com>
+Date: Mon, 9 Jul 2012 15:57:45 +0200
+Subject: [PATCH 3/3] Add POM macros to macros.fjava
+
+---
+ macros.fjava | 116 +++++++++++++++++++++++++-
+ scripts/pom_editor.sh | 222 +++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 337 insertions(+), 1 deletion(-)
+ create mode 100644 scripts/pom_editor.sh
+
+diff --git a/macros.fjava b/macros.fjava
+index 9d52d92..a00a572 100644
+--- a/macros.fjava
++++ b/macros.fjava
+@@ -26,7 +26,7 @@
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ #
+ # Authors: Stanislav Ochotnicky <sochotnicky at redhat.com>
+-# [your name here]
++# Mikolaj Izdebski <mizdebsk at redhat.com>
+
+
+ #==============================================================================
+@@ -75,3 +75,117 @@ python -m %{_datadir}/java-utils/maven_depmap %{-a} \\\
+
+
+
++#==============================================================================
++#
++# %pom_* -- macros for batch editing of POM files
++#
++# These macros can be used to edit Maven POM files directly from RPM spec
++# file. Using these macros it is possible to alter Maven dependency management,
++# change plugin invocation, or even inject or remove arbitrary XML code to/from
++# nodes described by an XPath expression.
++#
++# See comments preceding individual macros for more detailed documentation.
++#
++
++# Private macro, shouldn't be used directly
++%__pom_call . %{_datadir}/java-utils/pom_editor.sh; pom_
++
++
++# %pom_remove_dep - remove dependency on Maven artifact from POM file
++#
++# Usage: %pom_remove_dep [groupId]:[artifactId] [POM location]
++#
++# This macro patches specified POM file not to contain dependencies on given
++# Maven artifact.
++#
++# groupId and artifactId are identifiers of Maven group and artifact of the
++# module on which dependency is to be removed. If they are ommited then all
++# identifiers are matched.
++#
++# 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.
++#
++%pom_remove_dep() %{expand: %{__pom_call}remove_dep %*
++}
++
++
++# %pom_remove_plugin - remove Maven plugin invocation from POM file
++#
++# Usage: %pom_remove_plugin [groupId]:[artifactId] [POM location]
++#
++# This macro patches specified POM file not to contain invocations of given
++# Maven plugin.
++#
++# groupId and artifactId are identifiers of Maven group and artifact of the
++# plugin which invocation is to be removed. If they are ommited then all
++# identifiers are matched.
++#
++# 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.
++#
++%pom_remove_plugin() %{expand: %{__pom_call}remove_plugin %*
++}
++
++
++# %pom_disable_module - disable given project module in POM file
++#
++# Usage: %pom_disable_module <module name> [POM location]
++#
++# This macro patches specified POM file not to contain reference to given
++# project module.
++#
++# Module name is the exact name of the module to be disabled. It must not be
++# ommited.
++#
++# 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.
++#
++%pom_disable_module() %{expand: %{__pom_call}disable_module %*
++}
++
++
++# %pom_xpath_remove - remove an XML node from POM file
++#
++# Usage: %pom_xpath_remove <XPath> [POM location]
++#
++# This macro patches specified POM file removing all XML nodes described by the
++# XPath expression.
++#
++# XPath is an expression describing a set of XML nodes to be removed from the
++# POM file. It must be a properly formated XPath 1.0 expression, as described
++# in <http://www.w3.org/TR/xpath/>.
++#
++# 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: POM files use a specific namespace - http://maven.apache.org/POM/4.0.0.
++# The easiest way to respect this namespace in XPath expressions is prefixing
++# all node names with "pom:". For example, "pom:environment/pom:os" will work
++# because it selects nodes from pom namespace, but "environment/os" won't find
++# anything because it looks for nodes that don't belong to any XML namespace.
++#
++%pom_xpath_remove() %{expand: %{__pom_call}xpath_remove %*
++}
++
++
++# %pom_xpath_inject - inject XML code into POM file
++#
++# Usage: %pom_xpath_inject <XPath> [XML code] [POM location]
++#
++# This macro patches specified POM file appending some code as childreen of all
++# XML nodes described by the XPath expression.
++#
++# XPath is an expression describing a set of XML nodes in the POM file to which
++# child code is to be appended. It must be a properly formated XPath 1.0
++# expression, as described in <http://www.w3.org/TR/xpath/>.
++#
++# 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.
++#
++%pom_xpath_inject() %{expand: %{__pom_call}xpath_inject %*
++}
+diff --git a/scripts/pom_editor.sh b/scripts/pom_editor.sh
+new file mode 100644
+index 0000000..1725a76
+--- /dev/null
++++ b/scripts/pom_editor.sh
+@@ -0,0 +1,222 @@
++#!/bin/bash -e
++# Copyright (c) 2012, Red Hat, Inc
++# All rights reserved.
++#
++# Redistribution and use in source and binary forms, with or without
++# modification, are permitted provided that the following conditions
++# are met:
++#
++# 1. Redistributions of source code must retain the above copyright
++# notice, this list of conditions and the following disclaimer.
++# 2. Redistributions in binary form must reproduce the above copyright
++# notice, this list of conditions and the following disclaimer in the
++# documentation and/or other materials provided with the
++# distribution.
++# 3. Neither the name of Red Hat nor the names of its
++# contributors may be used to endorse or promote products derived
++# from this software without specific prior written permission.
++#
++# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
++# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
++# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
++# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
++# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
++# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
++# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
++# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
++# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
++#
++# Authors: Mikolaj Izdebski <mizdebsk at redhat.com>
++
++
++_pom_initialize()
++{
++ _pom_xslt_header='<?xml version="1.0" encoding="UTF-8"?>
++<xsl:stylesheet version="1.0"
++ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
++ xmlns="http://maven.apache.org/POM/4.0.0"
++ xmlns:pom="http://maven.apache.org/POM/4.0.0">
++ <xsl:output method="xml"
++ version="1.0"
++ encoding="UTF-8"
++ omit-xml-declaration="yes"/>
++'
++
++ _pom_xslt_trailer='<xsl:template match="@*|node()">
++ <xsl:copy>
++ <xsl:apply-templates select="@*|node()"/>
++ </xsl:copy>
++ </xsl:template>
++</xsl:stylesheet>
++'
++}
++
++
++# Print an error message followed by backtrace and exit.
++_pom_bailout()
++{
++ echo "${@}" >&2
++ echo "=== Backtrace: ===" >&2
++ i=0
++ while caller $i >&2
++ do
++ i=$((i+1))
++ done
++ exit 1
++}
++
++
++# Find POM using pattern $1 and patch it using XSLT patch coming
++# from stdin. Bailout if the patch cannot be applied.
++_pom_patch()
++{
++ # First try find the location of the POM file.
++ local pom="${1}"
++ if ! test -f "${pom}"; then
++ pom=./"${1}"/pom.xml
++ test -f "${pom}" || _pom_bailout Failed to locate POM file using pattern "'${1}'"
++ fi
++
++ # Create a backup file -- pom.xml.orig.
++ test -f "${pom}".orig || cp "${pom}"{,.orig}
++
++ # Apply identity transformation.
++ xsltproc --nonet - "${pom}" >"${pom}".tmp <<<"${_pom_xslt_header}${_pom_xslt_trailer}"
++
++ # Try to apply the patch.
++ xsltproc --nonet - "${pom}".tmp >"${pom}"
++
++ # Bail out if the resulting file is identical to the patched one.
++ # This is to help maintainers detect unneeded patches.
++ cmp -s "${pom}"{,.tmp} && _pom_bailout Operation on POM has no effect.
++ rm -f "${pom}".tmp
++}
++
++
++# Replace a particular node with a comment.
++# $1 - POM location pattern
++# $2 - XPath of the element to replace
++# $3 - comment to replace the element with
++_pom_disable_xpath()
++{
++ _pom_patch "${1}" <<EOF
++${_pom_xslt_header}
++ <xsl:template match="${2}">
++ <xsl:comment>
++ <xsl:text> ${3} </xsl:text>
++ </xsl:comment>
++ </xsl:template>
++${_pom_xslt_trailer}
++EOF
++}
++
++
++# Inject some code into a POM file.
++# The code is put as a child of element specified by XPath.
++# $1 - POM location pattern
++# $2 - XPath of the parent element
++# $3 - code to inject
++_pom_inject_xpath()
++{
++ _pom_patch "${1}" <<EOF
++${_pom_xslt_header}
++ <xsl:template match="${2}">
++ <xsl:copy>
++ <xsl:apply-templates select="@*"/>
++<xsl:text>
++
++</xsl:text>
++ <xsl:comment>
++ <xsl:text> begin of code added by maintainer </xsl:text>
++ </xsl:comment>
++<xsl:text>
++</xsl:text>
++${3}
++<xsl:text>
++</xsl:text>
++ <xsl:comment>
++ <xsl:text> end of code added by maintainer </xsl:text>
++ </xsl:comment>
++<xsl:text>
++</xsl:text>
++ <xsl:apply-templates select="node()"/>
++ </xsl:copy>
++ </xsl:template>
++${_pom_xslt_trailer}
++EOF
++}
++
++
++# Replace by a comment any XML node that has childreen nodes
++# groupId and artifactId with given contents.
++# $1 - XPath of parent node
++# $2 - groupId:artifactId
++# $3 - POM location pattern
++_pom_disable_gaid()
++{
++ local what=$(sed 's/[^ ]*://' <<<"${1}")
++ local gid=$(sed -e 's/:[^:]*//' -e "s/..*/[text()='&']/" <<<"${2}")
++ local aid=$(sed -e 's/[^:]*://' -e "s/..*/[text()='&']/" <<<"${2}")
++
++ # TODO: support cases with no groupId specified
++ _pom_patch "${3}" <<EOF
++${_pom_xslt_header}
++ <xsl:template match="//${1} [pom:groupId${gid} and pom:artifactId${aid}]">
++ <xsl:comment>
++ <xsl:text> ${what} disabled by maintainer: </xsl:text>
++ <xsl:apply-templates select="pom:groupId"/>
++ <xsl:text>:</xsl:text>
++ <xsl:apply-templates select="pom:artifactId"/>
++ <xsl:text> </xsl:text>
++ </xsl:comment>
++ </xsl:template>
++${_pom_xslt_trailer}
++EOF
++}
++
++
++pom_remove_dep()
++{
++ set +x
++ _pom_initialize
++ _pom_disable_gaid pom:dependencies/pom:dependency "${@}"
++ set -x
++}
++
++
++pom_remove_plugin()
++{
++ set +x
++ _pom_initialize
++ _pom_disable_gaid pom:plugins/pom:plugin "${@}"
++ set -x
++}
++
++
++pom_disable_module()
++{
++ set +x
++ _pom_initialize
++ _pom_disable_xpath "${2}" "//pom:modules/pom:module [text()='${1}']" "module disabled by maintainer: ${1}"
++ set -x
++}
++
++
++pom_xpath_remove()
++{
++ set +x
++ _pom_initialize
++ _pom_disable_xpath "${2}" "${1}" "element removed by maintainer: ${1}"
++ set -x
++}
++
++
++pom_xpath_inject()
++{
++ set +x
++ _pom_initialize
++ _pom_inject_xpath "${3}" "${1}" "${2}"
++ set -x
++}
+--
+1.7.10.4
+
diff --git a/jpackage-utils-build-classpath-symlink-fix.patch b/jpackage-utils-build-classpath-symlink-fix.patch
new file mode 100644
index 0000000..99e509a
--- /dev/null
+++ b/jpackage-utils-build-classpath-symlink-fix.patch
@@ -0,0 +1,13 @@
+diff --git a/bin/build-classpath b/bin/build-classpath
+index 56fc8ae..245c3ba 100755
+--- a/bin/build-classpath
++++ b/bin/build-classpath
+@@ -39,7 +39,7 @@ for extension in "$@" ; do
+ # well take everything in the directory
+ # This may create duplicates if symlinks point back inside the
+ # directory structure, but who cares
+- _JARS=$(find "$extension" -follow -name "*.jar" -xtype f -printf %p: 2>/dev/null)
++ _JARS=$(find "$extension" -follow -name "*.jar" -type f -printf %p: 2>/dev/null)
+ else
+ _JARS=$extension:
+ fi
diff --git a/jpackage-utils.spec b/jpackage-utils.spec
index 6388b1e..ff6911b 100644
--- a/jpackage-utils.spec
+++ b/jpackage-utils.spec
@@ -38,7 +38,7 @@
Name: jpackage-utils
Version: 1.7.5
-Release: 18%{?dist}
+Release: 18.1%{?dist}
Epoch: 0
Summary: JPackage utilities
License: BSD
@@ -55,10 +55,13 @@ Patch3: %{name}-set-classpath.patch
Patch4: %{name}-jnidir.patch
Patch5: 0001-Generate-maven-provides-from-fragments-instead-of-po.patch
Patch6: 0002-Add-default-parameters-for-add_maven_depmap.patch
+Patch7: 0003-Add-POM-macros-to-macros.fjava.patch
+Patch8: %{name}-build-classpath-symlink-fix.patch
Group: Utilities
Requires: coreutils
Requires: python
+Requires: libxslt
# for noarch->arch change
Obsoletes: %{name} < 0:1.7.5-9
@@ -77,6 +80,7 @@ information.
%patch2 -p1
%patch3 -p1
%patch4 -p1
+%patch8 -p1
cp -p %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE8} .
@@ -84,6 +88,7 @@ tar xf javapackages-%{fj_version}.tar.xz
cd javapackages-%{fj_version}
%patch5 -p1
%patch6 -p1
+%patch7 -p1
%build
echo "JPackage release %{distver} (%{distribution}) for %{buildarch}" \
@@ -200,6 +205,7 @@ install -m0644 -D depgenerators/fileattrs/osgi.attr \
install -pm 644 macros.fjava ${RPM_BUILD_ROOT}%{_sysconfdir}/rpm
install -pm 644 scripts/maven_depmap.py ${RPM_BUILD_ROOT}${_javadir}-utils
+install -pm 644 scripts/pom_editor.sh $RPM_BUILD_ROOT%{_javadir}-utils/
popd
cat <<EOF > %{name}-%{version}.files
@@ -244,6 +250,10 @@ EOF
%changelog
+* Mon Jul 09 2012 Stanislav Ochotnicky <sochotnicky at redhat.com> - 0:1.7.5-18.1
+- Backport macros for pom file modificaiton
+- Fix build-classpath ignoring symlinks in subdirs
+
* Thu Apr 19 2012 Stanislav Ochotnicky <sochotnicky at redhat.com> - 0:1.7.5-18
- Backport addition of default arguments to add_maven_depmap
More information about the scm-commits
mailing list