|
37 | 37 |
|
38 | 38 | π Repository for automated Java code migration research, part of the [MigrationBench](https://huggingface.co/collections/AmazonScience/migrationbench-68125452fc21a4564b92b6c3) project. |
39 | 39 |
|
| 40 | +<!-- toc --> |
40 | 41 |
|
41 | | -## π¦ Packages |
| 42 | +- [1. Overview](#1-overview) |
| 43 | +- [2. MigrationBench Datasets](#2-migrationbench-datasets) |
| 44 | +- [3. Installation](#3-installation) |
| 45 | + * [3.1 Prerequisites](#31-prerequisites) |
| 46 | + * [3.2 Install Package](#32-install-package) |
| 47 | +- [4. Usage](#4-usage) |
| 48 | + * [4.1 Agent Types](#41-agent-types) |
| 49 | + * [4.2 Running Migration](#42-running-migration) |
| 50 | + * [4.3 Command Line Options](#43-command-line-options) |
| 51 | +- [5. Data](#5-data) |
| 52 | +- [6. Resources](#6-resources) |
| 53 | +- [7. Citation](#7-citation) |
42 | 54 |
|
43 | | -This repository contains **two** sub-packages to conduct Java code migration with LLMs: |
| 55 | +<!-- tocstop --> |
44 | 56 |
|
45 | | -### 1. π€ [JavaMigrationAgent](./java_migration_agent) |
| 57 | +## 1. Overview |
46 | 58 |
|
47 | | -[**JavaMigrationAgent**](./java_migration_agent) is an LLM-based agent to automate Java 8 to Java 17 (21) migration, |
48 | | -built on top of the [Strands Agents](https://strandsagents.com/latest/) framework. |
| 59 | +**JavaMigrationAgent** is a library for automated code migration from Java 8 to Java 17 (21) using LLM-based agents built on the [Strands Agents](https://strandsagents.com/latest/) framework. |
49 | 60 |
|
50 | | -- It supports multiple migration strategies including baseline, PE (prompt engineering), RAG, and a hybrid approach (More cost effective). |
| 61 | +It provides multiple agent strategies for migration: |
| 62 | +1. **Baseline**: Direct LLM-based migration |
| 63 | +1. **PE (Prompt Engineering)** (Baseline + PE): Baseline with enhanced prompts for dependency updates |
| 64 | +1. **RAG** (Baseline + PE + RAG): Uses retrieval-augmented generation for dependency version lookup |
| 65 | +1. **Hybrid** (Seed change, followed by baseline + PE): Pre-processes dependencies before LLM migration (More cost effective) |
51 | 66 |
|
52 | | -### 2. π§ [SDFeedback](./self_debug) |
| 67 | +The agent relies on the [MigrationBench](https://github.com/amazon-science/MigrationBench) package for evaluation. |
53 | 68 |
|
54 | | -[**SDFeedback**](./self_debug) runs code migration implementation with LLMs by providing self debugging feedback, |
55 | | -motivated by the [Teaching Large Language Models to Self-Debug](https://arxiv.org/abs/2304.05128) paper. |
| 69 | +## 2. [π€ MigrationBench](https://huggingface.co/collections/AmazonScience/migrationbench-68125452fc21a4564b92b6c3) Datasets |
56 | 70 |
|
57 | | -- It includes both single-job and batch processing capabilities with AWS EMRS support. |
| 71 | +| Index | Dataset | Size | Notes | |
| 72 | +|-------|-----------------------------------------------|-------|-----------------------------------------------------------------------------------------------------| |
| 73 | +| 1 | [π€ AmazonScience/migration-bench-java-full](https://huggingface.co/datasets/AmazonScience/migration-bench-java-full) | 5,102 | Each repo has a test directory or at least one test case | |
| 74 | +| 2 | [π€ AmazonScience/migration-bench-java-selected](https://huggingface.co/datasets/AmazonScience/migration-bench-java-selected) | 300 | A **subset** of migration-bench-java-full | |
58 | 75 |
|
| 76 | +## 3. Installation |
59 | 77 |
|
60 | | -## π Data |
| 78 | +### 3.1 Prerequisites |
| 79 | + |
| 80 | +Verify you have `java 17` and `maven 3.9.6` installed: |
| 81 | + |
| 82 | +```bash |
| 83 | +# java |
| 84 | +$ java --version |
| 85 | +openjdk 17.0.15 2025-04-15 LTS |
| 86 | +OpenJDK Runtime Environment Corretto-17.0.15.6.1 (build 17.0.15+6-LTS) |
| 87 | +OpenJDK 64-Bit Server VM Corretto-17.0.15.6.1 (build 17.0.15+6-LTS, mixed mode, sharing) |
| 88 | +``` |
| 89 | + |
| 90 | +```bash |
| 91 | +# maven |
| 92 | +$ mvn --version |
| 93 | +Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) |
| 94 | +Maven home: /usr/local/bin/apache-maven-3.9.6 |
| 95 | +Java version: 17.0.15, vendor: Amazon.com Inc., runtime: /usr/lib/jvm/java-17-amazon-corretto.x86_64 |
| 96 | +``` |
| 97 | +If you haven't done it yet, follow the instructions in [MigrationBench](https://github.com/amazon-science/MigrationBench) to install Maven. |
| 98 | + |
| 99 | +### 3.2 Install Package |
| 100 | + |
| 101 | +```bash |
| 102 | +# cd .../JavaMigration/ |
| 103 | + |
| 104 | +pip install -r requirements.txt -e . |
| 105 | +``` |
| 106 | + |
| 107 | +Or with uv: |
| 108 | + |
| 109 | +```bash |
| 110 | +# cd .../JavaMigration/ |
| 111 | + |
| 112 | +uv pip install -e . |
| 113 | +``` |
| 114 | + |
| 115 | +## 4. Usage |
| 116 | + |
| 117 | +See the full binary script at [src/java_migration_agent/main.py](https://github.com/amazon-science/JavaMigration/blob/main/src/java_migration_agent/main.py). |
| 118 | + |
| 119 | + |
| 120 | +### 4.1 Agent Types |
| 121 | + |
| 122 | +| Agent Type | Description | |
| 123 | +|------------|-------------| |
| 124 | +| `baseline` | Direct LLM migration with `mvn clean verify` | |
| 125 | +| `pe` | Baseline with prompt engineering for dependency updates | |
| 126 | +| `rag` | Uses dependency version lookup tool for migration | |
| 127 | +| `hybrid` | Pre-processes pom.xml dependencies before LLM migration | |
| 128 | + |
| 129 | +### 4.2 Running Migration |
| 130 | + |
| 131 | +Run batch migration on the MigrationBench dataset: |
| 132 | + |
| 133 | +```bash |
| 134 | +python -m java_migration_agent \ |
| 135 | + --agent-type baseline \ |
| 136 | + --exp-id exp-001 \ |
| 137 | + --hf-dataset AmazonScience/migration-bench-java-selected \ |
| 138 | + --model-id global.anthropic.claude-sonnet-4-5-20250929-v1:0 \ |
| 139 | + --max-workers 8 \ |
| 140 | + --output-dir ./migration_results |
| 141 | +``` |
| 142 | + |
| 143 | +### 4.3 Command Line Options |
| 144 | + |
| 145 | + |
| 146 | +| Flag | Type | Default | Description | |
| 147 | +|--------|------|---------|-------------| |
| 148 | +| `--agent-type` | `str` | (required) | Agent type: `baseline`, `pe`, `rag`, or `hybrid` | |
| 149 | +| `--exp-id` | `str` | (required) | Experiment identifier for organizing results | |
| 150 | +| `--hf-dataset` | `str` | `AmazonScience/migration-bench-java-selected` | HuggingFace dataset name | |
| 151 | +| `--model-id` | `str` | `global.anthropic.claude-sonnet-4-5-20250929-v1:0` | Bedrock model ID | |
| 152 | +| `--temperature` | `float` | `1.0` | Model temperature | |
| 153 | +| `--max-messages` | `int` | `80` | Maximum messages per conversation | |
| 154 | +| `--max-workers` | `int` | `8` | Maximum parallel workers | |
| 155 | +| `--output-dir` | `str` | `./migration_results` | Output directory for results | |
| 156 | + |
| 157 | +## 5. π Data |
61 | 158 |
|
62 | 159 | Agent trajectories and execution results are stored in the `data/` folder. |
63 | 160 |
|
64 | | -## π Resources |
| 161 | +## 6. π Resources |
65 | 162 |
|
66 | 163 | 1. π€ [MigrationBench (Hugging Face)](https://huggingface.co/collections/AmazonScience/migrationbench-68125452fc21a4564b92b6c3) |
67 | 164 | 1. π» [MigrationBench (GitHub)](https://github.com/amazon-science/MigrationBench) |
68 | 165 | 1. π [arXiv Paper](https://arxiv.org/abs/2505.09569) |
69 | 166 |
|
70 | 167 |
|
71 | | -## π Citation |
| 168 | +## 7. π Citation |
72 | 169 |
|
73 | 170 | ```bibtex |
74 | 171 | @misc{liu2025migrationbenchrepositorylevelcodemigration, |
|
0 commit comments