Skip to content

Commit

Permalink
[Spotless] Applying Google Code Format for entire project #22 (opense…
Browse files Browse the repository at this point in the history
…arch-project#2005)

* Spotless apply on entire project

Signed-off-by: Mitchell Gale <[email protected]>

* Spotless apply

Signed-off-by: Mitchell Gale <[email protected]>

* Added spotless in sql-test-workflow.yml

Signed-off-by: Mitchell Gale <[email protected]>

* fixed error log message in sql-test-workflow.yml

Signed-off-by: Mitchell Gale <[email protected]>

* Added spotless to plugins: common, core, doctest, integ-test, legacy, opensearch, plugin, ppl, protocol, sql

Signed-off-by: Mitchell Gale <[email protected]>

* Update common/build.gradle

Signed-off-by: Mitchell Gale <[email protected]>

* deleted duplicated code in build gradle integ test

Signed-off-by: Mitchell Gale <[email protected]>

---------

Signed-off-by: Mitchell Gale <[email protected]>
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale authored Aug 22, 2023
1 parent b3fd4c4 commit 09d222b
Show file tree
Hide file tree
Showing 160 changed files with 12,488 additions and 12,539 deletions.
1 change: 0 additions & 1 deletion .github/workflows/sql-test-and-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- '!sql-jdbc/**'
- '**gradle*'
- '**lombok*'
- '**checkstyle*'
- 'integ-test/**'
- '**/*.jar'
- '**/*.pom'
Expand Down
28 changes: 10 additions & 18 deletions .github/workflows/sql-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,16 @@ jobs:
- name: Run tests
id: tests
run: |
# checkstyle
./gradlew :opensearch:checkstyleMain || echo "* Checkstyle failed for opensearch/src" > report.log
./gradlew :opensearch:checkstyleTest || echo "* Checkstyle failed for opensearch/test" >> report.log
./gradlew :sql:checkstyleMain || echo "* Checkstyle failed for sql/src" >> report.log
./gradlew :sql:checkstyleTest || echo "* Checkstyle failed for sql/test" >> report.log
./gradlew :ppl:checkstyleMain || echo "* Checkstyle failed for ppl/src" >> report.log
./gradlew :ppl:checkstyleTest || echo "* Checkstyle failed for ppl/test" >> report.log
./gradlew :core:checkstyleMain || echo "* Checkstyle failed for core/src" >> report.log
./gradlew :core:checkstyleTest || echo "* Checkstyle failed for core/test" >> report.log
./gradlew :common:checkstyleMain || echo "* Checkstyle failed for common/src" >> report.log
./gradlew :common:checkstyleTest || echo "* Checkstyle failed for common/test" >> report.log
./gradlew :legacy:checkstyleMain || echo "* Checkstyle failed for legacy/src" >> report.log
./gradlew :legacy:checkstyleTest || echo "* Checkstyle failed for legacy/test" >> report.log
./gradlew :protocol:checkstyleMain || echo "* Checkstyle failed for protocol/src" >> report.log
./gradlew :protocol:checkstyleTest || echo "* Checkstyle failed for protocol/test" >> report.log
./gradlew :opensearch-sql-plugin:checkstyleMain || echo "* Checkstyle failed for plugin/src" >> report.log
./gradlew :opensearch-sql-plugin:checkstyleTest || echo "* Checkstyle failed for plugin/test" >> report.log
# Add checkstyle for `integ-test` when fixed
# Spotless
./gradlew :opensearch:spotlessCheck || echo "* Spotless failed for opensearch" > report.log
./gradlew :sql:spotlessCheck || echo "* Spotless failed for sql" >> report.log
./gradlew :ppl:spotlessCheck || echo "* Spotless failed for ppl" >> report.log
./gradlew :core:spotlessCheck || echo "* Spotless failed for core" >> report.log
./gradlew :common:spotlessCheck || echo "* Spotless failed for common" >> report.log
./gradlew :legacy:spotlessCheck || echo "* Spotless failed for legacy" >> report.log
./gradlew :protocol:spotlessCheck || echo "* Spotless failed for protocol" >> report.log
./gradlew :opensearch-sql-plugin:spotlessCheck || echo "* Spotless failed for plugin" >> report.log
./gradlew :integ-test:spotlessCheck || echo "* Spotless failed for integ-test" >> report.log
# Unit tests
./gradlew :opensearch:test || echo "* Unit tests failed for opensearch" >> report.log
./gradlew :ppl:test || echo "* Unit tests failed for sql" >> report.log
Expand Down
10 changes: 3 additions & 7 deletions DEVELOPER_GUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ The plugin codebase is in standard layout of Gradle project::
├── THIRD-PARTY
├── build.gradle
├── config
│ └── checkstyle
├── docs
│   ├── attributions.md
│   ├── category.json
Expand Down Expand Up @@ -170,7 +169,6 @@ Here are sub-folders (Gradle modules) for plugin source code:
Here are other files and sub-folders that you are likely to touch:

- ``build.gradle``: Gradle build script.
- ``config``: only Checkstyle configuration files for now.
- ``docs``: documentation for developers and reference manual for users.
- ``doc-test``: code that run .rst docs in ``docs`` folder by Python doctest library.

Expand All @@ -189,15 +187,15 @@ Java files in the OpenSearch codebase are formatted with the Eclipse JDT formatt

The formatting check can be run explicitly with::

./gradlew spotlessJavaCheck
./gradlew spotlessCheck

The code can be formatted with::

./gradlew spotlessApply

These tasks can also be run for specific modules, e.g.::

./gradlew server:spotlessJavaCheck
./gradlew server:spotlessCheck

For more information on the spotless for the OpenSearch project please see `https://github.com/opensearch-project/OpenSearch/blob/main/DEVELOPER_GUIDE.md#java-language-formatting-guidelines <https://github.com/opensearch-project/OpenSearch/blob/main/DEVELOPER_GUIDE.md#java-language-formatting-guidelines>`_.

Expand Down Expand Up @@ -230,9 +228,7 @@ Most of the time you just need to run ./gradlew build which will make sure you p
* - ./gradlew generateGrammarSource
- (Re-)Generate ANTLR parser from grammar file.
* - ./gradlew compileJava
- Compile all Java source files.
* - ./gradlew checkstyle
- Run all checks according to Checkstyle configuration.
- Compile all Java source files.
* - ./gradlew test
- Run all unit tests.
* - ./gradlew :integ-test:integTest
Expand Down
31 changes: 1 addition & 30 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ buildscript {
plugins {
id 'nebula.ospackage' version "8.3.0"
id 'java-library'
id 'checkstyle'
id "io.freefair.lombok" version "6.4.0"
id 'jacoco'
id 'com.diffplug.spotless' version '6.19.0'
Expand All @@ -80,22 +79,10 @@ repositories {
maven { url 'https://jitpack.io' }
}

// Spotless checks will be added as PRs are applied to resolve each style issue is approved.
spotless {
java {
target fileTree('.') {
include 'datasources/**/*.java',
'core/**/*.java',
'protocol/**/*.java',
'prometheus/**/*.java',
'sql/**/*.java',
'common/**/*.java',
'spark/**/*.java',
'plugin/**/*.java',
'ppl/**/*.java',
'integ-test/**/*java',
'core/**/*.java',
'opensearch/**/*.java'
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
Expand Down Expand Up @@ -194,22 +181,6 @@ jacocoTestCoverageVerification {
}
check.dependsOn jacocoTestCoverageVerification

// TODO: fix code style in main and test source code
allprojects {
apply plugin: 'checkstyle'
checkstyle {
configFile rootProject.file("config/checkstyle/google_checks.xml")
toolVersion "10.3.2"
configProperties = [
"org.checkstyle.google.suppressionfilter.config": rootProject.file("config/checkstyle/suppressions.xml")]
ignoreFailures = false
}
}
checkstyle {
configFile file("config/checkstyle/checkstyle.xml")
}
checkstyleMain.ignoreFailures = false
checkstyleTest.ignoreFailures = true

configurations.all {
resolutionStrategy.force 'junit:junit:4.13.2'
Expand Down
25 changes: 20 additions & 5 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@
plugins {
id 'java-library'
id "io.freefair.lombok"
id 'com.diffplug.spotless' version '6.19.0'
}

repositories {
mavenCentral()
}

// Being ignored as a temporary measure before being removed in favour of
// spotless https://github.com/opensearch-project/sql/issues/1101
checkstyleTest.ignoreFailures = true
checkstyleMain.ignoreFailures = true

dependencies {
api "org.antlr:antlr4-runtime:4.7.1"
api group: 'com.google.guava', name: 'guava', version: '32.0.1-jre'
Expand Down Expand Up @@ -68,3 +64,22 @@ configurations.all {
resolutionStrategy.force "joda-time:joda-time:2.10.12"
resolutionStrategy.force "org.slf4j:slf4j-api:1.7.36"
}

spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**'
}
importOrder()
// Needs https://github.com/opensearch-project/sql/issues/1893 to be addressed first
// licenseHeader("/*\n" +
// " * Copyright OpenSearch Contributors\n" +
// " * SPDX-License-Identifier: Apache-2.0\n" +
// " */\n\n")
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
}
}
120 changes: 0 additions & 120 deletions config/checkstyle/checkstyle.xml

This file was deleted.

Loading

0 comments on commit 09d222b

Please sign in to comment.