Skip to content

Commit d08f662

Browse files
Merge pull request #1199 from codeflash-ai/omni-java
codeflash-omni-java
2 parents 4b8effa + 188b09f commit d08f662

207 files changed

Lines changed: 55230 additions & 1285 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/rules/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Core protocol in `languages/base.py`. Each language (`PythonSupport`, `JavaScrip
7373
|----------|----------------|---------|
7474
| Identity | `language`, `file_extensions`, `default_file_extension` | Language identification |
7575
| Identity | `comment_prefix`, `dir_excludes` | Language conventions |
76-
| AI service | `default_language_version` | Language version for API payloads (`None` for Python, `"ES2022"` for JS) |
76+
| AI service | `language_version` | Detected language version for API payloads (e.g., `"3.11.0"` for Python, `"17"` for Java) |
7777
| AI service | `valid_test_frameworks` | Allowed test frameworks for validation |
7878
| Discovery | `discover_functions`, `discover_tests` | Find optimizable functions and their tests |
7979
| Discovery | `adjust_test_config_for_discovery` | Pre-discovery config adjustment (no-op default) |
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: E2E - Java Fibonacci (No Git)
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'codeflash/languages/java/**'
7+
- 'codeflash/languages/base.py'
8+
- 'codeflash/languages/registry.py'
9+
- 'codeflash/optimization/**'
10+
- 'codeflash/verification/**'
11+
- 'code_to_optimize/java/**'
12+
- 'codeflash-java-runtime/**'
13+
- 'tests/scripts/end_to_end_test_java_fibonacci.py'
14+
- '.github/workflows/e2e-java-fibonacci-nogit.yaml'
15+
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref_name }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
java-fibonacci-optimization-no-git:
24+
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
25+
26+
runs-on: ubuntu-latest
27+
env:
28+
CODEFLASH_AIS_SERVER: prod
29+
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
30+
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
31+
COLUMNS: 110
32+
MAX_RETRIES: 3
33+
RETRY_DELAY: 5
34+
EXPECTED_IMPROVEMENT_PCT: 70
35+
CODEFLASH_END_TO_END: 1
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
with:
40+
ref: ${{ github.event.pull_request.head.ref }}
41+
repository: ${{ github.event.pull_request.head.repo.full_name }}
42+
fetch-depth: 0
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Validate PR
46+
env:
47+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
48+
PR_STATE: ${{ github.event.pull_request.state }}
49+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
50+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
51+
run: |
52+
if git diff --name-only "$BASE_SHA" "$HEAD_SHA" | grep -q "^.github/workflows/"; then
53+
echo "⚠️ Workflow changes detected."
54+
echo "PR Author: $PR_AUTHOR"
55+
if [[ "$PR_AUTHOR" == "misrasaurabh1" || "$PR_AUTHOR" == "KRRT7" ]]; then
56+
echo "✅ Authorized user ($PR_AUTHOR). Proceeding."
57+
elif [[ "$PR_STATE" == "open" ]]; then
58+
echo "✅ PR is open. Proceeding."
59+
else
60+
echo "⛔ Unauthorized user ($PR_AUTHOR) attempting to modify workflows. Exiting."
61+
exit 1
62+
fi
63+
else
64+
echo "✅ No workflow file changes detected. Proceeding."
65+
fi
66+
67+
- name: Set up JDK 11
68+
uses: actions/setup-java@v4
69+
with:
70+
java-version: '11'
71+
distribution: 'temurin'
72+
cache: maven
73+
74+
- name: Set up Python 3.11 for CLI
75+
uses: astral-sh/setup-uv@v6
76+
with:
77+
python-version: 3.11.6
78+
79+
- name: Install dependencies (CLI)
80+
run: uv sync
81+
82+
- name: Build codeflash-runtime JAR
83+
run: |
84+
cd codeflash-java-runtime
85+
mvn clean package -q -DskipTests
86+
mvn install -q -DskipTests
87+
88+
- name: Verify Java installation
89+
run: |
90+
java -version
91+
mvn --version
92+
93+
- name: Remove .git
94+
run: |
95+
if [ -d ".git" ]; then
96+
sudo rm -rf .git
97+
echo ".git directory removed."
98+
else
99+
echo ".git directory does not exist."
100+
exit 1
101+
fi
102+
103+
- name: Run Codeflash to optimize Fibonacci
104+
run: |
105+
uv run python tests/scripts/end_to_end_test_java_fibonacci.py
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Java E2E Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- omni-java
8+
paths:
9+
- 'codeflash/languages/java/**'
10+
- 'tests/test_languages/test_java*.py'
11+
- 'code_to_optimize/java/**'
12+
- '.github/workflows/java-e2e-tests.yml'
13+
pull_request:
14+
paths:
15+
- 'codeflash/languages/java/**'
16+
- 'tests/test_languages/test_java*.py'
17+
- 'code_to_optimize/java/**'
18+
- '.github/workflows/java-e2e-tests.yml'
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref_name }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
java-e2e:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Set up JDK 11
35+
uses: actions/setup-java@v4
36+
with:
37+
java-version: '11'
38+
distribution: 'temurin'
39+
cache: maven
40+
41+
- name: Install uv
42+
uses: astral-sh/setup-uv@v6
43+
44+
- name: Set up Python environment
45+
run: |
46+
uv venv --seed
47+
uv sync
48+
49+
- name: Verify Java installation
50+
run: |
51+
java -version
52+
mvn --version
53+
54+
- name: Build codeflash-runtime JAR
55+
run: |
56+
cd codeflash-java-runtime
57+
mvn clean package -q -DskipTests
58+
mvn install -q -DskipTests
59+
60+
- name: Build Java sample project
61+
run: |
62+
cd code_to_optimize/java
63+
mvn compile -q
64+
65+
- name: Run Java sample project tests
66+
run: |
67+
cd code_to_optimize/java
68+
mvn test -q
69+
70+
- name: Run Java E2E tests
71+
run: |
72+
uv run pytest tests/test_languages/test_java_e2e.py -v --tb=short
73+
74+
- name: Run Java unit tests
75+
run: |
76+
uv run pytest tests/test_languages/test_java/ -v --tb=short -x

.github/workflows/unit-tests.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ jobs:
4040
fetch-depth: 0
4141
token: ${{ secrets.GITHUB_TOKEN }}
4242

43+
- name: Set up JDK 11
44+
uses: actions/setup-java@v4
45+
with:
46+
java-version: '11'
47+
distribution: 'temurin'
48+
cache: maven
49+
50+
- name: Build codeflash-runtime JAR
51+
run: |
52+
cd codeflash-java-runtime
53+
mvn clean package -q -DskipTests
54+
mvn install -q -DskipTests
55+
4356
- name: Install uv
4457
uses: astral-sh/setup-uv@v6
4558
with:

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ cython_debug/
164164
.aider*
165165
/js/common/node_modules/
166166
*.xml
167+
# Allow pom.xml in test fixtures for Maven project detection
168+
!tests/test_languages/fixtures/**/pom.xml
169+
# Allow pom.xml in Java sample project
170+
!code_to_optimize/java/pom.xml
171+
# Allow pom.xml in codeflash-java-runtime
172+
!codeflash-java-runtime/pom.xml
167173
*.pem
168174

169175
# Ruff cache
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Codeflash configuration for Java project
2+
3+
[tool.codeflash]
4+
module-root = "src/main/java"
5+
tests-root = "src/test/java"
6+
formatter-cmds = []

code_to_optimize/java/pom.xml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>codeflash-java-sample</artifactId>
9+
<version>1.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>Codeflash Java Sample Project</name>
13+
<description>Sample Java project for testing Codeflash optimization</description>
14+
15+
<properties>
16+
<maven.compiler.source>11</maven.compiler.source>
17+
<maven.compiler.target>11</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<junit.jupiter.version>5.10.0</junit.jupiter.version>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.junit.jupiter</groupId>
25+
<artifactId>junit-jupiter</artifactId>
26+
<version>${junit.jupiter.version}</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.junit.jupiter</groupId>
31+
<artifactId>junit-jupiter-params</artifactId>
32+
<version>${junit.jupiter.version}</version>
33+
<scope>test</scope>
34+
</dependency>
35+
<!-- SQLite JDBC for Codeflash instrumentation -->
36+
<dependency>
37+
<groupId>org.xerial</groupId>
38+
<artifactId>sqlite-jdbc</artifactId>
39+
<version>3.42.0.0</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>com.codeflash</groupId>
44+
<artifactId>codeflash-runtime</artifactId>
45+
<version>1.0.0</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.11.0</version>
56+
<configuration>
57+
<source>11</source>
58+
<target>11</target>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<groupId>org.apache.maven.plugins</groupId>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<version>3.1.2</version>
65+
<configuration>
66+
<includes>
67+
<include>**/*Test.java</include>
68+
</includes>
69+
</configuration>
70+
</plugin>
71+
72+
<plugin>
73+
<groupId>org.jacoco</groupId>
74+
<artifactId>jacoco-maven-plugin</artifactId>
75+
<version>0.8.11</version>
76+
<executions>
77+
<execution>
78+
<id>prepare-agent</id>
79+
<goals>
80+
<goal>prepare-agent</goal>
81+
</goals>
82+
</execution>
83+
<execution>
84+
<id>report</id>
85+
<phase>verify</phase>
86+
<goals>
87+
<goal>report</goal>
88+
</goals>
89+
<configuration>
90+
<!-- For multi-module projects, include dependency classes -->
91+
<includes>
92+
<include>**/*.class</include>
93+
</includes>
94+
</configuration>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
</project>

0 commit comments

Comments
 (0)