From c50d2a1c0818a5420c0635a8af7edf1d4a1860e3 Mon Sep 17 00:00:00 2001 From: danusha2345 Date: Sun, 30 Aug 2026 12:13:38 +0300 Subject: [PATCH] fix: index Java packages named build (#1642) --- CHANGELOG.md | 4 ++++ __tests__/extraction.test.ts | 33 +++++++++++++++++++++++++++++++++ src/extraction/index.ts | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca5b9ff1..8eb3330d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixes + +- Java packages named `build` under standard main and test source roots are now indexed without pulling Gradle or Maven build output into the graph. (#1642) + ## [1.6.0] - 2026-08-26 diff --git a/__tests__/extraction.test.ts b/__tests__/extraction.test.ts index ad0ba2374..991309c27 100644 --- a/__tests__/extraction.test.ts +++ b/__tests__/extraction.test.ts @@ -7637,6 +7637,39 @@ describe('Nested non-submodule git repos', () => { expect(ig.ignores('dist/')).toBe(true); // valid rule survives expect(ig.ignores('src/app.ts')).toBe(false); }); + + it('keeps Java packages named build while excluding build output (#1642)', () => { + const sourceFile = 'module/src/main/java/com/acme/build/RealtimePlusService.java'; + const testFile = 'module/src/test/java/com/acme/build/RealtimePlusServiceTest.java'; + const outputFile = 'module/build/generated/Generated.java'; + + for (const rel of [sourceFile, testFile, outputFile]) { + const abs = path.join(tempDir, rel); + fs.mkdirSync(path.dirname(abs), { recursive: true }); + fs.writeFileSync(abs, 'class Example {}\n'); + } + + const scope = buildScopeIgnore(tempDir); + expect(scope.ignores(sourceFile)).toBe(false); + expect(scope.ignores(testFile)).toBe(false); + expect(scope.ignores(outputFile)).toBe(true); + + const files = scanDirectory(tempDir); + expect(files).toContain(sourceFile); + expect(files).toContain(testFile); + expect(files).not.toContain(outputFile); + }); + + it('lets an explicit .gitignore exclude a Java package named build (#1642)', () => { + const sourceFile = 'src/main/java/com/acme/build/Hidden.java'; + const abs = path.join(tempDir, sourceFile); + fs.mkdirSync(path.dirname(abs), { recursive: true }); + fs.writeFileSync(abs, 'class Hidden {}\n'); + fs.writeFileSync(path.join(tempDir, '.gitignore'), 'src/main/java/**/build/\n'); + + expect(buildScopeIgnore(tempDir).ignores(sourceFile)).toBe(true); + expect(scanDirectory(tempDir)).not.toContain(sourceFile); + }); }); // ============================================================================= diff --git a/src/extraction/index.ts b/src/extraction/index.ts index 93be48352..a62381414 100644 --- a/src/extraction/index.ts +++ b/src/extraction/index.ts @@ -227,6 +227,12 @@ const DEFAULT_IGNORE_PATTERNS: string[] = [ 'bazel-*/', // Bazel output symlink trees // Android resource dirs at any depth, with their qualifier variants (#1047). ...ANDROID_RES_TYPES.map((t) => `**/res/${t}*/`), + // `build` is also a legal Java package segment. Keep it under conventional + // Java source roots while continuing to exclude module/build output (#1642). + '!**/src/main/java/**/build/', + '!**/src/main/java/**/build/**', + '!**/src/test/java/**/build/', + '!**/src/test/java/**/build/**', ]; /** True if `buf` decodes as strict UTF-8 (no invalid byte sequences). */