Skip to content

Commit b9c6088

Browse files
committed
fix: Improve dependency parsing and logging
This commit refines the logic for parsing dependencies from Gradle build files and improves the associated logging for better debugging. **Key Changes:** * **Improved Regex for Alias Dependencies:** * The regular expression in `ProjectAnalyzerRepositoryImpl.kt` used for finding unprefixed aliases (e.g., `implementation(compose.ui)`) has been made more specific. * The new regex (`\(\s*([a-zA-Z_][\w.]+)\s*\)`) now correctly captures only valid alias paths, ignoring function calls with string literals like `project(":module")` or `files("...")`. * **Enhanced Logging and Filtering:** * Conditions for matching unprefixed aliases now explicitly ignore paths starting with `project` and `files` to prevent them from being incorrectly treated as library aliases. * The debug log for "not found" unprefixed aliases has been updated to log the entire regex match group, providing more context for troubleshooting parsing errors.
1 parent dbe57eb commit b9c6088

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

composeApp/src/jvmMain/kotlin/com/meet/dev/analyzer/data/repository/project/ProjectAnalyzerRepositoryImpl.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class ProjectAnalyzerRepositoryImpl : ProjectAnalyzerRepository {
174174

175175
// alias-like without libs prefix → implementation(compose.components.uiToolingPreview)
176176
val unprefixedAliasDepRegex =
177-
Regex("""(implementation|api|ksp|kapt|compileOnly|runtimeOnly|testImplementation|androidTestImplementation)\(([^)]+)\)""")
177+
Regex("""(implementation|api|ksp|kapt|compileOnly|runtimeOnly|testImplementation|androidTestImplementation)\(\s*([a-zA-Z_][\w.]+)\s*\)""")
178178

179179
val dependencies = arrayListOf<Dependency>()
180180

@@ -309,8 +309,9 @@ class ProjectAnalyzerRepositoryImpl : ProjectAnalyzerRepository {
309309
unprefixedAliasDepRegex.findAll(content).forEach { match ->
310310
val path = match.groupValues[2] // e.g. compose.components.uiToolingPreview
311311
// Skip ones already matched by libs.* to avoid duplicates
312-
if (!path.startsWith("libs.") && !path.startsWith("libs.bundles.")
313-
&& !path.startsWith("projects.") && !path.startsWith("project.")
312+
if (!path.startsWith("libs.")
313+
&& !path.startsWith("project")
314+
&& !path.startsWith("files")
314315
) {
315316
val alias =
316317
path.replace('.', '-') // e.g. compose-components-uiToolingPreview
@@ -341,7 +342,8 @@ class ProjectAnalyzerRepositoryImpl : ProjectAnalyzerRepository {
341342
AppLogger.d(TAG) { "Found unprefixedAliasDependency: $dependency" }
342343
dependencies.add(dependency)
343344
} else {
344-
AppLogger.d(TAG) { "Library not found for unprefixed alias: $path" }
345+
// AppLogger.d(TAG) { "Library not found for unprefixed alias: $path" }
346+
AppLogger.d(TAG) { "Library not found for unprefixed alias: ${match.groupValues}" }
345347
dependencies.add(
346348
Dependency(
347349
versionName = "",
@@ -536,6 +538,7 @@ class ProjectAnalyzerRepositoryImpl : ProjectAnalyzerRepository {
536538
val projectName = projectNameLine.substringAfter("=").replace("\"", "").trim()
537539
return projectName
538540
}
541+
539542
val rootModuleBuildFileInfo =
540543
moduleBuildFileInfos.find { it.moduleName == findProjectName() }
541544

0 commit comments

Comments
 (0)