Permalink
Browse files

Better version stripper

  • Loading branch information...
1 parent bce4f7c commit 61fb41095e2cac0806d42df87beba64b447f3696 @digulla committed Jun 8, 2011
Showing with 47 additions and 14 deletions.
  1. +24 −14 src/m4e/patches.py
  2. +23 −0 test/test-apply-patches.py
View
38 src/m4e/patches.py
@@ -213,23 +213,33 @@ def __repr__(self):
class StripQualifiers(object):
'''Strip Eclipse qualifiers from versions'''
def __init__(self):
- versionGroup = r'(\d+\.\d+\.\d+)'
- qualifier = r'(\.[^,]+)'
- self.versionPattern = re.compile('^%s%s?$' % (versionGroup, qualifier))
- self.versionRangePattern = re.compile('^([\[\]()])%s%s?,%s%s?([\[\]()])$' % (versionGroup, qualifier, versionGroup, qualifier))
+ self.versionRangePattern = re.compile('^([\[\]()])([^,]*),([^,]*)([\[\]()])$')
def run(self, pom):
for d in pom.dependencies():
- m = self.versionRangePattern.match(d.version)
- if m is None:
- m = self.versionPattern.match(d.version)
-
- if m is None:
- log.warn('Odd version %s in POM %s' % (d.version, pom.pomFile))
- else:
- d.version = m.group(1)
- else:
- d.version = '%s%s,%s%s' % (m.group(1), m.group(2), m.group(4), m.group(6))
+ d.version = self.stripQualifier(d.version)
+
+ def stripQualifier(self, version):
+ m = self.versionRangePattern.match(version)
+ if m is None:
+ return self.stripQualifier2(version)
+
+ prefix = m.group(1)
+ v1 = m.group(2)
+ v2 = m.group(3)
+ postfix = m.group(4)
+
+ v1 = self.stripQualifier2(v1)
+ v2 = self.stripQualifier2(v2)
+
+ return '%s%s,%s%s' % (prefix, v1, v2, postfix)
+
+ def stripQualifier2(self, version):
+ if not version:
+ return version
+
+ parts = version.split('.')
+ return '.'.join(parts[0:3])
def __repr__(self):
return 'StripQualifiers()'
View
23 test/test-apply-patches.py
@@ -245,3 +245,26 @@ def test_stripQualifier():
compareStrings(expected, repr(pom))
+def test_stripQualifier2():
+ compareStrings('1', StripQualifiers().stripQualifier('1'))
+
+def test_stripQualifier3():
+ compareStrings('1.0', StripQualifiers().stripQualifier('1.0'))
+
+def test_stripQualifier4():
+ compareStrings('1.3.2', StripQualifiers().stripQualifier('1.3.2'))
+
+def test_stripQualifier5():
+ compareStrings('', StripQualifiers().stripQualifier(''))
+
+def test_stripQualifier6():
+ compareStrings('[2.5.0,3.0.0)', StripQualifiers().stripQualifier('[2.5.0.v200906151043,3.0.0)'))
+
+def test_stripQualifier7():
+ compareStrings('[0,)', StripQualifiers().stripQualifier('[0,)'))
+
+def test_stripQualifier8():
+ compareStrings('[2.6.2,3.0)', StripQualifiers().stripQualifier('[2.6.2,3.0)'))
+
+def test_stripQualifier8():
+ compareStrings('[3.6.1,4)', StripQualifiers().stripQualifier('[3.6.1,4)'))

0 comments on commit 61fb410

Please sign in to comment.