[javapackages/xmvn-resolve-wrapper] [maven.req] Fix rebase bugs
by Michal Srb
commit 54719dcb6b315f3cf063663f2fc07a871d086ced
Author: Michal Srb <msrb(a)redhat.com>
Date: Mon Jun 2 08:31:23 2014 +0200
[maven.req] Fix rebase bugs
depgenerators/maven.req | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/depgenerators/maven.req b/depgenerators/maven.req
index ddfd423..39c5ab0 100755
--- a/depgenerators/maven.req
+++ b/depgenerators/maven.req
@@ -48,6 +48,8 @@ from javapackages.artifact import Artifact, ProvidedArtifact, SkippedArtifact, D
from javapackages.xmvn_resolve import XMvnResolve, ResolutionRequest, ResolutionResult
+XMVN_RESOLVE_PATH="/usr/bin/xmvn-resolve"
+
def process_java_version(version_string):
version = version_string.split('.')
if len(version) != 2:
@@ -161,8 +163,7 @@ class TagBuilder(object):
break
return poms
- def __generate_requires_from_pom(self, pomfile):
- pom = POM(pomfile)
+ def __generate_requires_from_pom(self, pom):
plugins = list(pom.get_plugins())
extensions = list(pom.get_extensions())
pgid = pom.parentGroupId
9 years, 10 months
[javapackages/xmvn-resolve-wrapper: 4/4] [maven.req] Migrate to xmvn-resolve wrapper and raw requests
by Michal Srb
commit 91cc552de3f49d8be8ce5c40a245154771970850
Author: Michal Srb <msrb(a)redhat.com>
Date: Mon Jun 2 07:57:56 2014 +0200
[maven.req] Migrate to xmvn-resolve wrapper and raw requests
depgenerators/maven.req | 94 +++++++++++++++++++----------------------------
1 files changed, 38 insertions(+), 56 deletions(-)
---
diff --git a/depgenerators/maven.req b/depgenerators/maven.req
index dea89d7..ddfd423 100755
--- a/depgenerators/maven.req
+++ b/depgenerators/maven.req
@@ -45,19 +45,8 @@ from lxml import etree
from javapackages import POM
from javapackages.depmap import Depmap, MetadataInvalidException
from javapackages.artifact import Artifact, ProvidedArtifact, SkippedArtifact, Dependency
+from javapackages.xmvn_resolve import XMvnResolve, ResolutionRequest, ResolutionResult
-XMVN_RESOLVE_PATH='/usr/bin/xmvn-resolve'
-
-def resolve_artifact(coordinates):
- # TODO: add support for namespaces
- outfile = open("/dev/null", 'w')
- procargs = [XMVN_RESOLVE_PATH, coordinates]
- proc = subprocess.Popen(procargs, shell=False, stdout=outfile)
- out = proc.communicate()[0]
- ret = proc.wait()
- if ret:
- return False
- return True
def process_java_version(version_string):
version = version_string.split('.')
@@ -172,59 +161,52 @@ class TagBuilder(object):
break
return poms
- def __generate_requires_from_pom(self, pom):
- plugins = pom.get_plugins()
- extensions = pom.get_extensions()
+ def __generate_requires_from_pom(self, pomfile):
+ pom = POM(pomfile)
+ plugins = list(pom.get_plugins())
+ extensions = list(pom.get_extensions())
pgid = pom.parentGroupId
paid = pom.parentArtifactId
pver = pom.parentVersion
+ deps = plugins + extensions
unresolvable = []
- # TODO: compat versions?
- for p in plugins:
- # TODO: namespaces
- plug = Dependency(p.groupId, p.artifactId, requestedVersion=p.version)
- aver = self.__is_provided_by_subpackage(plug)
- if resolve_artifact(plug.get_mvn_str()):
- print(plug.get_rpm_str())
- elif aver is not None:
- print("{rpmstr} = {version}".format(rpmstr=plug.get_rpm_str(), version=aver))
- else:
- unresolvable.append(plug.get_mvn_str())
- for pd in p.dependencies:
- # TODO: namespaces
- dep = Dependency(pd.groupId, pd.artifactId, requestedVersion=pd.version)
- if resolve_artifact(dep.get_mvn_str()):
- print(dep.get_rpm_str())
- else:
- unresolvable.append(plug.get_mvn_str())
-
- for e in extensions:
- # TODO: namespaces
- ext = Dependency(e.groupId, e.artifactId, requestedVersion=e.version)
- aver = self.__is_provided_by_subpackage(ext)
- if resolve_artifact(ext.get_mvn_str()):
- print(ext.get_rpm_str())
- elif aver is not None:
- print("{rpmstr} = {version}".format(rpmstr=ext.get_rpm_str(), version=aver))
- else:
- unresolvable.append(plug.get_mvn_str())
-
- if paid and pver:
- parent_dep = Dependency(pgid, paid, requestedVersion=pver, extension="pom")
- aver = self.__is_provided_by_subpackage(parent_dep)
- if resolve_artifact(parent_dep.get_mvn_str()):
- # TODO: namespaces
- print(parent_dep.get_rpm_str())
- elif aver is not None:
- print("{rpmstr} = {version}".format(rpmstr=parent_dep.get_rpm_str(), version=aver))
+ reqs = []
+ for d in deps:
+ reqs.append(ResolutionRequest(d.groupId, d.artifactId, version=d.version))
+ results = XMvnResolve.process_raw_request(reqs)
+ for i, r in enumerate(results):
+ dep = Dependency(deps[i].groupId, deps[i].artifactId, requestedVersion=deps[i].version)
+ if not r:
+ unresolvable.append(dep)
+ continue
+ if r.compatVersion != "SYSTEM":
+ dep.resolvedVersion = r.compatVersion
+ if r.namespace:
+ dep.namespace = r.namespace
+ print(dep.get_rpm_str())
+
+ if paid:
+ if not pver:
+ raise Exception("Unable to generate requires for artifact {}:{},".format(POM.groupId, POM.artifactId),
+ "because its parent POM {}:{} has unknown version".format(pgid, paid))
+
+ req = ResolutionRequest(pgid, paid, extension="pom")
+ r = XMvnResolve.process_raw_request([req])[0]
+ dep = Dependency(pgid, paid, pver, extension="pom")
+ if not r:
+ unresolvable.append(dep)
else:
- unresolvable.append(parent_dep.get_mvn_str())
+ if r.compatVersion != "SYSTEM":
+ dep.resolvedVersion = r.compatVersion
+ if r.namespace:
+ dep.namespace = r.namespace
+ print(dep.get_rpm_str())
if unresolvable:
- raise Exception("Unable to generate requires on unresolvable artifact{}: {}"
- .format('s' if len(unresolvable) > 1 else '', ", ".join(unresolvable)))
+ raise Exception("Unable to generate requires on unresolvable artifacts: {}"
+ .format(", ".join([x.get_mvn_str() for x in unresolvable])))
def __generate_java_requires(self, depmap):
9 years, 10 months
[javapackages/xmvn-resolve-wrapper: 3/4] [pom] Add ability to read parent's version
by Michal Srb
commit 3bf1aa10acf255728cc700aba3fd887475cb6c78
Author: Michal Srb <msrb(a)redhat.com>
Date: Mon Jun 2 07:57:13 2014 +0200
[pom] Add ability to read parent's version
python/javapackages/pom.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/python/javapackages/pom.py b/python/javapackages/pom.py
index 6c15813..7dc662a 100644
--- a/python/javapackages/pom.py
+++ b/python/javapackages/pom.py
@@ -97,7 +97,7 @@ class POM(object):
@property
def parentVersion(self):
"""
- version of the parent artifact of None
+ version of the parent artifact or None
"""
ver = self.__find('./pom:parent/pom:version')
if ver is None:
9 years, 10 months
[javapackages/xmvn-resolve-wrapper: 2/4] [xmvn_resolve] Add classmethod from_artifact() to ResolutionRequest
by Michal Srb
commit c0881a2174d575692b0ce58e23b52039eb89dafd
Author: Michal Srb <msrb(a)redhat.com>
Date: Wed May 28 08:57:36 2014 +0200
[xmvn_resolve] Add classmethod from_artifact() to ResolutionRequest
python/javapackages/xmvn_resolve.py | 41 +++++++++++++++++++++-------------
1 files changed, 25 insertions(+), 16 deletions(-)
---
diff --git a/python/javapackages/xmvn_resolve.py b/python/javapackages/xmvn_resolve.py
index b7988db..b4daedd 100644
--- a/python/javapackages/xmvn_resolve.py
+++ b/python/javapackages/xmvn_resolve.py
@@ -87,14 +87,18 @@ class ResolutionResult(object):
class ResolutionRequest(object):
- def __init__(self, artifact):
- self.artifact = artifact
+ def __init__(self, groupId, artifactId, extension="", classifier="", version=""):
+ self.groupId = groupId
+ self.artifactId = artifactId
+ self.extension = extension
+ self.classifier = classifier
+ self.version = version
def get_xml(self):
- return ResolutionRequest.create_raw_request_xml(self.artifact)
+ return ResolutionRequest.create_raw_request_xml(self.groupId, self.artifactId, self.extension, self.classifier, self.version)
@staticmethod
- def create_raw_request_xml(artifact):
+ def create_raw_request_xml(groupId, artifactId, extension="", classifier="", version=""):
template = """
<request>
<artifact>
@@ -103,24 +107,29 @@ class ResolutionRequest(object):
</artifact>
</request>
"""
- version = ""
- classifier = ""
- extension = ""
- if artifact.extension:
- extension = "<extension>{ext}</extension>".format(ext=extension)
- if artifact.classifier:
- classifier = "<classifier>{cla}</classifier>".format(cla=classifier)
- if artifact.version:
- version = "<version>{ver}</version>".format(ver=artifact.version)
+ ver = ""
+ cla = ""
+ ext = ""
+ if extension:
+ ext = "<extension>{ext}</extension>".format(ext=extension)
+ if classifier:
+ cla = "<classifier>{cla}</classifier>".format(cla=classifier)
+ if version:
+ ver = "<version>{ver}</version>".format(ver=version)
- return template.format(gid=artifact.groupId, aid=artifact.artifactId,
- ext=extension, cla=classifier, ver=version)
+ return template.format(gid=groupId, aid=artifactId,
+ ext=ext, cla=cla, ver=ver)
+
+ @classmethod
+ def from_artifact(cls, artifact):
+ return cls(artifact.artifactId, artifact.groupId,
+ artifact.extension, artifact.classifier, artifact.version)
if __name__ == "__main__":
artifact = Artifact("junit", "junit")
- req = ResolutionRequest(artifact)
+ req = ResolutionRequest.from_artifact(artifact)
results = XMvnResolve.process_raw_request([req])
print(len(results))
9 years, 10 months
[javapackages/xmvn-resolve-wrapper: 1/4] [xmvn_resolve] Initial implementation
by Michal Srb
commit a35d75f5558855a8bf7323c62b9b701991559ba8
Author: Michal Srb <msrb(a)redhat.com>
Date: Wed May 28 08:28:15 2014 +0200
[xmvn_resolve] Initial implementation
python/javapackages/xmvn_resolve.py | 127 +++++++++++++++++++++++++++++++++++
1 files changed, 127 insertions(+), 0 deletions(-)
---
diff --git a/python/javapackages/xmvn_resolve.py b/python/javapackages/xmvn_resolve.py
new file mode 100644
index 0000000..b7988db
--- /dev/null
+++ b/python/javapackages/xmvn_resolve.py
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+# Copyright (c) 2014, Red Hat, Inc
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name of Red Hat nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Michal Srb <msrb(a)redhat.com>
+
+
+import subprocess
+import lxml.etree
+from artifact import Artifact
+
+
+class XMvnResolve(object):
+ # TODO:
+ # - do not hardcode path to xmvn-resolve
+ # - documentation
+
+ @staticmethod
+ def process_raw_request(raw_request_list):
+ request = XMvnResolve.__join_raw_requests(raw_request_list)
+ procargs = ['/usr/bin/xmvn-resolve', '--raw-request']
+ proc = subprocess.Popen(procargs, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ stdout = proc.communicate(input=request)[0]
+ proc.wait()
+ result = XMvnResolve.__process_results(stdout)
+ return result
+
+ @staticmethod
+ def __join_raw_requests(raw_request_list):
+ request = "<requests>"
+ for r in raw_request_list:
+ request += r.get_xml()
+ request += "</requests>"
+
+ return request
+
+ @staticmethod
+ def __process_results(result_xml):
+ results = []
+
+ doc = lxml.etree.fromstring(result_xml)
+ nodes = doc.xpath('/results/result')
+ for node in nodes:
+ if len(node) > 0:
+ ns = node.find('./namespace')
+ compat_ver = node.find('./compatVersion')
+ results.append(ResolutionResult(ns.text or "",
+ compat_ver.text or ""))
+ else:
+ results.append(None)
+ return results
+
+
+class ResolutionResult(object):
+ def __init__(self, namespace="", compatVersion=""):
+ self.namespace = namespace
+ self.compatVersion = compatVersion
+
+ def __str__(self):
+ return "version:" + self.compatVersion + "namespace: " + self.namespace
+
+
+class ResolutionRequest(object):
+ def __init__(self, artifact):
+ self.artifact = artifact
+
+ def get_xml(self):
+ return ResolutionRequest.create_raw_request_xml(self.artifact)
+
+ @staticmethod
+ def create_raw_request_xml(artifact):
+ template = """
+<request>
+ <artifact>
+ <groupId>{gid}</groupId>
+ <artifactId>{aid}</artifactId>{ext}{cla}{ver}
+ </artifact>
+</request>
+"""
+ version = ""
+ classifier = ""
+ extension = ""
+ if artifact.extension:
+ extension = "<extension>{ext}</extension>".format(ext=extension)
+ if artifact.classifier:
+ classifier = "<classifier>{cla}</classifier>".format(cla=classifier)
+ if artifact.version:
+ version = "<version>{ver}</version>".format(ver=artifact.version)
+
+ return template.format(gid=artifact.groupId, aid=artifact.artifactId,
+ ext=extension, cla=classifier, ver=version)
+
+
+if __name__ == "__main__":
+ artifact = Artifact("junit", "junit")
+
+ req = ResolutionRequest(artifact)
+
+ results = XMvnResolve.process_raw_request([req])
+ print(len(results))
+ print(results[0])
9 years, 10 months
[javapackages] (4 commits) Created branch xmvn-resolve-wrapper
by Michal Srb
The branch 'xmvn-resolve-wrapper' was created.
Summary of new commits:
a35d75f... [xmvn_resolve] Initial implementation
c0881a2... [xmvn_resolve] Add classmethod from_artifact() to Resolutio
3bf1aa1... [pom] Add ability to read parent's version
91cc552... [maven.req] Migrate to xmvn-resolve wrapper and raw request
9 years, 10 months