[javapackages/big-refactoring] [artifact] get_parts_from_mvn_str() is static method now
by Michal Srb
commit 05eed89473b36d9c2726152e025ee0e2613a9796
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 10:21:05 2014 +0200
[artifact] get_parts_from_mvn_str() is static method now
python/javapackages/pom/artifact.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index 77d9f11..f1e94a5 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -28,7 +28,8 @@ class AbstractArtifact(object):
m['version'], namespace=namespace,
compat=compat, pkgver=pkgver)
- def get_parts_from_mvn_str(self, mvnstr):
+ @staticmethod
+ def get_parts_from_mvn_str(mvnstr):
tup = mvnstr.split(":")
# groupId and artifactId are always present
9 years, 10 months
[javapackages/big-refactoring] [artifact] Move get_xml_str() and get_xml_element() to AbstractArtifact
by Michal Srb
commit 4cdbd7b6a8505c6ee16ae3850b19ac8a8d224b34
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 10:18:39 2014 +0200
[artifact] Move get_xml_str() and get_xml_element() to AbstractArtifact
python/javapackages/pom/artifact.py | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index 914ff8a..77d9f11 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -56,6 +56,27 @@ class AbstractArtifact(object):
return parts
+ def get_xml_element(self, root="abstractArtifact"):
+ """
+ Return XML Element node representation of the Artifact
+ """
+ root = Element(root)
+
+ members = self.__get_members()
+
+ for key in members:
+ if members[key]:
+ item = SubElement(root, key)
+ item.text = members[key]
+ return root
+
+ def get_xml_str(self, root="abstractArtifact"):
+ """
+ Return XML formatted string representation of the Artifact
+ """
+ root = self.get_xml_element(root)
+ return tostring(root, pretty_print=True)
+
def __get_members(self):
m = {'groupId': '',
'artifactId': '',
@@ -100,21 +121,13 @@ class Artifact(AbstractArtifact):
"""
Return XML Element node representation of the Artifact
"""
- root = Element(root)
-
- for key in ("artifactId", "groupId", "extension", "version",
- "classifier"):
- if hasattr(self, key) and getattr(self, key):
- item = SubElement(root, key)
- item.text = getattr(self, key)
- return root
+ return AbstractArtifact.get_xml_element(self, root)
def get_xml_str(self, root="artifact"):
"""
Return XML formatted string representation of the Artifact
"""
- root = self.get_xml_element(root)
- return tostring(root, pretty_print=True)
+ return AbstractArtifact.get_xml_str(self, root)
def __eq__(self, other):
if type(other) is type(self):
@@ -178,6 +191,6 @@ class Artifact(AbstractArtifact):
Where last part is always considered to be version unless empty
"""
- p = cls.get_parts_from_mvn_str(mvnstr)
+ p = Artifact.get_parts_from_mvn_str(mvnstr)
return cls(p['groupId'], p['artifactId'], p['extension'],
p['classifier'], p['version'])
9 years, 10 months
[javapackages/big-refactoring] [exclusion] Initial impl
by Michal Srb
commit 6afc6272847a5a2b526ed2e370bd3fed20022245
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 09:57:11 2014 +0200
[exclusion] Initial impl
python/javapackages/pom/exclusion.py | 77 ++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/python/javapackages/pom/exclusion.py b/python/javapackages/pom/exclusion.py
new file mode 100644
index 0000000..2c237d7
--- /dev/null
+++ b/python/javapackages/pom/exclusion.py
@@ -0,0 +1,77 @@
+import sys
+
+from artifact import AbstractArtifact, ArtifactFormatException
+from pomreader import POMReader
+from lxml.etree import Element, SubElement, tostring
+
+
+class Exclusion(AbstractArtifact):
+
+ def __init__(self, groupId, artifactId):
+ self.groupId = groupId.strip()
+ self.artifactId = artifactId.strip()
+
+ def __unicode__(self):
+ return u"{gid}:{aid}".format(gid=self.groupId, aid=self.artifactId)
+
+ def __str__(self):
+ return unicode(self).encode(sys.getfilesystemencoding())
+
+ def get_xml_element(self, root="exclusion"):
+ """
+ Return XML Element node representation of the Exclusion
+ """
+ root = Element(root)
+
+ for key in ("artifactId", "groupId"):
+ if hasattr(self, key) and getattr(self, key):
+ item = SubElement(root, key)
+ item.text = getattr(self, key)
+ return root
+
+ def get_xml_str(self, root="exclusion"):
+ """
+ Return XML formatted string representation of the Exclusion
+ """
+ root = self.get_xml_element(root)
+ return tostring(root, pretty_print=True)
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __hash__(self):
+ return self.groupId.__hash__() + \
+ self.artifactId.__hash__()
+
+ @classmethod
+ def from_xml_element(cls, xmlnode):
+ """
+ Create Exclusion from xml.etree.ElementTree.Element as contained
+ within pom.xml.
+ """
+
+ parts = {'groupId': '', 'artifactId': ''}
+ parts = POMReader.find_parts(xmlnode, parts)
+
+ if not parts['groupId'] or not parts['artifactId']:
+ raise ArtifactFormatException(
+ "Empty groupId or artifactId encountered. "
+ "This is a bug, please report it!")
+
+ return cls(parts['groupId'], parts['artifactId'])
+
+ @classmethod
+ def from_mvn_str(cls, mvnstr):
+ """
+ Create Exclusion from Maven-style definition
+
+ The string should be in the format of:
+ groupId:artifactId
+ """
+ p = cls.get_parts_from_mvn_str(mvnstr)
+ return cls(p['groupId'], p['artifactId'])
9 years, 10 months
[javapackages/big-refactoring] [artifact] Remove Ivy code
by Michal Srb
commit e9281fc05419491e302b35a16a142a50e54ef71a
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 09:38:40 2014 +0200
[artifact] Remove Ivy code
Ivy specific code will be in separate module
python/javapackages/pom/artifact.py | 24 ++----------------------
1 files changed, 2 insertions(+), 22 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index 3cabd75..914ff8a 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -1,5 +1,6 @@
import sys
+from pomreader import POMReader
from printer import Printer
from lxml.etree import Element, SubElement, tostring
@@ -151,40 +152,19 @@ class Artifact(AbstractArtifact):
within pom.xml or a dependency map.
"""
- # TODO: find better way of handling pom/ivy/xyz differences
parts = {'groupId':'',
'artifactId':'',
'extension':'',
'classifier':'',
'version':''}
- ivyparts = {'org': '',
- 'name': '',
- 'revision': ''}
-
- for key in parts:
- node = xmlnode.find("./{*}" + key)
- if node is not None and node.text is not None:
- parts[key] = node.text.strip()
-
- if hasattr(xmlnode, "attrib"):
- attribs = xmlnode.attrib
- for key in ivyparts:
- try:
- ivyparts[key] = attribs[key]
- except KeyError:
- pass
-
- parts['groupId'] = parts['groupId'] or ivyparts['org']
- parts['artifactId'] = parts['artifactId'] or ivyparts['name']
- parts['version'] = parts['version'] or ivyparts['revision']
+ parts = POMReader.find_parts(xmlnode, parts)
if not parts['groupId'] or not parts['artifactId']:
raise ArtifactFormatException(
"Empty groupId or artifactId encountered. "
"This is a bug, please report it!")
-
return cls(parts['groupId'], parts['artifactId'], parts['extension'],
parts['classifier'], parts['version'])
9 years, 10 months
[javapackages/big-refactoring] Move most of the code for creating artifacts from coordinates to AbstractArtifact
by Michal Srb
commit b0d339fa0347f63e4d6b095254fe3cf8bbf686ce
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 09:33:45 2014 +0200
Move most of the code for creating artifacts from coordinates to AbstractArtifact
python/javapackages/pom/artifact.py | 52 +++++++++++++++++++-------------
python/javapackages/pom/dependency.py | 24 ++-------------
2 files changed, 34 insertions(+), 42 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index d8da712..3cabd75 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -27,6 +27,34 @@ class AbstractArtifact(object):
m['version'], namespace=namespace,
compat=compat, pkgver=pkgver)
+ def get_parts_from_mvn_str(self, mvnstr):
+ tup = mvnstr.split(":")
+
+ # groupId and artifactId are always present
+ if len(tup) < 2:
+ raise ArtifactFormatException("Artifact string '{mvnstr}' does not "
+ "contain ':' character. Can not parse"
+ .format(mvnstr=mvnstr))
+
+ if len(tup) > 5:
+ raise ArtifactFormatException("Artifact string '{mvnstr}' contains "
+ "too many colons. Can not parse"
+ .format(mvnstr=mvnstr))
+
+ parts = {'groupId': '',
+ 'artifactId': '',
+ 'extension': '',
+ 'classifier': '',
+ 'version': ''}
+
+ parts['groupId'] = tup[0]
+ parts['artifactId'] = tup[1]
+ parts['extension'] = tup[2] if len(tup) >= 4 else ""
+ parts['classifier'] = tup[3] if len(tup) >= 5 else ""
+ parts['version'] = tup[-1] if len(tup) >= 3 else ""
+
+ return parts
+
def __get_members(self):
m = {'groupId': '',
'artifactId': '',
@@ -170,24 +198,6 @@ class Artifact(AbstractArtifact):
Where last part is always considered to be version unless empty
"""
- tup = mvnstr.split(":")
-
- # groupId and artifactId are always present
- if len(tup) < 2:
- raise ArtifactFormatException("Artifact string '{mvnstr}' does not "
- "contain ':' character. Can not parse"
- .format(mvnstr=mvnstr))
-
- if len(tup) > 5:
- raise ArtifactFormatException("Artifact string '{mvnstr}' contains "
- "too many colons. Can not parse"
- .format(mvnstr=mvnstr))
-
- groupId = tup[0]
- artifactId = tup[1]
- extension = tup[2] if len(tup) >= 4 else ""
- classifier = tup[3] if len(tup) >= 5 else ""
- version = tup[-1] if len(tup) >= 3 else ""
-
- return cls(groupId, artifactId, extension,
- classifier, version)
+ p = cls.get_parts_from_mvn_str(mvnstr)
+ return cls(p['groupId'], p['artifactId'], p['extension'],
+ p['classifier'], p['version'])
diff --git a/python/javapackages/pom/dependency.py b/python/javapackages/pom/dependency.py
index 6b0d684..970036b 100644
--- a/python/javapackages/pom/dependency.py
+++ b/python/javapackages/pom/dependency.py
@@ -106,24 +106,6 @@ class Dependency(AbstractArtifact):
Where last part is always considered to be version unless empty
"""
- tup = mvnstr.split(":")
-
- # groupId and artifactId are always present
- if len(tup) < 2:
- raise ArtifactFormatException("Artifact string '{mvnstr}' does not "
- "contain ':' character. Can not parse"
- .format(mvnstr=mvnstr))
-
- if len(tup) > 5:
- raise ArtifactFormatException("Artifact string '{mvnstr}' contains "
- "too many colons. Can not parse"
- .format(mvnstr=mvnstr))
-
- groupId = tup[0]
- artifactId = tup[1]
- extension = tup[2] if len(tup) >= 4 else ""
- classifier = tup[3] if len(tup) >= 5 else ""
- version = tup[-1] if len(tup) >= 3 else ""
-
- return cls(groupId, artifactId, extension,
- classifier, version)
+ p = cls.get_parts_from_mvn_str(mvnstr)
+ return cls(p['groupId'], p['artifactId'], p['extension'],
+ p['classifier'], p['version'])
9 years, 10 months
[javapackages/big-refactoring] [dependency] Initial impl
by Michal Srb
commit b29c328997cba10939eeed33d615dc0779659f53
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 09:17:13 2014 +0200
[dependency] Initial impl
python/javapackages/pom/dependency.py | 129 +++++++++++++++++++++++++++++++++
1 files changed, 129 insertions(+), 0 deletions(-)
---
diff --git a/python/javapackages/pom/dependency.py b/python/javapackages/pom/dependency.py
new file mode 100644
index 0000000..6b0d684
--- /dev/null
+++ b/python/javapackages/pom/dependency.py
@@ -0,0 +1,129 @@
+import sys
+
+from artifact import AbstractArtifact, ArtifactFormatException
+from pomreader import POMReader
+from lxml.etree import Element, SubElement, tostring
+
+
+class Dependency(AbstractArtifact):
+
+ def __init__(self, groupId, artifactId, extension="", classifier="",
+ version="", scope="", optional=False, exclusions=set()):
+ self.groupId = groupId.strip()
+ self.artifactId = artifactId.strip()
+ self.extension = extension.strip()
+ self.classifier = classifier.strip()
+ self.version = version.strip()
+ self.scope = scope.strip()
+ self.optional = optional
+ self.exclusions = exclusions
+
+ def __unicode__(self):
+ return u"{gid}:{aid}:{ext}:{cla}:{ver}".format(gid=self.groupId,
+ aid=self.artifactId,
+ ext=self.extension,
+ cla=self.classifier,
+ ver=self.version)
+
+ def __str__(self):
+ return unicode(self).encode(sys.getfilesystemencoding())
+
+ def get_xml_element(self, root="dependency"):
+ """
+ Return XML Element node representation of the Artifact
+ """
+ root = Element(root)
+
+ for key in ("artifactId", "groupId", "extension", "version",
+ "classifier"):
+ if hasattr(self, key) and getattr(self, key):
+ item = SubElement(root, key)
+ item.text = getattr(self, key)
+ return root
+
+ def get_xml_str(self, root="artifact"):
+ """
+ Return XML formatted string representation of the Artifact
+ """
+ root = self.get_xml_element(root)
+ return tostring(root, pretty_print=True)
+
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.__dict__ == other.__dict__
+ return False
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __hash__(self):
+ return self.groupId.__hash__() + \
+ self.artifactId.__hash__() + \
+ self.version.__hash__() + \
+ self.extension.__hash__() + \
+ self.classifier.__hash__()
+
+ @classmethod
+ def from_xml_element(cls, xmlnode):
+ """
+ Create Dependency from xml.etree.ElementTree.Element as contained
+ within pom.xml.
+ """
+
+ parts = {'groupId': '',
+ 'artifactId': '',
+ 'extension': '',
+ 'classifier': '',
+ 'version': '',
+ 'scope': '',
+ 'optional': False}
+ # TODO: exclusions
+
+ parts = POMReader.find_parts(xmlnode, parts)
+
+ if not parts['groupId'] or not parts['artifactId']:
+ raise ArtifactFormatException(
+ "Empty groupId or artifactId encountered. "
+ "This is a bug, please report it!")
+
+ if parts['optional'] is not False:
+ if parts['optional'] == "false":
+ parts['optional'] = False
+ elif parts['optional'] == "true":
+ parts['optional'] = True
+
+ return cls(parts['groupId'], parts['artifactId'], parts['extension'],
+ parts['classifier'], parts['version'], parts['scope'],
+ parts['optional'])
+
+ @classmethod
+ def from_mvn_str(cls, mvnstr):
+ """
+ Create Dependency from Maven-style definition
+
+ The string should be in the format of:
+ groupId:artifactId[:extension[:classifier]][:version]
+
+ Where last part is always considered to be version unless empty
+ """
+ tup = mvnstr.split(":")
+
+ # groupId and artifactId are always present
+ if len(tup) < 2:
+ raise ArtifactFormatException("Artifact string '{mvnstr}' does not "
+ "contain ':' character. Can not parse"
+ .format(mvnstr=mvnstr))
+
+ if len(tup) > 5:
+ raise ArtifactFormatException("Artifact string '{mvnstr}' contains "
+ "too many colons. Can not parse"
+ .format(mvnstr=mvnstr))
+
+ groupId = tup[0]
+ artifactId = tup[1]
+ extension = tup[2] if len(tup) >= 4 else ""
+ classifier = tup[3] if len(tup) >= 5 else ""
+ version = tup[-1] if len(tup) >= 3 else ""
+
+ return cls(groupId, artifactId, extension,
+ classifier, version)
9 years, 10 months
[javapackages/big-refactoring] [pomreader] Use find() in find_parts()
by Michal Srb
commit 78df0e8af5b99eff75a2cebddc92f2ec73a94a9a
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 09:14:07 2014 +0200
[pomreader] Use find() in find_parts()
python/javapackages/pom/pomreader.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/python/javapackages/pom/pomreader.py b/python/javapackages/pom/pomreader.py
index 7863eea..80995c1 100644
--- a/python/javapackages/pom/pomreader.py
+++ b/python/javapackages/pom/pomreader.py
@@ -40,9 +40,9 @@ class POMReader(object):
return ret
@staticmethod
- def find_parts(doc, parts, xpath="./{*}", namespace=POM_NAMESPACE):
+ def find_parts(doc, parts, xpath="./{*}"):
for key in parts:
- node = POMReader.find(doc, xpath + key, namespace=namespace)
+ node = doc.find(xpath + key)
if node is not None and node.text is not None:
parts[key] = node.text.strip()
return parts
9 years, 10 months
[javapackages/big-refactoring] [pomreader] Implement find_parts method
by Michal Srb
commit 6039db5848693fead167567c0b802827d2d5d52d
Author: Michal Srb <msrb(a)redhat.com>
Date: Tue Jun 3 07:57:15 2014 +0200
[pomreader] Implement find_parts method
python/javapackages/pom/pomreader.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/python/javapackages/pom/pomreader.py b/python/javapackages/pom/pomreader.py
index 9066d2d..7863eea 100644
--- a/python/javapackages/pom/pomreader.py
+++ b/python/javapackages/pom/pomreader.py
@@ -38,3 +38,11 @@ class POMReader(object):
if len(ret) == 0:
ret = doc.xpath(xpath.replace('pom:', ''))
return ret
+
+ @staticmethod
+ def find_parts(doc, parts, xpath="./{*}", namespace=POM_NAMESPACE):
+ for key in parts:
+ node = POMReader.find(doc, xpath + key, namespace=namespace)
+ if node is not None and node.text is not None:
+ parts[key] = node.text.strip()
+ return parts
9 years, 10 months
[javapackages/big-refactoring] [artifact] Remove namespace from __hash__()
by Michal Srb
commit 027dc18d8d71d6375483fa8c443e74134ebc7f06
Author: Michal Srb <msrb(a)redhat.com>
Date: Mon Jun 2 22:45:00 2014 +0200
[artifact] Remove namespace from __hash__()
This artifact doesn't know anything about namespaces.
python/javapackages/pom/artifact.py | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
---
diff --git a/python/javapackages/pom/artifact.py b/python/javapackages/pom/artifact.py
index 72acdef..d8da712 100644
--- a/python/javapackages/pom/artifact.py
+++ b/python/javapackages/pom/artifact.py
@@ -100,9 +100,7 @@ class Artifact(AbstractArtifact):
self.artifactId.__hash__() + \
self.version.__hash__() + \
self.extension.__hash__() + \
- self.classifier.__hash__() + \
- self.namespace.__hash__()
-
+ self.classifier.__hash__()
@classmethod
def merge_artifacts(cls, dominant, recessive):
9 years, 10 months