fix(maven): match declarations in the project namespace (#12672)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 01:54:59 +00:00
1 parent 070d6420ec
commit 0ab693fe81
4 files changed
+27 -15

No files matched your search

+3 -2
View File
@@ -21,8 +21,9 @@ requires an absolute filesystem path and preserves that exact selection:
}
```
REA classifies files by their content. A well-formed Maven `<project>` document
is `maven-pom`. A Gradle metadata object starts with `formatVersion`.
REA classifies files by their content. A Maven `<project>` uses the Maven POM
namespace or legacy unqualified elements. REA reads structural declarations
in the project's namespace. A Gradle metadata object starts with `formatVersion`.
Version `1.1` can omit `component` and `variants`. For other revisions, REA
also requires a `component` object or `variants` array as format evidence.
[Gradle Module Metadata 1.1 specification](https://github.com/gradle/gradle/blob/v9.2.1/platforms/documentation/docs/src/docs/design/gradle-module-metadata-latest-specification.md#contents)
+5 -5
View File
@@ -623,11 +623,11 @@ it("refuses a document type declaration", () => {
);
});
it("refuses XML that is not a Maven project", () => {
expectFailure(
"<module><artifactId>demo</artifactId></module>",
"unsupported",
);
it.each([
"<module><artifactId>demo</artifactId></module>",
'<project xmlns:ext="urn:example"><ext:artifactId>demo</ext:artifactId></project>',
])("refuses XML that is not a Maven project: %s", (source) => {
expectFailure(source, "unsupported");
});
it("refuses a POM with two top-level dependencies blocks", () => {
+8 -6
View File
@@ -49,8 +49,13 @@ const childElements = (element: Element): Element[] => {
return children;
};
const childrenNamed = (element: Element, local: string): Element[] =>
childElements(element).filter((child) => child.localName === local);
const childrenNamed = (element: Element, ...names: string[]): Element[] =>
childElements(element).filter(
(child) =>
(child.namespaceURI ?? "") === (element.namespaceURI ?? "") &&
child.localName !== null &&
names.includes(child.localName),
);
const soleNamed = (element: Element, local: string): Element | undefined => {
const matches = childrenNamed(element, local);
@@ -73,10 +78,7 @@ const isMavenProjectRoot = (root: Node | null): root is Element => {
if (root.namespaceURI === MAVEN_POM_NAMESPACE) return true;
return (
(root.namespaceURI === null || root.namespaceURI === "") &&
childElements(root).some(
(child) =>
child.localName === "modelVersion" || child.localName === "artifactId",
)
childrenNamed(root, "modelVersion", "artifactId").length > 0
);
};
@@ -25,11 +25,18 @@ const bundleOutputSchema = contractNamed(
).outputSchema;
cliTest(
"preserves qualified POM property keys beside their references through CLI, MCP and retained Evidence",
"distinguishes POM declaration namespaces and preserves qualified property keys through CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-maven-property-keys-");
const path = join(root, "pom.xml");
const bytes = Buffer.from(qualifiedMavenPropertiesFixture);
const bytes = Buffer.from(
qualifiedMavenPropertiesFixture
.replace("<groupId>", "<a:groupId>foreign</a:groupId><groupId>")
.replace(
"<dependencies>",
"<dependencies><a:dependency><artifactId>foreign</artifactId></a:dependency>",
),
);
await writeFile(path, bytes);
const result = await cli.run({
arguments: ["inspect-maven-gradle-metadata", path, "--json"],
@@ -37,6 +44,8 @@ cliTest(
expect(result.exitCode, result.stdout + result.stderr).toBe(0);
const cliEvidence = outputSchema.parse(result.json);
const report = cliEvidence.normalized_result;
expect(report.coordinates.group_id).toBe("example");
expect(report.dependencies).toHaveLength(1);
expect(report.properties).toEqual([
{ name: "revision", value: "0", value_credentials_redacted: false },
{ name: "a:revision", value: "11", value_credentials_redacted: false },