Skip to content

Commit

Permalink
[ISSUE apache#4443] Automatically format code at build time using the…
Browse files Browse the repository at this point in the history
… Spotless plugin with the EventMesh coding style. (apache#4447)

* Add spotless gradle plugin, configure eclipse formatter.

* Fix task order.

* Fix task order.

* Modify the newline size to 150 lines, compatible with checkstyle.

* Apply spotless code format with all project java files.

* License header file using checkstyle-header1.txt.

* ignore protos file

* spotless task depends on test

* Fix build error.

* Compatible with spotless and checkstyle, add importorder file.

* Roll back changes in checkstyle.xml

* Modify newline indentation to 12

* Disable spotless alignment for exceptions on method declarations.

* fix indent errors.

* Reapply spotless to the entire project.

* method param indent to 16.

* Fix new line in try-with-resource blocks.

* Fix static import grouping and order issues.

* Implements declaration on type related fixes.

* fix javadoc

* fix some comments.

* fix some code styles.

* fix log code style.

* Repair folder name.

* fix some styles.

* fix some styles.

* fix comment format rules.

* revert

* fix some comments.

* fix path

* Remove spotlessJava step from ci build workflow.

* apply spotless.

* revert pmd plugin
  • Loading branch information
yanrongzhen authored Sep 30, 2023
1 parent ce15df9 commit 73af459
Show file tree
Hide file tree
Showing 535 changed files with 1,648 additions and 2,180 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:

# https://docs.gradle.org/current/userguide/performance.html
- name: Build
run: ./gradlew clean build jar dist jacocoTestReport -x generateGrammarSource --parallel --daemon
run: ./gradlew clean build jar dist jacocoTestReport -x spotlessJava -x generateGrammarSource --parallel --daemon

- name: Install plugin
run: ./gradlew installPlugin
Expand All @@ -100,4 +100,4 @@ jobs:

- name: Check third party dependencies
run: |
./gradlew clean jar dist -x test -x checkstyleMain -x javaDoc && ./gradlew installPlugin && ./gradlew tar && sh tools/dependency-check/check-dependencies.sh && echo "Thirty party dependencies check success"
./gradlew clean jar dist -x spotlessJava -x test -x checkstyleMain -x javaDoc && ./gradlew installPlugin && ./gradlew tar && sh tools/dependency-check/check-dependencies.sh && echo "Thirty party dependencies check success"
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ buildscript {
classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14"
classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE"
classpath "com.github.jk1:gradle-license-report:1.17"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.13.0"
}
}

Expand All @@ -61,6 +62,7 @@ allprojects {
apply plugin: "java-library"
apply plugin: 'signing'
apply plugin: 'checkstyle'
apply plugin: 'com.diffplug.spotless'

[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

Expand Down Expand Up @@ -91,6 +93,7 @@ allprojects {
.exclude('**/org/apache/eventmesh/connector/openfunction/client/EventMeshGrpcService**')
.exclude('**/org/apache/eventmesh/connector/openfunction/client/CallbackServiceGrpc**')
.exclude('**/org/apache/eventmesh/connector/jdbc/antlr**')
.dependsOn(spotlessApply)

dependencies {
repositories {
Expand All @@ -102,6 +105,27 @@ allprojects {
}
testImplementation "junit:junit:4.13.2"
}

spotless {
enforceCheck false
java {
target project.fileTree(project.projectDir) {
include '**/*.java'
exclude '**/org/apache/eventmesh/**/protos**'
exclude '**/org/apache/eventmesh/connector/openfunction/client/EventMeshGrpcService**'
exclude '**/org/apache/eventmesh/connector/openfunction/client/CallbackServiceGrpc**'
exclude '**/org/apache/eventmesh/connector/jdbc/antlr**'
exclude '**/org/apache/eventmesh/common/protocol/grpc**'
exclude '**/org/apache/eventmesh/connector/jdbc/source/dialect/snapshot/AbstractSnapshotEngine.java'
}
importOrder ('\\#org.apache.eventmesh','\\#org.apache','\\#java','\\#javax','\\#org','\\#io','\\#net','\\#junit','\\#com','\\#lombok',
'org.apache.eventmesh','org.apache','java','javax','org','io','net','junit','com','lombok')
licenseHeaderFile rootProject.file('style/checkstyle-header1.txt')
eclipse().configFile("${rootDir}/style/task/eventmesh-spotless-formatter.xml")
removeUnusedImports()
}
}
spotlessJava.dependsOn(compileJava, javadoc, compileTestJava, test, processResources, processTestResources)
}

task tar(type: Tar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.io.IOException;


import com.sun.net.httpserver.HttpServer;

import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void createTopicHandler(HttpExchange httpExchange) throws IOException {
return;
}

//TBD: A new rocketmq service will be implemented for creating topics
// TBD: A new rocketmq service will be implemented for creating topics
TopicResponse topicResponse = null; // Temporary variable for topic response
if (topicResponse != null) {
log.info("create a new topic: {}", topic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import com.sun.net.httpserver.HttpExchange;


public class RequestMappingTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public ResetCountDownLatch(int count) {
this.restSync = new RestSync(count);
}


/**
* Causes the current thread to wait until the latch has counted down to zero, unless the thread is {@linkplain Thread#interrupt interrupted}.
*
Expand Down Expand Up @@ -104,7 +103,6 @@ public boolean await(long timeout, TimeUnit unit)
return restSync.tryAcquireSharedNanos(1, unit.toNanos(timeout));
}


/**
* Decrements the count of the latch, releasing all waiting threads if the count reaches zero.
*
Expand Down Expand Up @@ -165,7 +163,7 @@ protected int tryAcquireShared(int acquires) {

@Override
protected boolean tryReleaseShared(int releases) {
for (; ; ) {
for (;;) {
int count = getState();
if (count == 0) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static ScheduledExecutorService createSingleScheduledExecutor(final Strin
return Executors.newSingleThreadScheduledExecutor(new EventMeshThreadFactory(threadName, true));
}


public static ScheduledExecutorService createScheduledExecutor(int core, ThreadFactory threadFactory) {
return Executors.newScheduledThreadPool(core, threadFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void await() {
if (hasWakeup.compareAndSet(true, false)) {
return;
}
//reset count
// reset count
waiter.reset();
try {
waiter.await();
Expand All @@ -74,7 +74,7 @@ public void await(long timeout, TimeUnit timeUnit) {
if (hasWakeup.compareAndSet(true, false)) {
return;
}
//reset count
// reset count
waiter.reset();
try {
waiter.await(timeout, timeUnit == null ? TimeUnit.MILLISECONDS : timeUnit);
Expand Down Expand Up @@ -104,15 +104,15 @@ private void shutdown(final boolean interruptThread) {
return;
}
this.isRunning = false;
//wakeup the thread to run
// wakeup the thread to run
wakeup();

try {
if (interruptThread) {
this.thread.interrupt();
}
if (!this.isDaemon) {
//wait main thread to wait this thread finish
// wait main thread to wait this thread finish
this.thread.join(TimeUnit.SECONDS.toMillis(60));
}
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public class CommonConfiguration {
@ConfigFiled(field = "security.validation.type.token", notEmpty = true)
private boolean eventMeshSecurityValidateTypeToken = false;


@ConfigFiled(field = "server.trace.enabled")
private boolean eventMeshServerTraceEnable = false;

Expand All @@ -105,7 +104,6 @@ public class CommonConfiguration {
@ConfigFiled(field = "server.provide.protocols", reload = true)
private List<String> eventMeshProvideServerProtocols;


@ConfigFiled(reload = true)
private String eventMeshWebhookOrigin;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,3 @@
Config[] value();
}
}



Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.TreeMap;
import java.util.Vector;


import lombok.extern.slf4j.Slf4j;

import inet.ipaddr.IPAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public List<Object> convert(ConvertInfo convertInfo, String separator) {
}
}


public static class ListConverterSemi extends ListConverter {

public String separator = ";";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Object convert(ConvertInfo convertInfo) {
this.setValue();

Class<?> superclass = convertInfo.getClazz();
for (; ; ) {
for (;;) {
superclass = superclass.getSuperclass();
if (Objects.equals(superclass, Object.class) || Objects.isNull(superclass)) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.Getter;

public enum EventMeshDataContentType {

JSON("application/json");

@Getter
Expand All @@ -29,5 +30,4 @@ public enum EventMeshDataContentType {
this.code = code;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;


import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.List;


import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.eventmesh.common.loadbalance;

public enum LoadBalanceType {

RANDOM(0, "random load balance strategy"),
WEIGHT_ROUND_ROBIN(1, "weight round robin load balance strategy"),
WEIGHT_RANDOM(2, "weight random load balance strategy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;


import lombok.extern.slf4j.Slf4j;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void increaseCurrentWeight() {
currentWeight.addAndGet(value);
}


public T getTarget() {
return target;
}
Expand All @@ -54,7 +53,6 @@ public int getValue() {
return value;
}


public AtomicInteger getCurrentWeight() {
return currentWeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;


import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -45,7 +44,6 @@ public WeightRoundRobinLoadBalanceSelector(List<Weight<T>> clusterGroup) {
this.totalWeight = totalWeight;
}


@Override
@SuppressWarnings("ConstantConditions")
public T select() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,3 @@ public int hashCode() {
return Objects.hashCode(topic, mode, type);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public enum SubscriptionMode {
/**
* UNRECOGNIZED
*/
UNRECOGNIZED("UNRECOGNIZED")
;
UNRECOGNIZED("UNRECOGNIZED");

private final String mode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.eventmesh.common.protocol;

public enum SubscriptionType {

/**
* SYNC
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public class HttpCommand implements ProtocolTransportObject {

private transient Body body;

//Command request time
// Command request time
public long reqTime;

//Command response time
// Command response time
public long resTime;

public CmdType cmdType = CmdType.REQ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;


public class HttpEventWrapper implements ProtocolTransportObject {

public static final long serialVersionUID = -8547334421415366981L;
Expand All @@ -59,10 +58,10 @@ public class HttpEventWrapper implements ProtocolTransportObject {

private String httpVersion;

//Command request time
// Command request time
private long reqTime;

//Command response time
// Command response time
private long resTime;

private HttpResponseStatus httpResponseStatus = HttpResponseStatus.OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import lombok.Builder;
import lombok.Data;


@Data
@Builder
public class WebhookProtocolTransportObject implements ProtocolTransportObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.eventmesh.common.protocol.http.body;


import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ public static Body buildBody(String requestCode, Map<String, Object> originalMap

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

public class HeartbeatResponseBody extends Body {

//return code
// return code
private Integer retCode;

//response message
// response message
private String retMsg;

//response time
// response time
private long resTime = System.currentTimeMillis();

public Integer getRetCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

public class ReplyMessageResponseBody extends Body {

//return code
// return code
private Integer retCode;

//response message
// response message
private String retMsg;

//response time
// response time
private long resTime = System.currentTimeMillis();

public Integer getRetCode() {
Expand Down
Loading

0 comments on commit 73af459

Please sign in to comment.