Skip to content

Enforce code style format #4087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Java Format Check

on:
workflow_dispatch:
pull_request:
paths:
- '**/*.java' # Only trigger for Java file changes

jobs:
check-format:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the PR code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Java (if needed for format check tools)
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'

# Step 3: Fetch latest changes
- name: Fetch latest changes
run: git fetch origin

- name: Get changed Java files
id: changed_files
run: |
echo "::group::Changed Java Files"
echo Base Branch: ${{ github.event.pull_request.base.ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} | grep '\.java$' || true)
echo "$CHANGED_FILES"
echo "::endgroup::"
# Write the multiline content to a file
echo "$CHANGED_FILES" > changed_files.txt

# Step 4: Get a list of changed Java files in the PR
- name: Check Java file format
run: |
# Check if the changed_files.txt exists
if [ ! -f changed_files.txt ]; then
echo "No changed files found."
exit 0
fi

# Read the multiline content from the file
CHANGED_FILES=$(cat changed_files.txt)

# Ensure there are changed files
if [ -z "$CHANGED_FILES" ]; then
echo "No Java files changed."
else
echo "Processing the following changed Java files:"

# Iterate over the CHANGED_FILES variable, assuming files are separated by newlines
while IFS= read -r FILE; do
# Skip empty lines if any
if [ -n "$FILE" ]; then
FILE_NAME=$(basename "$FILE")
echo "Checking for $FILE_NAME"

# Run your formatter validation for each file
mvn formatter:validate -f formatter-pom.xml "-Dformatter.includes=**/$FILE_NAME"
fi
done <<< "$CHANGED_FILES"
fi
37 changes: 37 additions & 0 deletions formatter-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<name>Jedis</name>
<version>5.3.0</version>
<description>Jedis is a blazingly small and sane Redis java client.</description>
<url>https://github.com/redis/jedis</url>


<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.23.0</version>
<configuration>
<configFile>${project.basedir}/hbase-formatter.xml</configFile>
</configuration>
<executions>
<execution>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion hbase-formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
Expand Down
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,22 @@
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
<artifactId>maven-java-formatter-plugin</artifactId>
<version>0.4</version>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.11.0</version>
<configuration>
<configFile>${project.basedir}/hbase-formatter.xml</configFile>
<directories>
<directory>${project.basedir}/src/main/java/redis/clients/jedis/annots</directory>
</directories>
</configuration>
<executions>
<execution>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/redis/clients/jedis/annots/Experimental.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
* If a type is marked with this annotation, all its members are considered experimental.
*/
@Documented
@Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.CONSTRUCTOR})
public @interface Experimental { }
@Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.FIELD,
ElementType.CONSTRUCTOR })
public @interface Experimental {
}
5 changes: 3 additions & 2 deletions src/main/java/redis/clients/jedis/annots/Internal.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
* If a type is marked with this annotation, all its members are considered internal.
*/
@Documented
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
public @interface Internal { }
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
public @interface Internal {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.lang.annotation.Target;

/**
* A member or type annotated with {@link VisibleForTesting} declares that it is only visible for testing purposes.
* A member or type annotated with {@link VisibleForTesting} declares that it is only visible for
* testing purposes.
*/
@Documented
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE})
public @interface VisibleForTesting { }
@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.TYPE })
public @interface VisibleForTesting {
}
Loading