Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(ingestion): handle relative paths in Gradle module indexing (#3587)
ASVLCII20093562b2a0
diff --git a/packages/core/src/repowise/core/ingestion/resolvers/jvm_gradle.py b/packages/core/src/repowise/core/ingestion/resolvers/jvm_gradle.pyindex 9526cb528..1f519465d 100644--- a/packages/core/src/repowise/core/ingestion/resolvers/jvm_gradle.py+++ b/packages/core/src/repowise/core/ingestion/resolvers/jvm_gradle.py@@ -11,6 +11,7 @@ re-export facade for backwards compatibility).from __future__ import annotations+import osimport refrom dataclasses import dataclass, fieldfrom functools import lru_cache@@ -424,7 +425,7 @@ def build_jvm_gradle_index(ss_map: dict[str, SourceSet] = {ss.name: ss for ss in source_sets}project = JvmGradleProject(id=module_name or "<root>",- root_dir=mod_dir.relative_to(resolved_repo).as_posix() if module_name else "",+ root_dir=Path(os.path.relpath(mod_dir, repo_path)).as_posix() if module_name else "",source_sets=ss_map,plugins=plugins,)diff --git a/tests/unit/ingestion/test_jvm_gradle.py b/tests/unit/ingestion/test_jvm_gradle.pyindex 64b34aa4d..814bfb402 100644--- a/tests/unit/ingestion/test_jvm_gradle.py+++ b/tests/unit/ingestion/test_jvm_gradle.py@@ -5,6 +5,7 @@ from __future__ import annotationsfrom pathlib import Pathimport networkx as nx+import pytestfrom repowise.core.ingestion.resolvers.context import ResolverContextfrom repowise.core.ingestion.resolvers.jvm_gradle import (@@ -45,6 +46,83 @@ def _make_kotlin_class(repo: Path, module: str, package: str, class_name: str) -class TestJvmGradleIndex:+ @pytest.mark.parametrize("repo_arg", ["project", "./project", "parent/../project"])+ def test_relative_repo_path(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, repo_arg: str+ ) -> None:+ repo = tmp_path / "project"+ repo.mkdir()+ (tmp_path / "parent").mkdir()+ (repo / "settings.gradle.kts").write_text(+ 'include("app", ":libs:core")\n'+ 'project(":libs:core").projectDir = file("custom/core")\n'+ )+ (repo / "build.gradle.kts").write_text("// root\n")+ app_path = _make_java_class(repo, "app", "com.example", "App")+ core_path = _make_kotlin_class(repo, "custom/core", "com.example", "Core")+ monkeypatch.chdir(tmp_path)++ index = build_jvm_gradle_index(Path(repo_arg))++ assert index.projects["app"].root_dir == "app"+ assert index.projects["libs:core"].root_dir == "custom/core"+ assert index.lookup_class("com.example.App") == [app_path]+ assert index.lookup_class("com.example.Core") == [core_path]++ @pytest.mark.parametrize("relative_repo", [False, True])+ @pytest.mark.parametrize("absolute_override", [False, True])+ def test_project_dir_outside_repo(+ self,+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+ relative_repo: bool,+ absolute_override: bool,+ ) -> None:+ repo = tmp_path / "project"+ repo.mkdir()+ external = tmp_path / "shared"+ external.mkdir()+ override = external.as_posix() if absolute_override else "../shared"+ (repo / "settings.gradle.kts").write_text(+ 'include("shared", "app")\n'+ f'project(":shared").projectDir = file("{override}")\n'+ )+ app_path = _make_java_class(repo, "app", "com.example", "App")+ _make_java_class(external, "", "com.external", "Shared")+ monkeypatch.chdir(tmp_path)++ index = build_jvm_gradle_index(Path("project") if relative_repo else repo)++ assert index.projects["shared"].root_dir == "../shared"+ assert "main" in index.projects["shared"].source_sets+ assert index.projects["app"].root_dir == "app"+ assert index.lookup_class("com.example.App") == [app_path]+ assert index.lookup_class("com.external.Shared") == []++ @pytest.mark.parametrize("relative_repo", [False, True])+ def test_symlinked_module_outside_repo(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, relative_repo: bool+ ) -> None:+ repo = tmp_path / "project"+ repo.mkdir()+ external = tmp_path / "shared"+ external.mkdir()+ _make_java_class(external, "", "com.external", "Shared")+ try:+ (repo / "shared").symlink_to(external, target_is_directory=True)+ except OSError as exc:+ pytest.skip(f"Directory symlinks unavailable: {exc}")+ (repo / "settings.gradle.kts").write_text('include("shared", "app")\n')+ app_path = _make_java_class(repo, "app", "com.example", "App")+ monkeypatch.chdir(tmp_path)++ index = build_jvm_gradle_index(Path("project") if relative_repo else repo)++ assert index.projects["shared"].root_dir == "shared"+ assert "main" in index.projects["shared"].source_sets+ assert index.lookup_class("com.example.App") == [app_path]+ assert index.lookup_class("com.external.Shared") == []+def test_discovers_java_and_kotlin_files(self, tmp_path: Path) -> None:(tmp_path / "settings.gradle.kts").write_text('include("app")\n')(tmp_path / "build.gradle.kts").write_text("// root\n")