Skip to content

Commit

Permalink
Add support for custom repository URLs
Browse files Browse the repository at this point in the history
Adds support for getting packages from custom repository URLs,
in the case of maven packages.

Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
  • Loading branch information
AyanSinhaMahapatra committed Aug 8, 2023
1 parent c775297 commit 74c225f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions minecode/visitors/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
logger.setLevel(logging.DEBUG)


MAVEN_BASE_URL = 'https://repo1.maven.org/maven2'


class GzipFileWithTrailing(gzip.GzipFile):
"""
A subclass of gzip.GzipFile supporting files with trailing garbage. Ignore
Expand Down Expand Up @@ -104,7 +107,7 @@ def get_seeds(self):
# also has a npm mirrors: https://maven-eu.nuxeo.org/nexus/#view-repositories;npmjs~browsestorage


def get_pom_text(namespace, name, version, qualifiers={}):
def get_pom_text(namespace, name, version, qualifiers={}, base_url=MAVEN_BASE_URL):
"""
Return the contents of the POM file of the package described by the purl
field arguments in a string.
Expand All @@ -116,7 +119,8 @@ def get_pom_text(namespace, name, version, qualifiers={}):
namespace=namespace,
name=name,
version=version,
qualifiers=qualifiers
qualifiers=qualifiers,
base_url=base_url,
)
# Get and parse POM info
pom_url = urls['api_data_url']
Expand Down Expand Up @@ -279,11 +283,17 @@ def map_maven_package(package_url, package_content):
db_package = None
error = ''

if "repository_url" in package_url.qualifiers:
base_url = package_url.qualifiers["repository_url"]
else:
base_url = MAVEN_BASE_URL

pom_text = get_pom_text(
namespace=package_url.namespace,
name=package_url.name,
version=package_url.version,
qualifiers=package_url.qualifiers
qualifiers=package_url.qualifiers,
base_url=base_url,
)
if not pom_text:
msg = f'Package does not exist on maven: {package_url}'
Expand All @@ -302,11 +312,14 @@ def map_maven_package(package_url, package_content):
ancestor_pom_texts=ancestor_pom_texts,
package=package
)


urls = get_urls(
namespace=package_url.namespace,
name=package_url.name,
version=package_url.version,
qualifiers=package_url.qualifiers
qualifiers=package_url.qualifiers,
base_url=base_url,
)
# In the case of looking up a maven package with qualifiers of
# `classifiers=sources`, the purl of the package created from the pom does
Expand Down

0 comments on commit 74c225f

Please sign in to comment.