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

Chore/formatting test #1192

Merged
merged 8 commits into from
May 2, 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
19 changes: 18 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,26 @@ 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")
}
}

// Add the custom command to the 'formatAll' alias
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.
*/
45 changes: 25 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 @@ -56,7 +56,9 @@ allprojects {

//lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.30'
testCompileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.30'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion

//tests
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoJupiterVersion
Expand All @@ -75,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 @@ -145,8 +131,27 @@ 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 {
googleJavaFormat().reflowLongStrings().skipJavadocFormatting()
removeUnusedImports()
licenseHeaderFile(rootProject.file("HEADER.txt"))
}
}

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

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

Expand All @@ -162,7 +167,7 @@ task prepareRelease(dependsOn: [collectFatJar]) {

task releaseModuleList() {
def nonReleaseModules = ["java-reactor", "kafka-connect-cloud-common",
"kafka-connect-common", "kafka-connect-query-language"]
"kafka-connect-common", "kafka-connect-query-language"]

def modulesFile = new File("gradle-modules.txt")
modulesFile.delete()
Expand Down
2 changes: 1 addition & 1 deletion java-connectors/kafka-connect-azure-eventhubs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ project(':kafka-connect-azure-eventhubs') {
// implementation group: 'com.azure', name: 'azure-messaging-eventhubs-checkpointstore-blob', version: '1.19.0'

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@
*/
public class AzureEventHubsConfigConstants {


private static final String DOT = ".";
public static final String OPTIONAL_EMPTY_DEFAULT = "";
public static final String CONNECTOR_PREFIX = "connect.eventhubs";
public static final String SOURCE_CONNECTOR_PREFIX = CONNECTOR_PREFIX + DOT + "source";

public static final String CONNECTOR_NAME = "name";
public static final String CONNECTOR_NAME_DOC = "Connector's name";
public static final String CONNECTOR_NAME_DEFAULT = AzureEventHubsSourceConnector.class.getSimpleName();
public static final String CONNECTOR_NAME_DEFAULT =
AzureEventHubsSourceConnector.class.getSimpleName();

public static final String CONNECTOR_WITH_CONSUMER_PREFIX =
SOURCE_CONNECTOR_PREFIX + DOT + "connection.settings" + DOT;
public static final String CONSUMER_OFFSET = SOURCE_CONNECTOR_PREFIX + DOT + "default.offset";
public static final String CONSUMER_OFFSET_DOC =
"Specifies whether by default we should consumer from earliest (default) or latest offset.";
public static final String CONSUMER_OFFSET_DEFAULT = "earliest";
public static final String CONSUMER_CLOSE_TIMEOUT = SOURCE_CONNECTOR_PREFIX + DOT + "close.timeout";
public static final String CONSUMER_CLOSE_TIMEOUT_DOC =
"Specifies timeout for consumer closing.";
public static final String CONSUMER_CLOSE_TIMEOUT =
SOURCE_CONNECTOR_PREFIX + DOT + "close.timeout";
public static final String CONSUMER_CLOSE_TIMEOUT_DOC = "Specifies timeout for consumer closing.";
public static final String CONSUMER_CLOSE_TIMEOUT_DEFAULT = "30";

public static final String KCQL_CONFIG = CONNECTOR_PREFIX + DOT + "kcql";
public static final String KCQL_DOC =
"KCQL expression describing field selection and data routing to the target.";

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,62 @@ public class AzureEventHubsSourceConfig extends BaseConfig implements ConnectorP

public static final String CONNECTION_GROUP = "Connection";

private static final UnaryOperator<String> CONFIG_NAME_PREFIX_APPENDER = name ->
AzureEventHubsConfigConstants.CONNECTOR_WITH_CONSUMER_PREFIX + name;
private static final UnaryOperator<String> CONFIG_NAME_PREFIX_APPENDER =
name -> AzureEventHubsConfigConstants.CONNECTOR_WITH_CONSUMER_PREFIX + name;

private static final Set<String> EXCLUDED_CONSUMER_PROPERTIES =
Set.of(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
ConsumerConfig.GROUP_ID_CONFIG, ConsumerConfig.CLIENT_ID_CONFIG, ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG);
Set.of(
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
ConsumerConfig.GROUP_ID_CONFIG,
ConsumerConfig.CLIENT_ID_CONFIG,
ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG);


@Getter
static ConfigDef configDefinition;
@Getter static ConfigDef configDefinition;

static {
ConfigDef kafkaConsumerConfigToExpose = getKafkaConsumerConfigToExpose();
configDefinition = new ConfigDef(kafkaConsumerConfigToExpose)
.define(AzureEventHubsConfigConstants.CONNECTOR_NAME,
Type.STRING,
AzureEventHubsConfigConstants.CONNECTOR_NAME_DEFAULT,
Importance.HIGH,
AzureEventHubsConfigConstants.CONNECTOR_NAME_DOC,
CONNECTION_GROUP,
1,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONNECTOR_NAME
).define(AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT,
Type.INT,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT_DEFAULT,
Importance.MEDIUM,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT_DOC,
CONNECTION_GROUP,
3,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT
)
.define(AzureEventHubsConfigConstants.CONSUMER_OFFSET,
Type.STRING,
AzureEventHubsConfigConstants.CONSUMER_OFFSET_DEFAULT,
Importance.MEDIUM,
AzureEventHubsConfigConstants.CONSUMER_OFFSET_DOC,
CONNECTION_GROUP,
4,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONSUMER_OFFSET
).define(AzureEventHubsConfigConstants.KCQL_CONFIG,
Type.STRING,
Importance.HIGH,
AzureEventHubsConfigConstants.KCQL_DOC,
"Mappings",
1,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.KCQL_CONFIG
);
configDefinition =
new ConfigDef(kafkaConsumerConfigToExpose)
.define(
AzureEventHubsConfigConstants.CONNECTOR_NAME,
Type.STRING,
AzureEventHubsConfigConstants.CONNECTOR_NAME_DEFAULT,
Importance.HIGH,
AzureEventHubsConfigConstants.CONNECTOR_NAME_DOC,
CONNECTION_GROUP,
1,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONNECTOR_NAME)
.define(
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT,
Type.INT,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT_DEFAULT,
Importance.MEDIUM,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT_DOC,
CONNECTION_GROUP,
3,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONSUMER_CLOSE_TIMEOUT)
.define(
AzureEventHubsConfigConstants.CONSUMER_OFFSET,
Type.STRING,
AzureEventHubsConfigConstants.CONSUMER_OFFSET_DEFAULT,
Importance.MEDIUM,
AzureEventHubsConfigConstants.CONSUMER_OFFSET_DOC,
CONNECTION_GROUP,
4,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.CONSUMER_OFFSET)
.define(
AzureEventHubsConfigConstants.KCQL_CONFIG,
Type.STRING,
Importance.HIGH,
AzureEventHubsConfigConstants.KCQL_DOC,
"Mappings",
1,
ConfigDef.Width.LONG,
AzureEventHubsConfigConstants.KCQL_CONFIG);
}

public AzureEventHubsSourceConfig(Map<?, ?> properties) {
Expand All @@ -111,11 +116,18 @@ private static ConfigDef getKafkaConsumerConfigToExpose() {
ConfigDef kafkaConsumerConfigToExpose = new ConfigDef();
ConsumerConfig.configDef().configKeys().values().stream()
.filter(configKey -> !EXCLUDED_CONSUMER_PROPERTIES.contains(configKey.name))
.forEach(configKey -> kafkaConsumerConfigToExpose.define(
CONFIG_NAME_PREFIX_APPENDER.apply(configKey.name),
configKey.type, configKey.defaultValue,
configKey.importance, configKey.documentation, configKey.group,
configKey.orderInGroup, configKey.width, configKey.displayName));
.forEach(
configKey ->
kafkaConsumerConfigToExpose.define(
CONFIG_NAME_PREFIX_APPENDER.apply(configKey.name),
configKey.type,
configKey.defaultValue,
configKey.importance,
configKey.documentation,
configKey.group,
configKey.orderInGroup,
configKey.width,
configKey.displayName));

return kafkaConsumerConfigToExpose;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
@Getter
public enum SourceDataType {

BYTES(ByteArrayDeserializer.class, Schema.OPTIONAL_BYTES_SCHEMA);

private final Class<? extends Deserializer> deserializerClass;
Expand Down
Loading
Loading