25 lines
825 B
Bash
Executable File
25 lines
825 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Path to the Google Java Formatter JAR
|
|
FORMATTER_JAR="$HOME/.local/share/java/google-java-format.jar"
|
|
|
|
# Download the Google Java Formatter JAR if it doesn't exist
|
|
if [ ! -f "$FORMATTER_JAR" ]; then
|
|
echo "Downloading Google Java Formatter..."
|
|
mkdir -p "$(dirname "$FORMATTER_JAR")"
|
|
curl -L -o "$FORMATTER_JAR" https://github.com/google/google-java-format/releases/download/v1.20.0/google-java-format-1.20.0-all-deps.jar
|
|
fi
|
|
|
|
# Format all staged Java files
|
|
STAGED_JAVA_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "\.java$")
|
|
|
|
if [ -n "$STAGED_JAVA_FILES" ]; then
|
|
echo "Formatting Java files..."
|
|
java -jar "$FORMATTER_JAR" --skip-sorting-imports --skip-reflowing-long-strings --aosp --replace $STAGED_JAVA_FILES
|
|
|
|
# Re-stage the formatted files
|
|
git add $STAGED_JAVA_FILES
|
|
fi
|
|
|
|
exit 0
|