Skip to content

Commit 4ac49ee

Browse files
authored
Merge pull request #1579 from codeflash-ai/codeflash/optimize-pr1199-2026-02-20T05.34.02
⚡️ Speed up function `_find_java_executable` by 64% in PR #1199 (`omni-java`)
2 parents 5759921 + 6e854a3 commit 4ac49ee

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

codeflash/languages/java/comparator.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
if TYPE_CHECKING:
2121
from codeflash.models.models import TestDiff
2222

23+
_IS_DARWIN = platform.system() == "Darwin"
24+
2325
logger = logging.getLogger(__name__)
2426

2527

@@ -88,16 +90,17 @@ def _find_java_executable() -> str | None:
8890
return str(java_path)
8991

9092
# On macOS, try to get JAVA_HOME from the system helper or Maven
91-
if platform.system() == "Darwin":
93+
if _IS_DARWIN:
9294
# Try to extract Java home from Maven (which always finds it)
9395
try:
9496
result = subprocess.run(["mvn", "--version"], capture_output=True, text=True, timeout=10, check=False)
95-
for line in result.stdout.split("\n"):
96-
if "runtime:" in line:
97-
runtime_path = line.split("runtime:")[-1].strip()
98-
java_path = Path(runtime_path) / "bin" / "java"
99-
if java_path.exists():
100-
return str(java_path)
97+
if result.returncode == 0:
98+
for line in result.stdout.split("\n"):
99+
if "runtime:" in line:
100+
runtime_path = line.split("runtime:")[-1].strip()
101+
java_path = Path(runtime_path) / "bin" / "java"
102+
if java_path.exists():
103+
return str(java_path)
101104
except (subprocess.TimeoutExpired, FileNotFoundError):
102105
pass
103106

0 commit comments

Comments
 (0)