From 869349c48c8ea0dc9bae2a911d0145b9bfda0fc7 Mon Sep 17 00:00:00 2001 From: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:29:09 +0530 Subject: [PATCH 1/2] fix(maven): fall back for Java sources outside the standard roots A module with .java or .kt files outside src/main/{java,kotlin}, src/test/{java,kotlin} and its resolved now gets the blocker 'Maven : Java sources outside the standard roots require full validation'. This covers a build-helper-maven-plugin test root such as src/it/java and a test root set by a parent POM outside the repository. Resources and the Maven wrapper's downloader are not counted. Closes #327 Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> --- docs/using-diffci.md | 1 + src/repo/adapters/maven.ts | 8 +++ .../repo/maven-test-source-directory.test.ts | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/docs/using-diffci.md b/docs/using-diffci.md index 8bdae3b..bd81109 100644 --- a/docs/using-diffci.md +++ b/docs/using-diffci.md @@ -688,6 +688,7 @@ _Module resource and dependency impact contributed by [@FredApps](https://github | `Maven analysis found no pom.xml` | A Java repository built with another tool | No | | `Maven reactor contains no Java sources` | A `pom.xml` with only resources | No | | `Maven …: custom source roots require full validation` | Set ``, or a `` that is interpolated (`${…}`), absolute, outside the module, declared more than once, inside a profile, or inherited from a parent POM | Declare a plain relative `` inside the module, in the module's own ``; DiffCI finds tests there | +| `Maven …: Java sources outside the standard roots require full validation` | A `.java` or `.kt` file in the module outside `src/main/{java,kotlin}`, `src/test/{java,kotlin}` and the module's ``, such as a `src/it/java` root added by `build-helper-maven-plugin` or a test root set by a parent POM outside the repository | Move the files under a standard root, or declare the test root as a plain relative `` in the module's own POM | | `Maven …: parent dependency inheritance requires full validation` | Inherit dependencies from an external parent POM | No | | `Maven …: unresolved dependency coordinates require full validation` | Use a `${property}` version DiffCI cannot resolve | No | diff --git a/src/repo/adapters/maven.ts b/src/repo/adapters/maven.ts index 823b94f..998d5da 100644 --- a/src/repo/adapters/maven.ts +++ b/src/repo/adapters/maven.ts @@ -148,6 +148,14 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution { const sources = owned.filter(file => /\.(?:java|kt)$/.test(file) && (/\/src\/(?:main|test)\/(?:java|kotlin)\//.test("/" + file) || (pom.testRoot !== undefined && file.startsWith(pom.testRoot + "/")))); const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file)); + // Java or Kotlin outside every root DiffCI recognises may still be compiled and run by Maven: a test root + // added by build-helper-maven-plugin, or one set by a parent POM outside the repository. Fail closed (#327). + // Resources (archetype templates, compiler-test inputs) and the Maven wrapper's downloader are not sources. + const known = new Set(sources); + if (owned.some(file => /\.(?:java|kt)$/.test(file) && !known.has(file) && + !/\/src\/(?:main|test)\/resources\//.test("/" + file) && !/(?:^|\/)\.mvn\//.test(file))) { + result.blockers.push(`Maven ${pom.path}: Java sources outside the standard roots require full validation`); + } members.set(pom, sources); resources.set(pom, assets); const anchor = sources[0] ?? assets[0]; diff --git a/tests/repo/maven-test-source-directory.test.ts b/tests/repo/maven-test-source-directory.test.ts index 721d6e8..7da9ac0 100644 --- a/tests/repo/maven-test-source-directory.test.ts +++ b/tests/repo/maven-test-source-directory.test.ts @@ -144,3 +144,56 @@ for (const [name, parentBuild, childBuild, testPath] of [ } finally { rmSync(root, { recursive: true, force: true }); } }); } + +const outsideRoots = /Java sources outside the standard roots require full validation/; + +// #327: Java or Kotlin that Maven may compile and run from a root DiffCI doesn't know falls back, for a library +// change and for a change to that file itself. +for (const [label, extra, buildHelper] of [ + ["a src/it/java test root added by build-helper-maven-plugin", "application/src/it/java/example/AppIT.java", true], + ["a test root set by a parent POM outside the repository", "application/src/integration/java/example/AppIT.java", false], + ["a Kotlin file outside the roots", "application/src/it/kotlin/example/AppIT.kt", false], +] as const) { + test(`Maven falls back for ${label} (#327)`, async () => { + const build = buildHelper + ? "org.codehaus.mojobuild-helper-maven-pluginadd-test-sourcesrc/it/java" + : ""; + const files = reactor(build, "application/src/test/java/example/AppTest.java"); + files[extra] = "package example; class AppIT {}"; + if (label.includes("parent POM")) { + files["application/pom.xml"] = files["application/pom.xml"]!.replace("", "com.acmecompany-parent3"); + } + const root = fixture(files); + try { + const graph = await buildDependencyGraph({ repoPath: root }); + assert.deepEqual(graph.adapterBlockers, ["Maven application/pom.xml: Java sources outside the standard roots require full validation"]); + for (const changed of ["library/src/main/java/example/Library.java", extra]) { + const impact = new ImpactAnalyzer().analyze(delta(changed), graph, graph.profile); + assert.equal(impact.fallbackRequired, true, changed); + assert.ok(impact.fallbackReasons.some((reason) => outsideRoots.test(reason)), impact.fallbackReasons.join("; ")); + } + } finally { rmSync(root, { recursive: true, force: true }); } + }); +} + +test("Maven does not fall back for Java under resources or in the Maven wrapper (#327)", async () => { + const files = reactor("", "application/src/test/java/example/AppTest.java"); + files["application/src/main/resources/archetype-resources/src/main/java/App.java"] = "public class App {}"; + files["application/src/test/resources/compile/Input.java"] = "class Input {}"; + files[".mvn/wrapper/MavenWrapperDownloader.java"] = "public class MavenWrapperDownloader {}"; + const root = fixture(files); + try { + const graph = await buildDependencyGraph({ repoPath: root }); + assert.deepEqual(graph.adapterBlockers, []); + const impact = new ImpactAnalyzer().analyze(delta("library/src/main/java/example/Library.java"), graph, graph.profile); + assert.equal(impact.fallbackRequired, false, impact.fallbackReasons.join("; ")); + } finally { rmSync(root, { recursive: true, force: true }); } +}); + +test("A file under a resolved is inside the roots (#327)", async () => { + const root = fixture(reactor("tests", "application/tests/example/AppTest.java")); + try { + const graph = await buildDependencyGraph({ repoPath: root }); + assert.ok(!graph.adapterBlockers?.some((reason) => outsideRoots.test(reason)), graph.adapterBlockers?.join("; ")); + } finally { rmSync(root, { recursive: true, force: true }); } +}); From 0ed8c98ce94b24ef5e8c4370a785c17e1d5c47b3 Mon Sep 17 00:00:00 2001 From: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:41:33 +0530 Subject: [PATCH 2/2] fix(maven): keep the blocker for resources when build-helper-maven-plugin is configured build-helper-maven-plugin can add a folder under src/{main,test}/resources as a source root, so Java there is only exempt when the POM doesn't configure it. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com> --- src/repo/adapters/maven.ts | 8 ++++++-- tests/repo/maven-test-source-directory.test.ts | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/repo/adapters/maven.ts b/src/repo/adapters/maven.ts index 998d5da..5ba8967 100644 --- a/src/repo/adapters/maven.ts +++ b/src/repo/adapters/maven.ts @@ -17,6 +17,8 @@ interface Pom { declaredTestRoots: string[]; /** Whether a `` sits inside a profile, which may or may not be active. */ profileTestRoot: boolean; + /** Whether the POM configures build-helper-maven-plugin, which can add any folder, resources included, as a source root. */ + buildHelper: boolean; } const DEFAULT_TEST_ROOT = "src/test/java"; @@ -86,6 +88,7 @@ function parsePom(path: string, source: string): Pom { customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java"), testRoot: profileTestRoot ? undefined : resolveTestRoot(dir, declaredTestRoots), declaredTestRoots, profileTestRoot, + buildHelper: xml.includes("build-helper-maven-plugin"), }; } @@ -150,10 +153,11 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution { const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file)); // Java or Kotlin outside every root DiffCI recognises may still be compiled and run by Maven: a test root // added by build-helper-maven-plugin, or one set by a parent POM outside the repository. Fail closed (#327). - // Resources (archetype templates, compiler-test inputs) and the Maven wrapper's downloader are not sources. + // Resources (archetype templates, compiler-test inputs) and the Maven wrapper's downloader are not sources, + // unless build-helper-maven-plugin is configured: it can add a folder under resources as a source root. const known = new Set(sources); if (owned.some(file => /\.(?:java|kt)$/.test(file) && !known.has(file) && - !/\/src\/(?:main|test)\/resources\//.test("/" + file) && !/(?:^|\/)\.mvn\//.test(file))) { + (pom.buildHelper || !/\/src\/(?:main|test)\/resources\//.test("/" + file)) && !/(?:^|\/)\.mvn\//.test(file))) { result.blockers.push(`Maven ${pom.path}: Java sources outside the standard roots require full validation`); } members.set(pom, sources); diff --git a/tests/repo/maven-test-source-directory.test.ts b/tests/repo/maven-test-source-directory.test.ts index 7da9ac0..99cb0e7 100644 --- a/tests/repo/maven-test-source-directory.test.ts +++ b/tests/repo/maven-test-source-directory.test.ts @@ -197,3 +197,14 @@ test("A file under a resolved is inside the roots (#327)", assert.ok(!graph.adapterBlockers?.some((reason) => outsideRoots.test(reason)), graph.adapterBlockers?.join("; ")); } finally { rmSync(root, { recursive: true, force: true }); } }); + +test("Maven falls back for Java under resources when build-helper-maven-plugin could add it as a root (#327)", async () => { + const build = "org.codehaus.mojobuild-helper-maven-pluginadd-test-sourcesrc/test/resources/java"; + const files = reactor(build, "application/src/test/java/example/AppTest.java"); + files["application/src/test/resources/java/example/ResourceIT.java"] = "package example; class ResourceIT {}"; + const root = fixture(files); + try { + const graph = await buildDependencyGraph({ repoPath: root }); + assert.deepEqual(graph.adapterBlockers, ["Maven application/pom.xml: Java sources outside the standard roots require full validation"]); + } finally { rmSync(root, { recursive: true, force: true }); } +});