diff --git a/graphify/manifest_ingest.py b/graphify/manifest_ingest.py index bffb7bc3b..58c1620ee 100644 --- a/graphify/manifest_ingest.py +++ b/graphify/manifest_ingest.py @@ -320,7 +320,10 @@ def _parse_pom(text: str) -> dict | None: version = _resolve(version) name = f"{gid}:{aid}" if gid else aid deps: list[str] = [] - for dep in root.findall(".//dependencies/dependency"): + # Only the project's own (and those of its profiles) are + # dependencies. only pins versions, and a plugin's + # belong to the build tool. + for dep in root.findall("dependencies/dependency") + root.findall("profiles/profile/dependencies/dependency"): da = _resolve(dep.findtext("artifactId")) dg = _resolve(dep.findtext("groupId")) if da: diff --git a/tests/test_manifest_ingest.py b/tests/test_manifest_ingest.py index 5ddd85583..daec627bb 100644 --- a/tests/test_manifest_ingest.py +++ b/tests/test_manifest_ingest.py @@ -75,6 +75,29 @@ def test_pom_parses_artifact_and_deps(tmp_path): assert any(e["target"] == "pkg_org_lib_core" for e in r["edges"]) + +def test_pom_deps_exclude_managed_and_plugin_dependencies(tmp_path): + # only pins versions and a plugin's are + # the build tool's; neither is a dependency of the project. Profile + # dependencies are. + dep = "{}{}" + p = _write(tmp_path / "pom.xml", + '\n' + ' com.acmeservice1.0\n' + f' {dep.format("com.google.guava", "guava")}' + '\n' + f' {dep.format("org.slf4j", "slf4j-api")}\n' + ' maven-surefire-plugin\n' + f' {dep.format("org.junit.platform", "junit-platform-surefire-provider")}\n' + ' \n' + f' pg{dep.format("org.postgresql", "postgresql")}' + '\n' + '\n') + r = extract_package_manifest(p) + assert {e["target"] for e in r["edges"] if e["relation"] == "depends_on"} == { + "pkg_org_slf4j_slf4j_api", "pkg_org_postgresql_postgresql", + } + # ── #1377: a package referenced by N manifests is ONE node ─────────────────── def test_apm_dependency_collapses_to_single_canonical_node(tmp_path):