From 2ceec6b9d6a802155fefc1d9d4ad669c61b388f4 Mon Sep 17 00:00:00 2001 From: linsui <2873532-linsui@users.noreply.gitlab.com> Date: Tue, 24 Sep 2024 18:55:30 +0800 Subject: [PATCH] scanner: catalog: dependency declaration can be declared as a simple string --- fdroidserver/scanner.py | 13 +++++++++---- tests/scanner.TestCase | 1 + .../catalog.test/gradle/libs.versions.toml | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index 0e877f07..88ce3236 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -33,6 +33,7 @@ from datetime import datetime, timedelta from enum import IntEnum from pathlib import Path from tempfile import TemporaryDirectory +from typing import Union if sys.version_info >= (3, 11): import tomllib @@ -114,7 +115,7 @@ class GradleVersionCatalog: """ return alias.replace("-", ".").replace("_", ".") - def get_version(self, version: dict) -> str: + def get_version(self, version: Union[dict, str]) -> str: if isinstance(version, str): return version ref = version.get("ref") @@ -126,8 +127,10 @@ class GradleVersionCatalog: or version.get("strictly", "") ) - def library_to_coordinate(self, library: dict) -> str: + def library_to_coordinate(self, library: Union[dict, str]) -> str: """Generate the Gradle dependency coordinate from catalog.""" + if isinstance(library, str): + return library module = library.get("module") if not module: group = library.get("group") @@ -143,8 +146,10 @@ class GradleVersionCatalog: else: return module - def plugin_to_coordinate(self, plugin: dict) -> str: + def plugin_to_coordinate(self, plugin: Union[dict, str]) -> str: """Generate the Gradle plugin coordinate from catalog.""" + if isinstance(plugin, str): + return plugin id = plugin.get("id") if not id: return "" @@ -155,7 +160,7 @@ class GradleVersionCatalog: else: return id - def bundle_to_coordinates(self, bundle) -> list[str]: + def bundle_to_coordinates(self, bundle: list[str]) -> list[str]: """Generate the Gradle dependency bundle coordinate from catalog.""" coordinates = [] for alias in bundle: diff --git a/tests/scanner.TestCase b/tests/scanner.TestCase index 701c0b2e..dbb27fd7 100755 --- a/tests/scanner.TestCase +++ b/tests/scanner.TestCase @@ -143,6 +143,7 @@ class ScannerTest(unittest.TestCase): 'firebase.crash': ['com.google.firebase:firebase-crash:1.1.1'], 'firebase.core': ['com.google.firebase:firebase-core:2.2.2'], 'play.service.ads': ['com.google.android.gms:play-services-ads:1.2.1'], + 'jacoco': ['org.jacoco:org.jacoco.core:0.8.7'], 'plugins.google.services': ['com.google.gms.google-services:1.2.1'], 'plugins.firebase.crashlytics': ['com.google.firebase.crashlytics:1.1.1'], 'bundles.firebase': [ diff --git a/tests/source-files/catalog.test/gradle/libs.versions.toml b/tests/source-files/catalog.test/gradle/libs.versions.toml index 666a0f7f..e5327907 100644 --- a/tests/source-files/catalog.test/gradle/libs.versions.toml +++ b/tests/source-files/catalog.test/gradle/libs.versions.toml @@ -6,6 +6,7 @@ gms = "1.2.1" firebase-crash = { module = "com.google.firebase:firebase-crash", version.ref = "firebase" } firebase_core = { module = "com.google.firebase:firebase-core", version = "2.2.2" } "play.service.ads" = { module = "com.google.android.gms:play-services-ads", version.ref = "gms"} +jacoco = "org.jacoco:org.jacoco.core:0.8.7" [plugins] google-services = { id = "com.google.gms.google-services", version.ref = "gms" }