Skip to content

Commit 96b99ea

Browse files
Merge pull request #1732 from codeflash-ai/fix/java/exclude-apidocs-from-discovery
fix(java): exclude apidocs and javadoc from file discovery
2 parents 8b0f1ea + c111635 commit 96b99ea

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

codeflash/languages/java/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def default_file_extension(self) -> str:
9191

9292
@property
9393
def dir_excludes(self) -> frozenset[str]:
94-
return frozenset({"target", "build", ".gradle", ".mvn", ".idea"})
94+
return frozenset({"target", "build", ".gradle", ".mvn", ".idea", "apidocs", "javadoc"})
9595

9696
def postprocess_generated_tests(
9797
self, generated_tests: GeneratedTestsList, test_framework: str, project_root: Path, source_file_path: Path

tests/test_languages/test_java/test_support.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from codeflash.languages.base import Language, LanguageSupport
88
from codeflash.languages.java.support import JavaSupport, get_java_support
9+
from codeflash.discovery.functions_to_optimize import get_files_for_language
910

1011

1112
class TestJavaSupportProtocol:
@@ -132,3 +133,73 @@ def test_discover_functions_from_fixture(self, support, java_fixture_path: Path)
132133

133134
functions = support.discover_functions(calculator_file)
134135
assert len(functions) > 0
136+
137+
138+
class TestJavaDirExcludes:
139+
"""Tests that Java-specific directories are excluded from file discovery."""
140+
141+
@pytest.fixture
142+
def support(self):
143+
return get_java_support()
144+
145+
def test_dir_excludes_contains_apidocs(self, support):
146+
"""apidocs (generated Javadoc HTML) must not be walked during --all."""
147+
assert "apidocs" in support.dir_excludes
148+
149+
def test_dir_excludes_contains_javadoc(self, support):
150+
"""javadoc directory must not be walked during --all."""
151+
assert "javadoc" in support.dir_excludes
152+
153+
def test_apidocs_js_files_not_discovered(self, tmp_path: Path):
154+
"""JS files inside apidocs/ must not appear in Java file discovery."""
155+
# Simulate a Java project with an apidocs directory that contains .js files
156+
src_dir = tmp_path / "src" / "main" / "java"
157+
src_dir.mkdir(parents=True)
158+
(src_dir / "Foo.java").write_text("public class Foo { public void bar() {} }")
159+
160+
apidocs_dir = tmp_path / "apidocs" / "script-files"
161+
apidocs_dir.mkdir(parents=True)
162+
(apidocs_dir / "jquery-3.7.1.min.js").write_text("/* jQuery */")
163+
(apidocs_dir / "search.js").write_text("/* search */")
164+
165+
files = get_files_for_language(tmp_path, language=Language.JAVA)
166+
file_names = [f.name for f in files]
167+
168+
assert "Foo.java" in file_names
169+
assert "jquery-3.7.1.min.js" not in file_names
170+
assert "search.js" not in file_names
171+
172+
def test_javadoc_files_not_discovered(self, tmp_path: Path):
173+
"""Files inside javadoc/ must not appear in Java file discovery."""
174+
src_dir = tmp_path / "src"
175+
src_dir.mkdir(parents=True)
176+
(src_dir / "Bar.java").write_text("public class Bar { public void baz() {} }")
177+
178+
javadoc_dir = tmp_path / "javadoc"
179+
javadoc_dir.mkdir(parents=True)
180+
(javadoc_dir / "index.html").write_text("<html></html>")
181+
# Also create a .java file here (edge case: javadoc may contain source snippets)
182+
(javadoc_dir / "Snippet.java").write_text("public class Snippet {}")
183+
184+
files = get_files_for_language(tmp_path, language=Language.JAVA)
185+
file_names = [f.name for f in files]
186+
187+
assert "Bar.java" in file_names
188+
assert "Snippet.java" not in file_names
189+
190+
def test_apidocs_excluded_in_all_mode(self, tmp_path: Path):
191+
"""In --all mode (language=None), apidocs .js files must also be excluded."""
192+
src_dir = tmp_path / "src"
193+
src_dir.mkdir(parents=True)
194+
(src_dir / "Hello.java").write_text("public class Hello { public void hi() {} }")
195+
196+
apidocs_dir = tmp_path / "apidocs"
197+
apidocs_dir.mkdir(parents=True)
198+
(apidocs_dir / "jquery.min.js").write_text("/* jQuery */")
199+
200+
# language=None simulates --all mode
201+
files = get_files_for_language(tmp_path, language=None)
202+
file_names = [f.name for f in files]
203+
204+
assert "Hello.java" in file_names
205+
assert "jquery.min.js" not in file_names

0 commit comments

Comments
 (0)