diff --git a/MANIFEST.in b/MANIFEST.in index b9e1d722..295d9832 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -742,7 +742,12 @@ include tests/signindex/testy.jar include tests/signindex/unsigned.jar include tests/source-files/at.bitfire.davdroid/build.gradle include tests/source-files/catalog.test/app/build.gradle +include tests/source-files/catalog.test/buildSrc/build.gradle.kts +include tests/source-files/catalog.test/buildSrc/settings.gradle.kts +include tests/source-files/catalog.test/buildSrc2/build.gradle.kts +include tests/source-files/catalog.test/buildSrc2/settings.gradle.kts include tests/source-files/catalog.test/build.gradle.kts +include tests/source-files/catalog.test/core/build.gradle include tests/source-files/catalog.test/libs.versions.toml include tests/source-files/catalog.test/gradle/libs.versions.toml include tests/source-files/catalog.test/settings.gradle.kts diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index fc6c823c..0e66a5a4 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -73,9 +73,7 @@ GRADLE_KTS_CATALOG_FILE_REGEX = re.compile( GRADLE_CATALOG_FILE_REGEX = re.compile( r'''(\w+)\s*\{[^}]*from\(files\(['"]([^"]+)['"]\)\)''' ) -VERSION_CATALOG_REGEX = re.compile( - r'dependencyResolutionManagement\s*\{[^}]*versionCatalogs\s*\{' -) +VERSION_CATALOG_REGEX = re.compile(r'versionCatalogs\s*\{') class ExitCode(IntEnum): @@ -891,7 +889,7 @@ def scan_source(build_dir, build=metadata.Build(), json_per_build=None): if m: return m - catalogs = {} + all_catalogs = {} # Iterate through all files in the source code for root, dirs, files in os.walk(build_dir, topdown=True): # It's topdown, so checking the basename is enough @@ -900,7 +898,7 @@ def scan_source(build_dir, build=metadata.Build(), json_per_build=None): dirs.remove(ignoredir) if "settings.gradle" in files or "settings.gradle.kts" in files: - catalogs = get_catalogs(root) + all_catalogs[str(root)] = get_catalogs(root) for curfile in files: if curfile in ['.DS_Store']: @@ -983,6 +981,13 @@ def scan_source(build_dir, build=metadata.Build(), json_per_build=None): break elif curfile.endswith('.gradle') or curfile.endswith('.gradle.kts'): + catalog_path = str(build_dir) + # Find the longest path of dir that the curfile is in + for p in all_catalogs: + if os.path.commonpath([root, p]) == p: + catalog_path = p + catalogs = all_catalogs.get(catalog_path, {}) + if not os.path.isfile(filepath): continue with open(filepath, 'r', errors='replace') as f: diff --git a/tests/scanner.TestCase b/tests/scanner.TestCase index ce606d35..83b6e8ff 100755 --- a/tests/scanner.TestCase +++ b/tests/scanner.TestCase @@ -74,7 +74,7 @@ class ScannerTest(unittest.TestCase): 'se.manyver': 3, 'lockfile.test': 1, 'com.lolo.io.onelist': 6, - 'catalog.test': 10, + 'catalog.test': 22, } for d in glob.glob(os.path.join(source_files, '*')): build = fdroidserver.metadata.Build() diff --git a/tests/source-files/catalog.test/buildSrc/build.gradle.kts b/tests/source-files/catalog.test/buildSrc/build.gradle.kts new file mode 100644 index 00000000..5572706f --- /dev/null +++ b/tests/source-files/catalog.test/buildSrc/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + alias(libs.plugins.google.services) + alias(libs.plugins.firebase.crashlytics) + alias(projectLibs.plugins.firebase.crashlytics) +} diff --git a/tests/source-files/catalog.test/buildSrc/settings.gradle.kts b/tests/source-files/catalog.test/buildSrc/settings.gradle.kts new file mode 100644 index 00000000..98644daf --- /dev/null +++ b/tests/source-files/catalog.test/buildSrc/settings.gradle.kts @@ -0,0 +1,22 @@ +pluginManagement { + repositories { + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "buildSrc" +rootProject.buildFileName = "buildSrc.gradle.kts" diff --git a/tests/source-files/catalog.test/buildSrc2/build.gradle.kts b/tests/source-files/catalog.test/buildSrc2/build.gradle.kts new file mode 100644 index 00000000..5572706f --- /dev/null +++ b/tests/source-files/catalog.test/buildSrc2/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + alias(libs.plugins.google.services) + alias(libs.plugins.firebase.crashlytics) + alias(projectLibs.plugins.firebase.crashlytics) +} diff --git a/tests/source-files/catalog.test/buildSrc2/settings.gradle.kts b/tests/source-files/catalog.test/buildSrc2/settings.gradle.kts new file mode 100644 index 00000000..98644daf --- /dev/null +++ b/tests/source-files/catalog.test/buildSrc2/settings.gradle.kts @@ -0,0 +1,22 @@ +pluginManagement { + repositories { + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "buildSrc" +rootProject.buildFileName = "buildSrc.gradle.kts" diff --git a/tests/source-files/catalog.test/core/build.gradle b/tests/source-files/catalog.test/core/build.gradle new file mode 100644 index 00000000..72c9d184 --- /dev/null +++ b/tests/source-files/catalog.test/core/build.gradle @@ -0,0 +1,2 @@ +implementation libs.bundles.firebase +implementation libs.play.service.ads diff --git a/tests/source-files/catalog.test/settings.gradle.kts b/tests/source-files/catalog.test/settings.gradle.kts index 4ea352c8..fd9ba80c 100644 --- a/tests/source-files/catalog.test/settings.gradle.kts +++ b/tests/source-files/catalog.test/settings.gradle.kts @@ -1,4 +1,7 @@ dependencyResolutionManagement { + repositories { + mavenCentral() + } defaultLibrariesExtensionName = "projectLibs" versionCatalogs { create("libs") {