diff --git a/swh/indexer/metadata_dictionary.py b/swh/indexer/metadata_dictionary.py --- a/swh/indexer/metadata_dictionary.py +++ b/swh/indexer/metadata_dictionary.py @@ -246,6 +246,7 @@ d = xmltodict.parse(content)['project'] metadata = self.translate_dict(d, normalize=False) metadata[SCHEMA_URI+'codeRepository'] = self.parse_repositories(d) + metadata[SCHEMA_URI+'license'] = self.parse_licenses(d) return self.normalize_translation(metadata) _default_repository = {'url': 'https://repo.maven.apache.org/maven2/'} @@ -278,6 +279,13 @@ def normalize_groupId(self, id_): return {"@id": id_} + def parse_licenses(self, d): + """https://maven.apache.org/pom.html#Licenses""" + licenses = d.get('licenses', {}).get('license', []) + if isinstance(licenses, dict): + licenses = [licenses] + return [{"@id": license['url']} for license in licenses] + def main(): raw_content = """{"name": "test_name", "unknown_term": "ut"}""" diff --git a/swh/indexer/tests/test_metadata.py b/swh/indexer/tests/test_metadata.py --- a/swh/indexer/tests/test_metadata.py +++ b/swh/indexer/tests/test_metadata.py @@ -426,6 +426,14 @@ + + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + """ result = MAPPINGS["MavenMapping"].translate(raw_content) self.assertEqual(result, { @@ -434,6 +442,7 @@ 'name': 'Maven Default Project', 'identifier': 'com.mycompany.app', 'version': '1.2.3', + 'license': 'https://www.apache.org/licenses/LICENSE-2.0.txt', 'codeRepository': 'http://repo1.maven.org/maven2/com/mycompany/app/my-app', })