https://github.com/algodesigner/eclipse-format
eclipse-format: A command-line tool for formatting Java code using Eclipse's formatter in headless mode with complete symmetry to Eclipse IDE.
https://github.com/algodesigner/eclipse-format
automation build-tools ci-cd cli code-formatting code-quality code-style developer-tools eclipse eclipse-formatter eclipse-ide formatter formatting-tool gradle java java-development java-formatter programming-tools software-quality
Last synced: 6 days ago
JSON representation
eclipse-format: A command-line tool for formatting Java code using Eclipse's formatter in headless mode with complete symmetry to Eclipse IDE.
- Host: GitHub
- URL: https://github.com/algodesigner/eclipse-format
- Owner: algodesigner
- License: bsd-3-clause
- Created: 2026-02-26T12:30:04.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-05-22T17:20:49.000Z (20 days ago)
- Last Synced: 2026-05-22T20:57:53.836Z (20 days ago)
- Topics: automation, build-tools, ci-cd, cli, code-formatting, code-quality, code-style, developer-tools, eclipse, eclipse-formatter, eclipse-ide, formatter, formatting-tool, gradle, java, java-development, java-formatter, programming-tools, software-quality
- Language: Shell
- Homepage:
- Size: 97.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Eclipse Formatter CLI
A command-line tool for formatting Java code using Eclipse's code formatter in headless mode. Provides a simple, user-friendly interface for consistent code formatting across projects.
## Features
- ๐ **Simple CLI interface** - Easy to use with intuitive commands
- โก **Fast formatting** - Leverages Eclipse's proven formatter engine
- ๐ง **Customisable** - Use your own Eclipse formatter configuration
- ๐ **Batch processing** - Format single files or entire directories
- ๐ **Dry run mode** - Preview changes before applying
- ๐ **Recursive formatting** - Process nested directories
- ๐งช **Tested** - Comprehensive unit and integration tests
- ๐๏ธ **IDE friendly** - Works with Eclipse and IntelliJ IDEA
## ๐ Quick Installation
### Option 1: One-Command Setup (Easiest & Recommended)
```bash
# Clone and setup in one go
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./setup.sh
# Now use it!
./eclipse-format --help
```
### Option 2: Interactive Installer (Full Features)
```bash
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./install.sh
# Choose from:
# 1. System-wide installation (requires sudo)
# 2. Local user installation (~/.local/bin)
# 3. Standalone script
# 4. Just build
```
### Option 3: Universal Wrapper (Smart Auto-Detection)
```bash
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./gradlew shadowJar
./eclipse-format.sh --help # Auto-finds the JAR!
```
### Option 4: Direct Usage (Simple)
```bash
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./gradlew shadowJar
java -jar build/libs/eclipse-format.jar --help
```
### Option 5: Windows Users
```batch
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
gradlew.bat shadowJar
eclipse-format.bat --help
```
## Usage
### Basic Usage
```bash
# Format a single Java file
eclipse-format MyClass.java
# Format all Java files in a directory
eclipse-format src/
# Format recursively
eclipse-format -r src/
# Dry run (show what would change)
eclipse-format -d src/
# Verbose output
eclipse-format -v MyClass.java
# Auto-discover eclipse-format.xml (walks up from target)
eclipse-format MyClass.java
# Use custom configuration file
eclipse-format -c my-formatter.xml MyClass.java
```
### Command Line Options
```
Usage: eclipse-format [-cdrv] [-c=]
File or directory to format
-c, --config=
Path to Eclipse formatter configuration file.
If not specified, searches for eclipse-format.xml
starting from the target's parent directory and
walking up the directory tree.
-d, --dry-run Show what would be formatted without making changes
-r, --recursive Format files recursively
-v, --verbose Verbose output
--help Show this help message and exit
--version Print version information and exit
```
### Configuration File
The tool uses Eclipse's XML formatter configuration files. You can:
1. **Export from Eclipse IDE**: Window โ Preferences โ Java โ Code Style โ Formatter โ Export...
2. **Use the default** included in this project (`eclipse-format.xml`)
3. **Create your own** XML configuration
**Config file resolution:** When `-c` is not specified, the tool searches
for `eclipse-format.xml` by walking up the directory tree. The search
starts from the target's parent directory (for a file) or the target
directory itself (for a directory), ascending towards the filesystem
root. The first `eclipse-format.xml` found is used. Use `-c` to specify
an exact path and bypass auto-discovery entirely.
Place `eclipse-format.xml` in your project root and run the tool from
any subdirectory โ it will find it automatically. This matches the
behaviour of tools like clang-format.
Example configuration file structure:
```xml
```
## Development
### Prerequisites
- Java 15 or higher
- Gradle 8.5 or higher
### Setup Development Environment
```bash
# Clone and setup
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
# Setup for Eclipse
./gradlew setupEclipse
# Setup for IntelliJ IDEA
./gradlew setupIntelliJ
# Clean IDE files
./gradlew cleanIDE
```
### Build Commands
```bash
# Build the project
./gradlew build
# Run tests
./gradlew test
# Run integration tests
./gradlew integrationTest
# Create executable JAR
./gradlew shadowJar
# Run the application
./gradlew run --args="-v MyClass.java"
```
### Project Structure
```
eclipse-format/
โโโ src/
โ โโโ main/java/com/algodesigner/eclipseformat/cli/
โ โ โโโ EclipseFormatCli.java # Main CLI entry point
โ โ โโโ FormatterService.java # Core formatting logic
โ โโโ test/java/com/algodesigner/eclipseformat/cli/
โ โโโ EclipseFormatCliTest.java # Unit tests
โ โโโ IntegrationTest.java # Integration tests
โโโ eclipse-format.xml # Default formatter config
โโโ build.gradle # Gradle build configuration
โโโ gradlew # Gradle wrapper
โโโ README.md # This file
```
## Examples
### Example 1: Format a Project
```bash
# Format all Java files (auto-discovers eclipse-format.xml in project root)
eclipse-format -r src/main/java/
# With custom configuration
eclipse-format -c company-style.xml -r src/
```
### Example 2: Preview Changes
```bash
# See what files would be formatted
eclipse-format -d -r src/
# Output:
# [DRY RUN] Would format: src/main/java/com/example/Main.java
# [DRY RUN] Would format: src/main/java/com/example/Util.java
```
### Example 3: CI/CD Integration
```bash
# Check if code is properly formatted (exit code 0 if formatted, 1 if not)
eclipse-format -d -r src/ && echo "Code is properly formatted"
```
## Testing
The project includes comprehensive test coverage:
```bash
# Run all tests
./gradlew test
# Run specific test class
./gradlew test --tests "EclipseFormatterCliTest"
# Run integration tests
./gradlew test --tests "IntegrationTest"
# Generate test coverage report
./gradlew jacocoTestReport
```
## Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request
### Code Style
Please ensure your code follows the project's formatting rules:
```bash
# Format your code before submitting
./gradlew run --args="src/main/java/"
```
## License
This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICENSE) file for details.
## Uninstalling
Easy removal with the uninstall script:
```bash
# Interactive uninstall (recommended)
./uninstall.sh
# Remove everything
./uninstall.sh --all
# Clean up PATH entries
./uninstall.sh --clean-path
```
See [USAGE.md](USAGE.md) for complete uninstall options.
## Support
- ๐ **Documentation**: [README.md](README.md) and [USAGE.md](USAGE.md)
- ๐ **Issues**: Report installation or usage issues
- ๐ง **Uninstall**: Use `./uninstall.sh` for clean removal
## Acknowledgments
- Built with [Picocli](https://picocli.info/) for CLI parsing
- Uses Eclipse's Java Development Tools for formatting
- Inspired by the need for consistent code formatting in CI/CD pipelines
---
Made with โค๏ธ by [Vlad Shurupov](https://github.com/algodesigner) for clean code everywhere