diff --git a/ognibuild/buildlog.py b/ognibuild/buildlog.py index 35f3d23..115b3f2 100644 --- a/ognibuild/buildlog.py +++ b/ognibuild/buildlog.py @@ -141,9 +141,11 @@ def problem_to_upstream_requirement(problem): # noqa: C901 elif isinstance(problem, MissingJavaClass): return JavaClassRequirement(problem.classname) elif isinstance(problem, MissingHaskellDependencies): - return [HaskellPackageRequirement.from_string(dep) for dep in problem.deps] + return [HaskellPackageRequirement.from_string(dep) + for dep in problem.deps] elif isinstance(problem, MissingMavenArtifacts): - return [MavenArtifactRequirement(artifact) for artifact in problem.artifacts] + return [MavenArtifactRequirement.from_str(artifact) + for artifact in problem.artifacts] elif isinstance(problem, MissingCSharpCompiler): return BinaryRequirement("msc") elif isinstance(problem, GnomeCommonMissing): diff --git a/ognibuild/buildsystem.py b/ognibuild/buildsystem.py index 82d4992..17dd76f 100644 --- a/ognibuild/buildsystem.py +++ b/ognibuild/buildsystem.py @@ -41,6 +41,7 @@ from .requirements import ( RPackageRequirement, OctavePackageRequirement, PhpPackageRequirement, + MavenArtifactRequirement, ) from .fix_build import run_with_build_fixers from .session import which @@ -1209,6 +1210,23 @@ class Maven(BuildSystem): # is that what we need? raise NotImplementedError + def get_declared_dependencies(self, session, fixers=None): + import xml.etree.ElementTree as ET + try: + root = xmlparse_simplify_namespaces(self.path, + ['http://maven.apache.org/POM/4.0.0']) + except ET.ParseError as e: + logging.warning('Unable to parse package.xml: %s', e) + return + assert root.tag == 'project', 'root tag is %r' % root.tag + deps_tag = root.find('dependencies') + if deps_tag: + for dep in deps_tag.findall('dependency'): + yield "core", MavenArtifactRequirement( + dep.find('groupId').text, + dep.find('artifactId').text, + dep.find('version').text) + class Cabal(BuildSystem): diff --git a/ognibuild/requirements.py b/ognibuild/requirements.py index cb83fbd..729e77b 100644 --- a/ognibuild/requirements.py +++ b/ognibuild/requirements.py @@ -429,11 +429,41 @@ class HaskellPackageRequirement(Requirement): class MavenArtifactRequirement(Requirement): - artifacts: List[Tuple[str, str, str]] + group_id: str + artifact_id: str + version: Optional[str] + kind: Optional[str] - def __init__(self, artifacts): + def __init__(self, group_id, artifact_id, version=None, kind=None): super(MavenArtifactRequirement, self).__init__("maven-artifact") - self.artifacts = artifacts + self.group_id = group_id + self.artifact_id = artifact_id + self.version = version + self.kind = kind + + def __str__(self): + return "maven requirement: %s:%s:%s" % ( + self.group_id, self.artifact_id, self.version) + + @classmethod + def from_str(cls, text): + return cls.from_tuple(text.split(':')) + + @classmethod + def from_tuple(cls, parts): + if len(parts) == 4: + (group_id, artifact_id, kind, version) = parts + elif len(parts) == 3: + (group_id, artifact_id, version) = parts + kind = "jar" + elif len(parts) == 2: + version = None + (group_id, artifact_id) = parts + kind = "jar" + else: + raise ValueError( + "invalid number of parts to artifact %r" % parts) + return cls(group_id, artifact_id, version, kind) class GnomeCommonRequirement(Requirement): diff --git a/ognibuild/resolver/apt.py b/ognibuild/resolver/apt.py index 39ceb7c..ce160f3 100644 --- a/ognibuild/resolver/apt.py +++ b/ognibuild/resolver/apt.py @@ -412,32 +412,25 @@ def resolve_haskell_package_req(apt_mgr, req): def resolve_maven_artifact_req(apt_mgr, req): - artifact = req.artifacts[0] - parts = artifact.split(":") - if len(parts) == 4: - (group_id, artifact_id, kind, version) = parts - regex = False - elif len(parts) == 3: - (group_id, artifact_id, version) = parts - kind = "jar" - regex = False - elif len(parts) == 2: + if req.version is None: version = ".*" - (group_id, artifact_id) = parts - kind = "jar" regex = True + escape = re.escape else: - raise AssertionError("invalid number of parts to artifact %s" % artifact) - paths = [ - posixpath.join( - "/usr/share/maven-repo", - group_id.replace(".", "/"), - artifact_id, + version = req.version + regex = False + def escape(x): + return x + kind = req.kind or 'jar' + path = posixpath.join( + escape("/usr/share/maven-repo"), + escape(req.group_id.replace(".", "/")), + escape(req.artifact_id), version, - "%s-%s.%s" % (artifact_id, version, kind), + escape("%s-") + version + escape("." + kind) ) - ] - return find_reqs_simple(apt_mgr, paths, regex=regex) + + return find_reqs_simple(apt_mgr, [path], regex=regex) def resolve_gnome_common_req(apt_mgr, req):