commit a92512ca45aaffcded52e4ac759a7766d0edd0d6
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Tue Jul 1 07:50:19 2014 +0200
Finish the pom_xpath_disable macro implementation
java-utils/pom_editor.py | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/java-utils/pom_editor.py b/java-utils/pom_editor.py
index f7e6253..b717052 100644
--- a/java-utils/pom_editor.py
+++ b/java-utils/pom_editor.py
@@ -280,7 +280,7 @@ class XmlFile(object):
.format(query))
return query_result[0]
- def xpath_query(self, query):
+ def xpath_query(self, query, check_result=True):
if not query.startswith('/'):
query = '//' + query
try:
@@ -293,7 +293,7 @@ class XmlFile(object):
except etree.XPathEvalError as error:
raise PomQueryInvalid("XPath query '{0}': {1}.".format(query,
error.message))
- if len(query_result) == 0:
+ if check_result and len(query_result) == 0:
raise PomQueryNoMatch(dedent("""\
XPath query '{0}' didn't match any node.
(Did you forget to specify 'pom:' namespace?)""").format(query))
@@ -465,17 +465,20 @@ def pom_xpath_set(where, content, pom=None):
@macro(types=(Pom,))
def pom_xpath_disable(when, pom=None):
"""<XPath> [POM location]"""
- def disable_recursive(xml, xmlpath):
- if xml.xpath(when):
+ to_disable = []
+ def disable_recursive(pom):
+ if pom.xpath_query(when, check_result=False):
return True
- for submodule, submod_path in zip(*submodule_info(xml, xmlpath)):
+ for submodule, submod_path in zip(*submodule_info(pom.root, pom.xmlpath)):
realpath = find_xml(submod_path)
- subxml = etree.parse(realpath)
- if disable_recursive(subxml, realpath):
- pom_disable_module(submodule, pom=realpath)
+ subpom = Pom(realpath)
+ if disable_recursive(subpom):
+ to_disable.append((pom.xmlpath, submodule))
- if disable_recursive(pom.root, pom.xmlpath):
+ if disable_recursive(pom):
raise PomException("Main POM satisfies the condition")
+ for pompath, module in to_disable:
+ pom_disable_module(module, pompath)
@macro(types=(Pom, Ivy))
def pom_remove_dep(dep, pom=None):