Skip to content

Commit 119cabc

Browse files
authored
[Backport 2.x] Migrating from checkstyle to spotless (#648 and #651) (#661)
* Migrating from checkstyle to spotless for formatting (#648) * Adding spotless for checking and fixing formatting and removing checkstyle Signed-off-by: Vacha Shah <[email protected]> * Making build task depend on spotlessJavaCheck Signed-off-by: Vacha Shah <[email protected]> * Removing resources and documentation related to checkstyle Signed-off-by: Vacha Shah <[email protected]> * Running spotless for json, transport and util folders Signed-off-by: Vacha Shah <[email protected]> * Running spotless for samples Signed-off-by: Vacha Shah <[email protected]> * Removing commented code Signed-off-by: Vacha Shah <[email protected]> --------- Signed-off-by: Vacha Shah <[email protected]> * Fixing merge conflicts and build Signed-off-by: Vacha Shah <[email protected]> * Enabling spotless for all modules from PR 651 Signed-off-by: Vacha Shah <[email protected]> * Applying spotless to all the remaining files Signed-off-by: Vacha Shah <[email protected]> --------- Signed-off-by: Vacha Shah <[email protected]>
1 parent 53489bc commit 119cabc

File tree

1,660 files changed

+272379
-272548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,660 files changed

+272379
-272548
lines changed

.github/workflows/checkstyle.yml

-24
This file was deleted.

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1515

1616
### Changed
1717
- Moved "software.amazon.awssdk" dependencies to the compileOnly scope. ([#628](https://github.com/opensearch-project/opensearch-java/pull/628))
18+
- Migrated from checkstyle to spotless ([#648](https://github.com/opensearch-project/opensearch-java/pull/648))
1819

1920
### Deprecated
2021

DEVELOPER_GUIDE.md

+21-4
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,28 @@ Follow links in the [Java Tutorial](https://code.visualstudio.com/docs/java/java
9797

9898
## Java Language Formatting Guidelines
9999

100-
Java files in the opensearch-java codebase are formatted with the [checkstyle plugin](https://docs.gradle.org/current/userguide/checkstyle_plugin.html). This plugin is configured using [checkstyle.xml](config/checkstyle/checkstyle.xml). To run the formatting checks:
100+
Java files in the OpenSearch codebase are formatted with the Eclipse JDT formatter, using the [Spotless Gradle](https://github.com/diffplug/spotless/tree/master/plugin-gradle) plugin. This plugin is configured on a project-by-project basis, via `build.gradle.kts`. So long as at least one project is configured, the formatting check can be run explicitly with:
101101

102-
```
103-
./gradlew checkstyleMain checkstyleTest
104-
```
102+
./gradlew spotlessJavaCheck
103+
104+
The code can be formatted with:
105+
106+
./gradlew spotlessApply
107+
108+
These tasks can also be run for specific subprojects, e.g.
109+
110+
./gradlew :java-client:spotlessJavaCheck
111+
./gradlew :samples:spotlessJavaCheck
112+
113+
Please follow these formatting guidelines:
114+
115+
* Java indent is 4 spaces
116+
* Line width is 140 characters
117+
* Lines of code surrounded by `// tag::NAME` and `// end::NAME` comments are included in the documentation and should only be 76 characters wide not counting leading indentation. Such regions of code are not formatted automatically as it is not possible to change the line length rule of the formatter for part of a file. Please format such sections sympathetically with the rest of the code, while keeping lines to maximum length of 76 characters.
118+
* Wildcard imports (`import foo.bar.baz.*`) are forbidden and will cause the build to fail.
119+
* If *absolutely* necessary, you can disable formatting for regions of code with the `// tag::NAME` and `// end::NAME` directives, but note that these are intended for use in documentation, so please make it clear what you have done, and only do this where the benefit clearly outweighs the decrease in consistency.
120+
* Note that JavaDoc and block comments i.e. `/* ... */` are not formatted, but line comments i.e `// ...` are.
121+
* There is an implicit rule that negative boolean expressions should use the form `foo == false` instead of `!foo` for better readability of the code. While this isn't strictly enforced, if might get called out in PR reviews as something to change.
105122

106123
## Submitting Changes
107124

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Checkstyle](https://github.com/opensearch-project/opensearch-java/actions/workflows/checkstyle.yml/badge.svg?branch=main)](https://github.com/opensearch-project/opensearch-java/actions/workflows/checkstyle.yml)
21
[![Build](https://github.com/opensearch-project/opensearch-java/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/opensearch-project/opensearch-java/actions/workflows/build.yml)
32
[![Integration Tests](https://github.com/opensearch-project/opensearch-java/actions/workflows/test-integration.yml/badge.svg?branch=main)](https://github.com/opensearch-project/opensearch-java/actions/workflows/test-integration.yml)
43
![Maven Central](https://img.shields.io/maven-central/v/org.opensearch.client/opensearch-java)

build.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ allprojects {
4242
mavenCentral()
4343
maven(url = "https://plugins.gradle.org/m2/")
4444
}
45-
46-
apply(plugin = "checkstyle")
4745
}
4846

4947
// Find git information.

buildSrc/formatterConfig.xml

+362
Large diffs are not rendered by default.

config/checkstyle/checkstyle.xml

-156
This file was deleted.

config/checkstyle/checkstyle_suppressions.xml

-44
This file was deleted.

config/checkstyle/header.java.txt

-7
This file was deleted.

java-client/build.gradle.kts

+21-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ buildscript {
4646
plugins {
4747
java
4848
`java-library`
49-
checkstyle
5049
`maven-publish`
5150
id("com.github.jk1.dependency-license-report") version "2.5"
5251
id("org.owasp.dependencycheck") version "8.4.0"
52+
id("com.diffplug.spotless") version "6.22.0"
5353
}
5454

5555
apply(plugin = "org.owasp.dependencycheck")
@@ -60,10 +60,6 @@ configurations {
6060
}
6161
}
6262

63-
checkstyle {
64-
toolVersion = "10.12.3"
65-
}
66-
6763
java {
6864
targetCompatibility = JavaVersion.VERSION_11
6965
sourceCompatibility = JavaVersion.VERSION_11
@@ -113,6 +109,10 @@ tasks.withType<Jar> {
113109
}
114110
}
115111

112+
tasks.build {
113+
dependsOn("spotlessJavaCheck")
114+
}
115+
116116
tasks.test {
117117
systemProperty("tests.security.manager", "false")
118118

@@ -265,6 +265,22 @@ tasks.withType<Jar> {
265265
}
266266
}
267267

268+
spotless {
269+
java {
270+
271+
target("**/*.java")
272+
273+
// Use the default importOrder configuration
274+
importOrder()
275+
removeUnusedImports()
276+
277+
eclipse().configFile("../buildSrc/formatterConfig.xml")
278+
279+
trimTrailingWhitespace()
280+
endWithNewline()
281+
}
282+
}
283+
268284
publishing {
269285
repositories{
270286
if (version.toString().endsWith("SNAPSHOT")) {

java-client/src/main/java/org/opensearch/client/ApiClient.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@
3232

3333
package org.opensearch.client;
3434

35-
import org.opensearch.client.transport.TransportOptions;
36-
import org.opensearch.client.transport.Transport;
35+
import javax.annotation.Nullable;
3736
import org.opensearch.client.json.JsonpDeserializer;
3837
import org.opensearch.client.json.JsonpMapperBase;
39-
40-
import javax.annotation.Nullable;
38+
import org.opensearch.client.transport.Transport;
39+
import org.opensearch.client.transport.TransportOptions;
4140

4241
public abstract class ApiClient<T extends Transport, Self extends ApiClient<T, Self>> {
4342

java-client/src/main/java/org/opensearch/client/json/AttributedJsonpMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public boolean ignoreUnknownFields() {
7272
@SuppressWarnings("unchecked")
7373
public <T> T attribute(String name) {
7474
if (this.name.equals(name)) {
75-
return (T)this.value;
75+
return (T) this.value;
7676
} else {
7777
return mapper.attribute(name);
7878
}

java-client/src/main/java/org/opensearch/client/json/BuildFunctionDeserializer.java

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
package org.opensearch.client.json;
3434

3535
import jakarta.json.stream.JsonParser;
36-
3736
import java.util.function.Function;
3837

3938
/**

java-client/src/main/java/org/opensearch/client/json/DelegatingDeserializer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
package org.opensearch.client.json;
3434

3535
import jakarta.json.stream.JsonParser;
36-
3736
import java.util.EnumSet;
3837

3938
public abstract class DelegatingDeserializer<T, U> implements JsonpDeserializer<T> {
@@ -68,7 +67,7 @@ public T deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event eve
6867
*/
6968
public static JsonpDeserializer<?> unwrap(JsonpDeserializer<?> deserializer) {
7069
while (deserializer instanceof DelegatingDeserializer) {
71-
deserializer = ((DelegatingDeserializer<?,?>) deserializer).unwrap();
70+
deserializer = ((DelegatingDeserializer<?, ?>) deserializer).unwrap();
7271
}
7372
return deserializer;
7473
}

0 commit comments

Comments
 (0)