commit e2195a59c6b8b109e53d26cf59624e4c00ceb699
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Thu Feb 6 14:11:32 2014 +0100
[pom_editor] don't follow module nodes where arbitrary content is
allowed
java-utils/pom_editor.py | 4 ++-
.../example_parent_plugin_with_module.xml | 28 ++++++++++++++++++++
test/pom_editor_paths_test.py | 9 ++++++
3 files changed, 40 insertions(+), 1 deletions(-)
---
diff --git a/java-utils/pom_editor.py b/java-utils/pom_editor.py
index 57dd8a7..fd43cc8 100644
--- a/java-utils/pom_editor.py
+++ b/java-utils/pom_editor.py
@@ -93,13 +93,15 @@ def find_pom(pompath):
def find_poms_recursive(pomspec):
modules = [find_pom(pomspec)]
found = set(modules)
+ module_xpath = '/pom:project/pom:modules/pom:module |\
+ /pom:project/pom:profile/pom:modules/pom:module'
try:
while modules:
pompath = find_pom(modules.pop())
found.add(pompath)
pom_xml = etree.parse(pompath)
modules += [path.join(path.dirname(pompath), node.text.strip())
- for node in pom_xml.xpath('//pom:modules/pom:module',
+ for node in pom_xml.xpath(module_xpath,
namespaces=Pom.NSMAP)]
return found
diff --git a/test/data/pom_editor/example_parent_plugin_with_module.xml
b/test/data/pom_editor/example_parent_plugin_with_module.xml
new file mode 100644
index 0000000..8fd2c0d
--- /dev/null
+++ b/test/data/pom_editor/example_parent_plugin_with_module.xml
@@ -0,0 +1,28 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-parent</artifactId>
+ <version>17</version>
+ </parent>
+ <modules>
+ <module>intermediate</module>
+ </modules>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.example</groupId>
+ <artifactId>parent</artifactId>
+ <version>2.6</version>
+ <name>Example parent</name>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>4.0</version>
+ <configuration>
+ <module>common</module>
+ </configuration>
+ </plugin>
+ </plugins>
+
+
+</project>
diff --git a/test/pom_editor_paths_test.py b/test/pom_editor_paths_test.py
index db6188d..e699727 100644
--- a/test/pom_editor_paths_test.py
+++ b/test/pom_editor_paths_test.py
@@ -125,6 +125,15 @@ class TestRecursive(WorkdirTestCase):
self.assertEqual(0, return_value, stderr)
self.assertEqual('', report, report)
+ def test_recursive_plugin_with_module(self):
+ poms_tree = dict(self.example_tree)
+ poms_tree[''] = 'example_parent_plugin_with_module.xml'
+ return_value, stderr, report = exec_pom_macro('%pom_remove_dep -r
:junit',
+ poms_tree=poms_tree,
+ want_tree={'intermediate/schemas':
'example_schemas_removed_junit.xml'})
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
def test_default_recursive_profile(self):
poms_tree = dict(self.example_tree)
poms_tree[''] = 'example_parent_profile.xml'