-
Notifications
You must be signed in to change notification settings - Fork 20
Change package URL output to Google Maven format #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| import subprocess | ||
| import shutil | ||
| import stat | ||
| import requests | ||
| from packageurl.contrib import url2purl | ||
| from askalono import identify | ||
| import fosslight_util.constant as constant | ||
|
|
@@ -566,26 +567,24 @@ def parse_gradle_download_lines(stdout_text, package_manager_name=''): | |
|
|
||
| def get_download_location(download_url_map, group_id, artifact_id, version, mvnrepo_url): | ||
| actual_key = f"{group_id}:{artifact_id}:{version}" | ||
| if download_url_map: | ||
| try: | ||
| actual_url = download_url_map.get(actual_key) | ||
|
|
||
| use_mvnrepo = True | ||
| if actual_url: | ||
| central_like = ("repo1.maven.org" in actual_url) or ("repo.maven.apache.org" in actual_url) | ||
| google_like = (("maven.google.com" in actual_url) or | ||
| ("dl.google.com/android/maven2" in actual_url) or | ||
| ("dl.google.com/dl/android/maven2" in actual_url)) | ||
| if central_like or google_like: | ||
| use_mvnrepo = True | ||
| else: | ||
| use_mvnrepo = False | ||
| except Exception as e: | ||
| logger.debug(f"Failed to get download location from download_url_map: {e}") | ||
| use_mvnrepo = True | ||
| else: | ||
| use_mvnrepo = True | ||
| if use_mvnrepo: | ||
| return f"{mvnrepo_url}{group_id}/{artifact_id}/{version}" | ||
| else: | ||
| return actual_url | ||
| actual_url = download_url_map.get(actual_key) if download_url_map else None | ||
| if actual_url: | ||
| if any(host in actual_url for host in ("repo1.maven.org", "repo.maven.apache.org")): | ||
| return f"{mvnrepo_url}{group_id}/{artifact_id}/{version}" | ||
| if not any(host in actual_url for host in ( | ||
| "maven.google.com", "dl.google.com/android/maven2", "dl.google.com/dl/android/maven2")): | ||
| return actual_url | ||
| return get_google_maven_url(mvnrepo_url, group_id, artifact_id, version) | ||
|
|
||
|
|
||
| def get_google_maven_url(mvnrepo_url, group_id, artifact_id, version, ): | ||
| group_path = group_id.replace('.', '/') | ||
| pom_url = (f"https://dl.google.com/dl/android/maven2" | ||
| f"/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.pom") | ||
| try: | ||
| resp = requests.head(pom_url, timeout=5, allow_redirects=True) | ||
| if resp.status_code == 200: | ||
| return f"https://maven.google.com/web/index.html#{group_id}:{artifact_id}:{version}" | ||
| except Exception: | ||
| logger.debug(f"Failed to check Google Maven URL: {pom_url}") | ||
| return f"{mvnrepo_url}{group_id}/{artifact_id}/{version}" | ||
|
woocheol-lge marked this conversation as resolved.
Comment on lines
568
to
+590
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per‑artifact HEAD probe can substantially slow large scans.
♻️ Suggested cache to avoid repeated network round‑trips+_GOOGLE_MAVEN_CACHE: dict[tuple[str, str, str], str] = {}
+
def get_google_maven_url(mvnrepo_url, group_id, artifact_id, version, ):
+ cache_key = (group_id, artifact_id, version)
+ if cache_key in _GOOGLE_MAVEN_CACHE:
+ return _GOOGLE_MAVEN_CACHE[cache_key]
group_path = group_id.replace('.', '/')
pom_url = (f"https://dl.google.com/dl/android/maven2"
f"/{group_path}/{artifact_id}/{version}/{artifact_id}-{version}.pom")
+ result = f"{mvnrepo_url}{group_id}/{artifact_id}/{version}"
try:
resp = requests.head(pom_url, timeout=5, allow_redirects=True)
if resp.status_code == 200:
- return f"https://maven.google.com/web/index.html#{group_id}:{artifact_id}:{version}"
+ result = f"https://maven.google.com/web/index.html#{group_id}:{artifact_id}:{version}"
except Exception:
logger.debug(f"Failed to check Google Maven URL: {pom_url}")
- return f"{mvnrepo_url}{group_id}/{artifact_id}/{version}"
+ _GOOGLE_MAVEN_CACHE[cache_key] = result
+ return result🧰 Tools🪛 Ruff (0.15.11)[warning] 588-588: Do not catch blind exception: (BLE001) 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: fosslight/fosslight_dependency_scanner
Length of output: 390
🏁 Script executed:
Repository: fosslight/fosslight_dependency_scanner
Length of output: 2198
Add
requeststo the project's runtime dependencies.requestsis imported unconditionally at line 14 of this module. It is not currently declared inpyproject.tomlorrequirements.txt, which will cause fresh installs to fail with an ImportError. Addrequeststo thedependencieslist inpyproject.toml(andrequirements.txtif maintained).🤖 Prompt for AI Agents