Blob Blame Raw
From 52525455278ad5801cf89a768b81499229af1f68 Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Thu, 29 May 2014 13:45:52 +0200
Subject: [PATCH 10/10] [maven.req] When generating req from POM file, do not
 blindly take first POM file, but iterate over all of them and pick the right
 one

---
 depgenerators/maven.req | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/depgenerators/maven.req b/depgenerators/maven.req
index aea1dd4..dea89d7 100755
--- a/depgenerators/maven.req
+++ b/depgenerators/maven.req
@@ -137,7 +137,9 @@ class TagBuilder(object):
 
         if os.path.exists(XMVN_RESOLVE_PATH):
             if is_it_pom_only_pkg(paths[0]):
-                self.__generate_requires_from_pom(ppaths[0])
+                poms = self.__find_poms_for_metadata(ppaths, paths[0])
+                for p in poms:
+                    self.__generate_requires_from_pom(p)
 
         for path in paths:
             if path.endswith(".pom"):
@@ -154,8 +156,23 @@ class TagBuilder(object):
         return None
 
 
-    def __generate_requires_from_pom(self, pomfile):
-        pom = POM(pomfile)
+    # TODO: move functions like this to some POMUtils, or similar module
+    def __find_poms_for_metadata(self, pom_paths, metadata_path):
+        poms = []
+        depmap = Depmap([metadata_path])
+        provided = depmap.get_provided_artifacts()
+        for prov in provided:
+            for p in pom_paths:
+                pom = POM(p)
+                if (pom.groupId == prov.groupId and
+                    pom.artifactId == prov.artifactId and
+                    pom.version == prov.version):
+
+                    poms.append(pom)
+                    break
+        return poms
+
+    def __generate_requires_from_pom(self, pom):
         plugins = pom.get_plugins()
         extensions = pom.get_extensions()
         pgid = pom.parentGroupId
-- 
1.9.3