|
1 | | -# Javalang-analyzing-cli |
| 1 | +# Javalang-analyzing-cli |
| 2 | + |
| 3 | +> A powerful Java code analysis command-line tool designed for research and code quality analysis. |
| 4 | +
|
| 5 | +[](LICENSE) |
| 6 | +[](https://github.com/your-username/Javalang-analyzing-cli/releases) |
| 7 | + |
| 8 | +## 🚀 Quick Start |
| 9 | + |
| 10 | +### Download |
| 11 | + |
| 12 | +Download the latest `Javalang-analyzing-cli-all.jar` from the [Releases](https://github.com/your-username/Javalang-analyzing-cli/releases) page. |
| 13 | + |
| 14 | +This is a **Fat JAR** that includes all dependencies - no additional installation required. |
| 15 | + |
| 16 | +### System Requirements |
| 17 | + |
| 18 | +- **Java 21** or higher |
| 19 | +- Supported OS: Windows, macOS, Linux |
| 20 | + |
| 21 | +### Basic Usage |
| 22 | + |
| 23 | +```bash |
| 24 | +# Check version |
| 25 | +java -jar Javalang-analyzing-cli-all.jar --version |
| 26 | + |
| 27 | +# Show help |
| 28 | +java -jar Javalang-analyzing-cli-all.jar --help |
| 29 | + |
| 30 | +# Analyze test cases and generate LLM context |
| 31 | +java -jar Javalang-analyzing-cli-all.jar ParseTestCaseToLlmContext \ |
| 32 | + --project /path/to/your/java/project \ |
| 33 | + --format json |
| 34 | +``` |
| 35 | + |
| 36 | +## 📋 Supported Tasks |
| 37 | + |
| 38 | +### ParseTestCaseToLlmContext |
| 39 | + |
| 40 | +Parses Java test cases and outputs structured JSON files for LLM code analysis. |
| 41 | + |
| 42 | +**Output includes**: |
| 43 | +- 📝 Test case source code |
| 44 | +- 🔍 Method invocation sequence (DFS traversal) |
| 45 | +- 📦 Production code implementations |
| 46 | +- 🏷️ Statement classification (ASSERT, MOCK, NEW, third-party calls, etc.) |
| 47 | +- 📂 Imported packages list |
| 48 | + |
| 49 | +**Example**: |
| 50 | +```bash |
| 51 | +java -jar Javalang-analyzing-cli-all.jar ParseTestCaseToLlmContext \ |
| 52 | + --project /Users/john/projects/commons-cli \ |
| 53 | + --threads 8 \ |
| 54 | + --format json |
| 55 | +``` |
| 56 | + |
| 57 | +**Output file format**: `project_name:testclass_name:testcase_name.json` |
| 58 | + |
| 59 | +## 📄 Output Example |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "project": "commons-cli", |
| 64 | + "testClassName": "org.apache.commons.cli.ArgumentIsOptionTest", |
| 65 | + "testCaseName": "testOption", |
| 66 | + "parsedStatementsSequence": [ |
| 67 | + "org.apache.commons.cli.CommandLineParser.parse(Options, String[])", |
| 68 | + "ASSERT org.junit.jupiter.api.Assertions.assertTrue(boolean)", |
| 69 | + "GET org.apache.commons.cli.CommandLine.hasOption(String)" |
| 70 | + ], |
| 71 | + "productionFunctionImplementations": [ |
| 72 | + "public boolean hasOption(String opt) { ... }" |
| 73 | + ], |
| 74 | + "testCaseSourceCode": "@Test\npublic void testOption() { ... }", |
| 75 | + "importedPackages": [ |
| 76 | + "org.junit.jupiter.api.Test", |
| 77 | + "org.junit.jupiter.api.Assertions" |
| 78 | + ] |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## ⚙️ Command Line Options |
| 83 | + |
| 84 | +| Option | Description | Default | Example | |
| 85 | +|--------|-------------|---------|---------| |
| 86 | +| `--project` | Project root directory (absolute path) | **Required** | `/home/user/my-project` | |
| 87 | +| `--threads` | Number of threads to use | `0` (auto-detect CPU cores) | `8` | |
| 88 | +| `--format` | Output format | `json` | `json`, `csv`, `md`, `console` | |
| 89 | +| `--lang` | Programming language | `java` | `java` | |
| 90 | +| `--output-file` | Output file path | Console output | `/tmp/results.json` | |
| 91 | +| `--config` | Configuration file path | None | `config.yml` | |
| 92 | +| `--plugin-path` | Plugin directory path | None | `/path/to/plugins` | |
| 93 | + |
| 94 | +## 🏗️ Supported Build Systems |
| 95 | + |
| 96 | +The tool automatically detects the project's build system and configures the appropriate classpath: |
| 97 | + |
| 98 | +- ✅ **Maven**: Automatically parses `pom.xml` and dependencies |
| 99 | +- ✅ **Gradle**: Uses Gradle Tooling API to get project configuration |
| 100 | +- 🔄 **Automatic dependency resolution**: Searches `~/.m2` and `~/.gradle/caches` for missing test dependencies |
| 101 | + |
| 102 | +### Automatically Handled Test Frameworks |
| 103 | + |
| 104 | +- **JUnit 5** (Jupiter) |
| 105 | +- **JUnit 4** |
| 106 | +- **Mockito** |
| 107 | +- **Hamcrest** |
| 108 | +- **AssertJ** |
| 109 | + |
| 110 | +## 🛠️ Advanced Usage |
| 111 | + |
| 112 | +### Configuration File |
| 113 | + |
| 114 | +Create an `analyzer.yml` configuration file: |
| 115 | + |
| 116 | +```yaml |
| 117 | +project: /path/to/project |
| 118 | +threads: 8 |
| 119 | +lang: java |
| 120 | +output: |
| 121 | + format: json |
| 122 | + file: results.json |
| 123 | + |
| 124 | +# Task-specific configuration |
| 125 | +ParseTestCaseToLlmContext: |
| 126 | + outputDirectory: /custom/output/path |
| 127 | + includeDisabledTests: false |
| 128 | +``` |
| 129 | +
|
| 130 | +Using configuration file: |
| 131 | +```bash |
| 132 | +java -jar Javalang-analyzing-cli-all.jar ParseTestCaseToLlmContext --config analyzer.yml |
| 133 | +``` |
| 134 | + |
| 135 | +### Multi-threaded Processing |
| 136 | + |
| 137 | +```bash |
| 138 | +# Use 16 threads for parallel analysis |
| 139 | +java -jar Javalang-analyzing-cli-all.jar ParseTestCaseToLlmContext \ |
| 140 | + --project /large/project \ |
| 141 | + --threads 16 |
| 142 | +``` |
| 143 | + |
| 144 | +### Plugin Extensions |
| 145 | + |
| 146 | +The tool supports extension through Java SPI mechanism: |
| 147 | + |
| 148 | +```bash |
| 149 | +# Use custom plugins |
| 150 | +java -jar Javalang-analyzing-cli-all.jar CustomTask \ |
| 151 | + --plugin-path /path/to/plugins \ |
| 152 | + --project /path/to/project |
| 153 | +``` |
| 154 | + |
| 155 | +## 🏷️ Statement Classification |
| 156 | + |
| 157 | +The tool automatically identifies and classifies statements in test code: |
| 158 | + |
| 159 | +| Classification | Description | Examples | |
| 160 | +|----------------|-------------|----------| |
| 161 | +| `ASSERT` | Assertion statements | `assertTrue()`, `assertEquals()` | |
| 162 | +| `MOCK` | Mock operations | `when()`, `verify()` | |
| 163 | +| `NEW` | Object creation | `new Object()` | |
| 164 | +| `THIRD` | Third-party library calls | External library method calls | |
| 165 | +| `GET/SET` | Property access | `getProperty()`, `setProperty()` | |
| 166 | +| `PRODUCTION` | Production code calls | Business logic methods being tested | |
| 167 | + |
| 168 | +## 🐛 Troubleshooting |
| 169 | + |
| 170 | +### Common Issues |
| 171 | + |
| 172 | +**Q: "No suitable build tool found" error** |
| 173 | +``` |
| 174 | +A: Ensure the project root contains pom.xml (Maven) or build.gradle (Gradle) files. |
| 175 | +``` |
| 176 | + |
| 177 | +**Q: Test dependencies cannot be resolved** |
| 178 | +``` |
| 179 | +A: Ensure the project has been built (mvn compile or gradle build), |
| 180 | + the tool will automatically search local caches. |
| 181 | +``` |
| 182 | + |
| 183 | +**Q: Out of memory errors** |
| 184 | +``` |
| 185 | +A: Increase JVM heap memory: |
| 186 | +java -Xmx4g -jar Javalang-analyzing-cli-all.jar ... |
| 187 | +``` |
| 188 | + |
| 189 | +**Q: Unicode escape characters in output** |
| 190 | +``` |
| 191 | +A: This is normal - the tool is configured to output readable characters |
| 192 | + instead of Unicode escapes. |
| 193 | +``` |
| 194 | + |
| 195 | +### Debug Mode |
| 196 | + |
| 197 | +The tool outputs detailed debug information including: |
| 198 | +- Detected build system |
| 199 | +- Parsed dependencies |
| 200 | +- Classpath configuration |
| 201 | +- List of processed files |
| 202 | + |
| 203 | +This information helps diagnose issues. |
| 204 | + |
| 205 | +## 🔧 Development |
| 206 | + |
| 207 | +### Building the Project |
| 208 | + |
| 209 | +```bash |
| 210 | +git clone https://github.com/your-username/Javalang-analyzing-cli.git |
| 211 | +cd Javalang-analyzing-cli |
| 212 | +./gradlew shadowJar |
| 213 | +``` |
| 214 | + |
| 215 | +The generated Fat JAR is located at: `build/libs/Javalang-analyzing-cli-*-all.jar` |
| 216 | + |
| 217 | +### Adding New Tasks |
| 218 | + |
| 219 | +1. Implement the `AnalyzerTask` interface |
| 220 | +2. Register in `META-INF/services/edu.stevens.swe.research.java.cli.analyzer.spi.AnalyzerTask` |
| 221 | +3. Rebuild and test |
| 222 | + |
| 223 | +## 📄 License |
| 224 | + |
| 225 | +This project is open source under the [Apache License 2.0](LICENSE). |
| 226 | + |
| 227 | +## 🤝 Contributing |
| 228 | + |
| 229 | +Issues and Pull Requests are welcome! |
| 230 | + |
| 231 | +## 📞 Support |
| 232 | + |
| 233 | +For issues, please report them in [GitHub Issues](https://github.com/your-username/Javalang-analyzing-cli/issues). |
0 commit comments