Blob Blame Raw
From 6886cb1f4c0b70d83eb19c706701f83643cfd5ba Mon Sep 17 00:00:00 2001
From: Michal Srb <msrb@redhat.com>
Date: Wed, 14 Jan 2015 10:07:49 +0100
Subject: [PATCH 2/3] Replace all dashes with dots in versioned provides and
 requires

e.g.:
mvn(org.codehaus.plexus:plexus-interactivity-api) = 1.0-alpha-6
will become:
mvn(org.codehaus.plexus:plexus-interactivity-api) = 1.0.alpha.6

This should prevent triggering of following error:
Error: Package: plexus-interactivity-jline-1.0-0.14.alpha6.10.fc22.noarch
    Requires: mvn(org.codehaus.plexus:plexus-interactivity-api) = 1.0-alpha-6
    Removing: plexus-interactivity-api-1.0-0.14.alpha6.9.fc22.noarch
        mvn(org.codehaus.plexus:plexus-interactivity-api) = 1.0-alpha-6
    Updated By: plexus-interactivity-api-1.0-0.14.alpha6.10.fc22.noarch
        mvn(org.codehaus.plexus:plexus-interactivity-api) = 1.0-alpha-6
---
 python/javapackages/common/osgi.py   | 30 +++++++++++++++++++-----------
 python/javapackages/common/util.py   |  4 ++++
 python/javapackages/maven/printer.py |  3 +++
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/python/javapackages/common/osgi.py b/python/javapackages/common/osgi.py
index 832ae72..35c4f34 100644
--- a/python/javapackages/common/osgi.py
+++ b/python/javapackages/common/osgi.py
@@ -35,6 +35,21 @@
 import re
 
 from javapackages.common.manifest import Manifest
+from javapackages.common.util import sanitize_version
+
+
+class OSGiUtils(object):
+
+    @staticmethod
+    def get_rpm_str(bundle, version="", namespace=""):
+        ns = namespace
+        if version:
+            version = sanitize_version(version)
+        return "{ns}{d}osgi({bundle}){eq}{version}".format(ns=ns,
+                                                           d="-" if ns else "",
+                                                           bundle=bundle,
+                                                           eq=" = " if version else "",
+                                                           version=version)
 
 
 class OSGiRequire(object):
@@ -75,13 +90,7 @@ class OSGiRequire(object):
 
     def get_rpm_str(self, version="", namespace=""):
         ns = namespace or self.namespace
-        verstr = ""
-        if version:
-            verstr = " = {ver}".format(ver=version)
-        return "{ns}{d}osgi({bundle}){verstr}".format(ns=ns,
-                                                      d="-" if ns else "",
-                                                      bundle=self.bundle,
-                                                      verstr=verstr)
+        return OSGiUtils.get_rpm_str(self.bundle, version=version, namespace=ns)
 
 
 class OSGiBundle(object):
@@ -166,7 +175,6 @@ class OSGiBundle(object):
         return not self.__eq__(other)
 
     def get_rpm_str(self, version="", namespace=""):
-        return "{ns}{d}osgi({bundle}) = {version}".format(ns=namespace or self.namespace,
-                                                          d="-" if self.namespace else "",
-                                                          bundle=self.bundle,
-                                                          version=version or self.version)
+        ver = version or self.version
+        ns = namespace or self.namespace
+        return OSGiUtils.get_rpm_str(self.bundle, version=ver, namespace=ns)
diff --git a/python/javapackages/common/util.py b/python/javapackages/common/util.py
index f893cc4..e373984 100644
--- a/python/javapackages/common/util.py
+++ b/python/javapackages/common/util.py
@@ -128,3 +128,7 @@ def get_logger(name):
     handler.setFormatter(formatter)
     logger.addHandler(handler)
     return logger
+
+
+def sanitize_version(version):
+    return version.replace("-", ".")
diff --git a/python/javapackages/maven/printer.py b/python/javapackages/maven/printer.py
index 095da99..4933bfc 100644
--- a/python/javapackages/maven/printer.py
+++ b/python/javapackages/maven/printer.py
@@ -31,6 +31,8 @@
 #
 # Authors:  Michal Srb <msrb@redhat.com>
 
+from javapackages.common.util import sanitize_version
+
 class Printer(object):
     @staticmethod
     def get_mvn_str(gid, aid, ext="", cla="", ver=""):
@@ -66,6 +68,7 @@ class Printer(object):
             rpmstr = "{ns}-{rpmstr}".format(ns=namespace, rpmstr=rpmstr)
 
         if pkgver is not None:
+            pkgver = sanitize_version(pkgver)
             rpmstr = "{rpmstr} = {ver}".format(rpmstr=rpmstr, ver=pkgver)
 
         return rpmstr
-- 
2.1.0