Skip to content
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

Experimental Java Autoformatting #1210

Merged
merged 4 commits into from
May 8, 2024
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
5 changes: 4 additions & 1 deletion .github/workflows/java-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ jobs:
with:
gradle-version: 8.6

- name: Check License Headers and Test with Gradle
- name: Formatting and Headers Check
run: cd 'java-connectors' && ./gradlew ${{ matrix.module }}:spotlessCheck

- name: Test with Gradle
run: cd 'java-connectors' && ./gradlew ${{ matrix.module }}:test

build-and-cache:
Expand Down
18 changes: 17 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import sbt.*
import sbt.Project.projectToLocalProject

import java.io.File
import scala.sys.process._

ThisBuild / scalaVersion := Dependencies.scalaVersion

Expand Down Expand Up @@ -474,10 +475,25 @@ addCommandAlias(
"validateAll",
"headerCheck;test:headerCheck;it:headerCheck;fun:headerCheck;scalafmtCheckAll;test-common/scalafmtCheck;test-common/headerCheck",
)

lazy val gradleSpotlessApply = taskKey[Unit]("Run 'gradle spotlessApply' via external process")
gradleSpotlessApply := {
// Specify the desired working directory for the external process
val targetDirectory = baseDirectory.value / "java-connectors"

// Execute 'gradle spotlessApply' in the specified directory
val exitCode = Process("gradle spotlessApply", targetDirectory).!

if (exitCode != 0) {
throw new RuntimeException("gradle spotlessApply command failed")
}
}

addCommandAlias(
"formatAll",
"headerCreateAll;scalafmtAll;scalafmtSbt;test-common/scalafmt;test-common/headerCreateAll",
";headerCreateAll;scalafmtAll;scalafmtSbt;test-common/scalafmt;test-common/headerCreateAll;gradleSpotlessApply",
)

addCommandAlias("fullTest", ";test;it:test;fun:test")
addCommandAlias("fullCoverageTest", ";coverage;test;it:test;coverageReport;coverageAggregate")

Expand Down
28 changes: 15 additions & 13 deletions java-connectors/HEADER.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Copyright 2017-${year} ${name} Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
/*
* Copyright 2017-$YEAR Lenses.io Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
44 changes: 24 additions & 20 deletions java-connectors/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.cadixdev.licenser' version '0.6.1'
id "com.diffplug.spotless" version "6.25.0"
id 'java'
id 'java-library'
}
Expand All @@ -14,7 +14,7 @@ allprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.cadixdev.licenser'
apply plugin: 'com.diffplug.spotless'

java {
setSourceCompatibility(JavaVersion.VERSION_11)
Expand Down Expand Up @@ -77,22 +77,6 @@ allprojects {
}
}

license {
include("**/**.java", "**/**Test.java")
exclude("**/kcql/antlr4/**.java") //antlr generated files
header = project.file("${project.rootDir}/HEADER.txt")
newLine = false

style {
java = 'BLOCK_COMMENT'
}

properties {
name = 'Lenses.io'
year = LocalDate.now().year
}
}

jar {
manifest {
attributes("StreamReactor-Version": project.version,
Expand Down Expand Up @@ -147,14 +131,34 @@ allprojects {
// exclude(dependency("com.google.guava:guava:28.1-android"))
}


spotless {

format 'misc', {
// define the files to apply `misc` to
target '*.gradle', '.gitattributes', '.gitignore'

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
}
java {
toggleOffOn()
// optional: you can specify a specific version and/or config file
eclipse('4.30').configFile("${rootDir}/config/Lenses_eclipse.xml")
licenseHeaderFile(rootProject.file("HEADER.txt"))
}
}

}
compileJava.dependsOn("checkLicenses")
//compileJava.dependsOn("checkLicenses")

task fatJar(dependsOn: [test, jar, shadowJar])

task collectFatJar(type: Copy, dependsOn: [fatJar]) {
from("${buildDir}/libs").include("kafka-connect-*-all.jar")
.exclude("*-common-*").into(libsDir)
.exclude("*-common-*").into(libsDir)
}
}

Expand Down
Loading
Loading