A high-performance Java utility for consolidating complex project structures into a single flat text file. Perfect for code analysis, archival, or intellectual property applications.
- Configure paths in
SourceCodeFlattener.java๏ผ
private final static Path rootPath = get("YOUR_SOURCE_CODE_PATH");
private final static Path outputPath = get("source-code.txt");- Use default implementations: The default
FileFilterprocesses all files (no filtering).
private final static FileFilter FILE_FILTER = path -> true; // Process all files
private final static FileProcessor fileProcessor = new DefaultFileProcessor(FILE_FILTER, rootPath);- Run the application:
mvn compile
java -cp target/classes org.glowberry.flattener.SourceCodeFlattener- Get organized output in
source-code.txtwith clear file boundaries.
- Pluggable Filter Interface: Implement
FileFilterto define custom inclusion rules - Flexible Processing: Replace
FileProcessorfor specialized traversal logic - Interface Segregation: Clean separation between filtering, processing, and output
The tool provides sensible defaults while empowering complete customization:
// Implement your own filtering logic
public class CustomFilter implements FileFilter {
@Override
public boolean shouldProcess(Path path) {
return path.toString().endsWith(".java"); // Your rules
}
}
// Use with existing processor
FileProcessor processor = new CustomFileProcessor(new CustomFilter(), rootPath);