Skip to content

Commit 8e2e1c4

Browse files
authored
Merge pull request #41 from codeflash-ai/docs/update-java-support
docs: add Java support to setup skill, optimize skill, and stop hook
2 parents 6dce808 + 4b5da35 commit 8e2e1c4

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

scripts/suggest-optimize.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ fi
9595
# Determine which language families actually had changes
9696
HAS_PYTHON_CHANGES="false"
9797
HAS_JS_CHANGES="false"
98+
HAS_JAVA_CHANGES="false"
9899
if echo "$CHANGED_FILES" | grep -qE '\.py$'; then
99100
HAS_PYTHON_CHANGES="true"
100101
fi
101102
if echo "$CHANGED_FILES" | grep -qE '\.(js|ts|jsx|tsx)$'; then
102103
HAS_JS_CHANGES="true"
103104
fi
105+
if echo "$CHANGED_FILES" | grep -qE '\.java$'; then
106+
HAS_JAVA_CHANGES="true"
107+
fi
104108

105109
# Dedup: don't trigger twice for the same set of changes.
106110
SEEN_MARKER="$TRANSCRIPT_DIR/codeflash-seen"
@@ -130,6 +134,13 @@ if [ "$HAS_JS_CHANGES" = "true" ]; then
130134
exit 0
131135
fi
132136

137+
# --- Java project path ----------------------------------------------------
138+
if [ "$HAS_JAVA_CHANGES" = "true" ]; then
139+
MESSAGE="Java files were changed in a recent commit. Use the codeflash:optimize skill WITHOUT ANY ARGUMENTS to optimize the Java code for performance."
140+
jq -nc --arg reason "$MESSAGE" '{"decision": "block", "reason": $reason, "systemMessage": $reason}'
141+
exit 0
142+
fi
143+
133144
# --- Python project path ---------------------------------------------------
134145
if [ "$HAS_PYTHON_CHANGES" != "true" ]; then
135146
exit 0

skills/optimize/SKILL.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ Disambiguate the file and function from `$ARGUMENTS` if --file and/or --function
1414

1515
## Correct cwd
1616

17-
Based on the language of the file/s of concern, Find the `pyproject.toml` (Python) /`package.json` (JS/TS) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).
17+
Based on the language of the file/s of concern, find the config file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff):
18+
- **Python**: `pyproject.toml`
19+
- **JS/TS**: `package.json`
20+
- **Java**: `pom.xml` or `build.gradle`/`build.gradle.kts`
1821

19-
`cd` into the directory where you found the `pyproject.toml`/`package.json`.
22+
`cd` into the directory where you found the config file.
2023

2124
## Build the command
2225

skills/setup/SKILL.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,54 @@ Merge this into the existing `package.json` object — do not overwrite other fi
9090

9191
### Check 1c: Project Configuration (Java)
9292

93-
Find the `pom.xml` (if it's a maven project) or `build.gradle.kts` (if it's a gradle project) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).
93+
Find the `pom.xml` (Maven) or `build.gradle`/`build.gradle.kts` (Gradle) file closest to the file/files of concern (the file passed to codeflash --file or the files which changed in the diff).
9494

95+
For Maven projects, check if `codeflash.*` properties exist in the `<properties>` section of `pom.xml`. For Gradle projects, check if `codeflash.*` properties exist in `gradle.properties`.
96+
97+
- If the build file exists but lacks codeflash properties, run **Configuration Discovery (Java)** below and add them.
98+
- If no build file exists, exit early — Java projects require Maven or Gradle.
99+
100+
#### Configuration Discovery (Java)
101+
102+
Perform the following discovery steps relative to the directory containing the target `pom.xml` or `build.gradle`:
103+
104+
**Discover source root:**
105+
Find the relative path to the Java source directory. Look for:
106+
1. Standard Maven/Gradle layout: `src/main/java`
107+
2. Custom `sourceDirectory` in `pom.xml`
108+
3. Fallback to `src` if it exists
109+
Default to `src/main/java`.
110+
111+
**Discover test root:**
112+
Find the relative path to the Java test directory. Look for:
113+
1. Standard layout: `src/test/java`
114+
2. Custom `testSourceDirectory` in `pom.xml`
115+
3. Directories named `test` or `tests`
116+
Default to `src/test/java`.
117+
118+
**Write the configuration:**
119+
120+
For Maven projects, add `codeflash.*` properties to the `<properties>` section of `pom.xml`. Only write properties that differ from defaults:
121+
122+
```xml
123+
<properties>
124+
<!-- Only add if source root is NOT src/main/java -->
125+
<codeflash.moduleRoot>src/main/java</codeflash.moduleRoot>
126+
<!-- Only add if test root is NOT src/test/java -->
127+
<codeflash.testsRoot>src/test/java</codeflash.testsRoot>
128+
</properties>
129+
```
130+
131+
For Gradle projects, add properties to `gradle.properties` (create the file if it doesn't exist):
132+
133+
```properties
134+
codeflash.moduleRoot=src/main/java
135+
codeflash.testsRoot=src/test/java
136+
```
137+
138+
If the project uses the standard `src/main/java` and `src/test/java` layout, no config properties are needed — Codeflash auto-detects the defaults.
139+
140+
After writing, confirm the configuration with the user before proceeding.
95141

96142
### Check 2: Installation
97143

0 commit comments

Comments
 (0)