Improve maven support.
This commit is contained in:
parent
057599575a
commit
ae9e30468a
4 changed files with 69 additions and 26 deletions
|
@ -141,9 +141,11 @@ def problem_to_upstream_requirement(problem): # noqa: C901
|
||||||
elif isinstance(problem, MissingJavaClass):
|
elif isinstance(problem, MissingJavaClass):
|
||||||
return JavaClassRequirement(problem.classname)
|
return JavaClassRequirement(problem.classname)
|
||||||
elif isinstance(problem, MissingHaskellDependencies):
|
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):
|
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):
|
elif isinstance(problem, MissingCSharpCompiler):
|
||||||
return BinaryRequirement("msc")
|
return BinaryRequirement("msc")
|
||||||
elif isinstance(problem, GnomeCommonMissing):
|
elif isinstance(problem, GnomeCommonMissing):
|
||||||
|
|
|
@ -41,6 +41,7 @@ from .requirements import (
|
||||||
RPackageRequirement,
|
RPackageRequirement,
|
||||||
OctavePackageRequirement,
|
OctavePackageRequirement,
|
||||||
PhpPackageRequirement,
|
PhpPackageRequirement,
|
||||||
|
MavenArtifactRequirement,
|
||||||
)
|
)
|
||||||
from .fix_build import run_with_build_fixers
|
from .fix_build import run_with_build_fixers
|
||||||
from .session import which
|
from .session import which
|
||||||
|
@ -1209,6 +1210,23 @@ class Maven(BuildSystem):
|
||||||
# is that what we need?
|
# is that what we need?
|
||||||
raise NotImplementedError
|
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):
|
class Cabal(BuildSystem):
|
||||||
|
|
||||||
|
|
|
@ -429,11 +429,41 @@ class HaskellPackageRequirement(Requirement):
|
||||||
|
|
||||||
class MavenArtifactRequirement(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")
|
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):
|
class GnomeCommonRequirement(Requirement):
|
||||||
|
|
|
@ -412,32 +412,25 @@ def resolve_haskell_package_req(apt_mgr, req):
|
||||||
|
|
||||||
|
|
||||||
def resolve_maven_artifact_req(apt_mgr, req):
|
def resolve_maven_artifact_req(apt_mgr, req):
|
||||||
artifact = req.artifacts[0]
|
if req.version is None:
|
||||||
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:
|
|
||||||
version = ".*"
|
version = ".*"
|
||||||
(group_id, artifact_id) = parts
|
|
||||||
kind = "jar"
|
|
||||||
regex = True
|
regex = True
|
||||||
|
escape = re.escape
|
||||||
else:
|
else:
|
||||||
raise AssertionError("invalid number of parts to artifact %s" % artifact)
|
version = req.version
|
||||||
paths = [
|
regex = False
|
||||||
posixpath.join(
|
def escape(x):
|
||||||
"/usr/share/maven-repo",
|
return x
|
||||||
group_id.replace(".", "/"),
|
kind = req.kind or 'jar'
|
||||||
artifact_id,
|
path = posixpath.join(
|
||||||
|
escape("/usr/share/maven-repo"),
|
||||||
|
escape(req.group_id.replace(".", "/")),
|
||||||
|
escape(req.artifact_id),
|
||||||
version,
|
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):
|
def resolve_gnome_common_req(apt_mgr, req):
|
||||||
|
|
Loading…
Add table
Reference in a new issue