Skip to content

Commit d5cc40e

Browse files
authored
style: make intellij and spotless formatting consistent (#8)
1 parent b0f81c9 commit d5cc40e

File tree

65 files changed

+5189
-4884
lines changed

Some content is hidden

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

65 files changed

+5189
-4884
lines changed

.editorconfig

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# This .editorconfig section approximates ktfmt's formatting rules. You can include it in an
2+
# existing .editorconfig file or use it standalone by copying it to <project root>/.editorconfig
3+
# and making sure your editor is set to read settings from .editorconfig files.
4+
#
5+
# It includes editor-specific config options for IntelliJ IDEA.
6+
#
7+
# If any option is wrong, PR are welcome
8+
9+
[*]
10+
max_line_length = unset
11+
12+
[pom.xml]
13+
max_line_length = 180
14+
15+
[{*.kt,*.kts}]
16+
indent_style = space
17+
insert_final_newline = true
18+
max_line_length = 100
19+
indent_size = 2
20+
ij_continuation_indent_size = 4
21+
ij_java_names_count_to_use_import_on_demand = 9999
22+
ij_kotlin_align_in_columns_case_branch = false
23+
ij_kotlin_align_multiline_binary_operation = false
24+
ij_kotlin_align_multiline_extends_list = false
25+
ij_kotlin_align_multiline_method_parentheses = false
26+
ij_kotlin_align_multiline_parameters = true
27+
ij_kotlin_align_multiline_parameters_in_calls = false
28+
ij_kotlin_allow_trailing_comma = true
29+
ij_kotlin_allow_trailing_comma_on_call_site = true
30+
ij_kotlin_assignment_wrap = normal
31+
ij_kotlin_blank_lines_after_class_header = 0
32+
ij_kotlin_blank_lines_around_block_when_branches = 0
33+
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
34+
ij_kotlin_block_comment_at_first_column = true
35+
ij_kotlin_call_parameters_new_line_after_left_paren = true
36+
ij_kotlin_call_parameters_right_paren_on_new_line = false
37+
ij_kotlin_call_parameters_wrap = on_every_item
38+
ij_kotlin_catch_on_new_line = false
39+
ij_kotlin_class_annotation_wrap = split_into_lines
40+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
41+
ij_kotlin_continuation_indent_for_chained_calls = true
42+
ij_kotlin_continuation_indent_for_expression_bodies = true
43+
ij_kotlin_continuation_indent_in_argument_lists = true
44+
ij_kotlin_continuation_indent_in_elvis = false
45+
ij_kotlin_continuation_indent_in_if_conditions = false
46+
ij_kotlin_continuation_indent_in_parameter_lists = false
47+
ij_kotlin_continuation_indent_in_supertype_lists = false
48+
ij_kotlin_else_on_new_line = false
49+
ij_kotlin_enum_constants_wrap = off
50+
ij_kotlin_extends_list_wrap = normal
51+
ij_kotlin_field_annotation_wrap = split_into_lines
52+
ij_kotlin_finally_on_new_line = false
53+
ij_kotlin_if_rparen_on_new_line = false
54+
ij_kotlin_import_nested_classes = false
55+
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
56+
ij_kotlin_keep_blank_lines_before_right_brace = 2
57+
ij_kotlin_keep_blank_lines_in_code = 2
58+
ij_kotlin_keep_blank_lines_in_declarations = 2
59+
ij_kotlin_keep_first_column_comment = true
60+
ij_kotlin_keep_indents_on_empty_lines = false
61+
ij_kotlin_keep_line_breaks = true
62+
ij_kotlin_lbrace_on_next_line = false
63+
ij_kotlin_line_comment_add_space = false
64+
ij_kotlin_line_comment_at_first_column = true
65+
ij_kotlin_method_annotation_wrap = split_into_lines
66+
ij_kotlin_method_call_chain_wrap = normal
67+
ij_kotlin_method_parameters_new_line_after_left_paren = true
68+
ij_kotlin_method_parameters_right_paren_on_new_line = true
69+
ij_kotlin_method_parameters_wrap = on_every_item
70+
ij_kotlin_name_count_to_use_star_import = 9999
71+
ij_kotlin_name_count_to_use_star_import_for_members = 9999
72+
ij_kotlin_parameter_annotation_wrap = off
73+
ij_kotlin_space_after_comma = true
74+
ij_kotlin_space_after_extend_colon = true
75+
ij_kotlin_space_after_type_colon = true
76+
ij_kotlin_space_before_catch_parentheses = true
77+
ij_kotlin_space_before_comma = false
78+
ij_kotlin_space_before_extend_colon = true
79+
ij_kotlin_space_before_for_parentheses = true
80+
ij_kotlin_space_before_if_parentheses = true
81+
ij_kotlin_space_before_lambda_arrow = true
82+
ij_kotlin_space_before_type_colon = false
83+
ij_kotlin_space_before_when_parentheses = true
84+
ij_kotlin_space_before_while_parentheses = true
85+
ij_kotlin_spaces_around_additive_operators = true
86+
ij_kotlin_spaces_around_assignment_operators = true
87+
ij_kotlin_spaces_around_equality_operators = true
88+
ij_kotlin_spaces_around_function_type_arrow = true
89+
ij_kotlin_spaces_around_logical_operators = true
90+
ij_kotlin_spaces_around_multiplicative_operators = true
91+
ij_kotlin_spaces_around_range = false
92+
ij_kotlin_spaces_around_relational_operators = true
93+
ij_kotlin_spaces_around_unary_operator = false
94+
ij_kotlin_spaces_around_when_arrow = true
95+
ij_kotlin_variable_annotation_wrap = off
96+
ij_kotlin_while_on_new_line = false
97+
ij_kotlin_wrap_elvis_expressions = 1
98+
ij_kotlin_wrap_expression_body_functions = 1
99+
ij_kotlin_wrap_first_method_in_call_chain = false

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Neo4j Connector for Kafka
2+
3+
The project provides Neo4j sink and source connector implementations for Kafka Connect platform.
4+
5+
## Documentation & Articles
6+
7+
Read more at https://neo4j.com/docs/kafka/
8+
9+
## Feedback & Suggestions
10+
11+
Please raise [issues on Github](https://github.com/neo4j/neo4j-kafka-connector/issues). We also love contributions, so
12+
don't be shy to send a Pull Request.
13+
14+
## Development & Contributions
15+
16+
### Build locally
17+
18+
First, build and install the `build-resources` module.
19+
20+
```
21+
mvn clean install -f build-resources/pom.xml
22+
```
23+
24+
Then, you can build and package the project using;
25+
26+
```
27+
mvn clean package
28+
```
29+
30+
You'll find the connector archive
31+
at `kafka-connect-neo4j/target/components/packages/neo4j-kafka-connect-neo4j-{version}.zip`.
32+
33+
### Code Format
34+
35+
For Kotlin code, we follow the [ktfmt](https://github.com/facebook/ktfmt) code style. There is an `.editorconfig` file
36+
to mimic the underlying style guides for built-in Intellij code style rules, but we recommend
37+
[ktfmt IntelliJ Plugin](https://plugins.jetbrains.com/plugin/14912-ktfmt) for formatting. Remember that your builds will
38+
fail if your changes doesn't match the enforced code style, but you can use `./mvnw spotless:apply` to format your code.
39+
40+
For POM files, we are using [sortpom](https://github.com/Ekryd/sortpom) to have a tidier project object model. Remember
41+
that your builds will fail if your changes doesn't conform to the enforced rules, but you can use `./mvnw sortpom:sort`
42+
to format it accordingly.
43+
44+
### Docs
45+
46+
The documentation source for this version lives at [this repository](https://github.com/neo4j/docs-kafka-connector).
47+
Please raise any documentation updates by creating a PR against it.
48+
49+
## License
50+
51+
Neo4j Connector for Kafka is licensed under the terms of the Apache License, version 2.0. See `LICENSE` for more
52+
details.

common/src/main/kotlin/streams/events/StreamsEvent.kt

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ enum class OperationType {
2323
}
2424

2525
data class Meta(
26-
val timestamp: Long,
27-
val username: String,
28-
val txId: Long,
29-
val txEventId: Int,
30-
val txEventsCount: Int,
31-
val operation: OperationType,
32-
val source: Map<String, Any> = emptyMap()
26+
val timestamp: Long,
27+
val username: String,
28+
val txId: Long,
29+
val txEventId: Int,
30+
val txEventsCount: Int,
31+
val operation: OperationType,
32+
val source: Map<String, Any> = emptyMap()
3333
)
3434

3535
enum class EntityType {
@@ -38,17 +38,17 @@ enum class EntityType {
3838
}
3939

4040
data class RelationshipNodeChange(
41-
val id: String,
42-
val labels: List<String>?,
43-
val ids: Map<String, Any>
41+
val id: String,
42+
val labels: List<String>?,
43+
val ids: Map<String, Any>
4444
)
4545

4646
abstract class RecordChange {
4747
abstract val properties: Map<String, Any>?
4848
}
4949

5050
data class NodeChange(override val properties: Map<String, Any>?, val labels: List<String>?) :
51-
RecordChange()
51+
RecordChange()
5252

5353
data class RelationshipChange(override val properties: Map<String, Any>?) : RecordChange()
5454

@@ -60,20 +60,20 @@ abstract class Payload {
6060
}
6161

6262
data class NodePayload(
63-
override val id: String,
64-
override val before: NodeChange?,
65-
override val after: NodeChange?,
66-
override val type: EntityType = EntityType.node
63+
override val id: String,
64+
override val before: NodeChange?,
65+
override val after: NodeChange?,
66+
override val type: EntityType = EntityType.node
6767
) : Payload()
6868

6969
data class RelationshipPayload(
70-
override val id: String,
71-
val start: RelationshipNodeChange,
72-
val end: RelationshipNodeChange,
73-
override val before: RelationshipChange?,
74-
override val after: RelationshipChange?,
75-
val label: String,
76-
override val type: EntityType = EntityType.relationship
70+
override val id: String,
71+
val start: RelationshipNodeChange,
72+
val end: RelationshipNodeChange,
73+
override val before: RelationshipChange?,
74+
override val after: RelationshipChange?,
75+
val label: String,
76+
override val type: EntityType = EntityType.relationship
7777
) : Payload()
7878

7979
enum class StreamsConstraintType {
@@ -88,36 +88,36 @@ enum class RelKeyStrategy {
8888
}
8989

9090
data class Constraint(
91-
val label: String?,
92-
val properties: Set<String>,
93-
val type: StreamsConstraintType
91+
val label: String?,
92+
val properties: Set<String>,
93+
val type: StreamsConstraintType
9494
)
9595

9696
data class Schema(
97-
val properties: Map<String, String> = emptyMap(),
98-
val constraints: List<Constraint> = emptyList()
97+
val properties: Map<String, String> = emptyMap(),
98+
val constraints: List<Constraint> = emptyList()
9999
)
100100

101101
open class StreamsEvent(open val payload: Any)
102102

103103
data class StreamsTransactionEvent(
104-
val meta: Meta,
105-
override val payload: Payload,
106-
val schema: Schema
104+
val meta: Meta,
105+
override val payload: Payload,
106+
val schema: Schema
107107
) : StreamsEvent(payload)
108108

109109
data class StreamsTransactionNodeEvent(
110-
val meta: Meta,
111-
val payload: NodePayload,
112-
val schema: Schema
110+
val meta: Meta,
111+
val payload: NodePayload,
112+
val schema: Schema
113113
) {
114114
fun toStreamsTransactionEvent() = StreamsTransactionEvent(this.meta, this.payload, this.schema)
115115
}
116116

117117
data class StreamsTransactionRelationshipEvent(
118-
val meta: Meta,
119-
val payload: RelationshipPayload,
120-
val schema: Schema
118+
val meta: Meta,
119+
val payload: RelationshipPayload,
120+
val schema: Schema
121121
) {
122122
fun toStreamsTransactionEvent() = StreamsTransactionEvent(this.meta, this.payload, this.schema)
123123
}

common/src/main/kotlin/streams/extensions/CommonExtensions.kt

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ import streams.service.StreamsSinkEntity
2828
import streams.utils.JSONUtils
2929

3030
fun Map<String, String>.getInt(name: String, defaultValue: Int) =
31-
this.get(name)?.toInt() ?: defaultValue
31+
this.get(name)?.toInt() ?: defaultValue
3232

3333
fun Map<*, *>.asProperties() =
34-
this.let {
35-
val properties = Properties()
36-
properties.putAll(it)
37-
properties
38-
}
34+
this.let {
35+
val properties = Properties()
36+
properties.putAll(it)
37+
properties
38+
}
3939

4040
fun Node.asStreamsMap(): Map<String, Any?> {
4141
val nodeMap = this.asMap().toMutableMap()
@@ -60,47 +60,46 @@ fun String.toPointCase(): String {
6060
fun String.quote(): String = if (SourceVersion.isIdentifier(this)) this else "`$this`"
6161

6262
fun Map<String, Any?>.flatten(
63-
map: Map<String, Any?> = this,
64-
prefix: String = ""
63+
map: Map<String, Any?> = this,
64+
prefix: String = ""
6565
): Map<String, Any?> {
66-
return map
67-
.flatMap {
68-
val key = it.key
69-
val value = it.value
70-
val newKey = if (prefix != "") "$prefix.$key" else key
71-
if (value is Map<*, *>) {
72-
flatten(value as Map<String, Any>, newKey).toList()
73-
} else {
74-
listOf(newKey to value)
66+
return map.flatMap {
67+
val key = it.key
68+
val value = it.value
69+
val newKey = if (prefix != "") "$prefix.$key" else key
70+
if (value is Map<*, *>) {
71+
flatten(value as Map<String, Any>, newKey).toList()
72+
} else {
73+
listOf(newKey to value)
74+
}
7575
}
76-
}
77-
.toMap()
76+
.toMap()
7877
}
7978

8079
fun ConsumerRecord<*, *>.topicPartition() = TopicPartition(this.topic(), this.partition())
8180

8281
fun ConsumerRecord<*, *>.offsetAndMetadata(metadata: String = "") =
83-
OffsetAndMetadata(this.offset() + 1, metadata)
82+
OffsetAndMetadata(this.offset() + 1, metadata)
8483

8584
private fun convertAvroData(rawValue: Any?): Any? =
86-
when (rawValue) {
87-
is Collection<*> -> rawValue.map(::convertAvroData)
88-
is Array<*> ->
89-
if (rawValue.javaClass.componentType.isPrimitive) rawValue
90-
else rawValue.map(::convertAvroData)
91-
is Map<*, *> -> rawValue.mapKeys { it.key.toString() }.mapValues { convertAvroData(it.value) }
92-
is ByteBuffer -> rawValue.array()
93-
is CharSequence -> rawValue.toString()
94-
else -> rawValue
95-
}
85+
when (rawValue) {
86+
is Collection<*> -> rawValue.map(::convertAvroData)
87+
is Array<*> ->
88+
if (rawValue.javaClass.componentType.isPrimitive) rawValue
89+
else rawValue.map(::convertAvroData)
90+
is Map<*, *> -> rawValue.mapKeys { it.key.toString() }.mapValues { convertAvroData(it.value) }
91+
is ByteBuffer -> rawValue.array()
92+
is CharSequence -> rawValue.toString()
93+
else -> rawValue
94+
}
9695

9796
private fun convertData(data: Any?, stringWhenFailure: Boolean = false): Any? {
9897
return when (data) {
9998
null -> null
10099
is ByteArray -> JSONUtils.readValue<Any>(data, stringWhenFailure)
101100
else ->
102-
if (stringWhenFailure) data.toString()
103-
else throw RuntimeException("Unsupported type ${data::class.java.name}")
101+
if (stringWhenFailure) data.toString()
102+
else throw RuntimeException("Unsupported type ${data::class.java.name}")
104103
}
105104
}
106105

common/src/main/kotlin/streams/extensions/CoroutineExtensions.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ suspend fun <T> List<Deferred<T>>.awaitAll(timeoutMs: Long): List<T> {
5353

5454
@ExperimentalCoroutinesApi
5555
fun <T> Deferred<T>.errors() =
56-
when {
57-
isCompleted -> getCompletionExceptionOrNull()
58-
isCancelled -> getCompletionExceptionOrNull() // was getCancellationException()
59-
isActive -> RuntimeException("Job $this still active")
60-
else -> null
61-
}
56+
when {
57+
isCompleted -> getCompletionExceptionOrNull()
58+
isCancelled -> getCompletionExceptionOrNull() // was getCancellationException()
59+
isActive -> RuntimeException("Job $this still active")
60+
else -> null
61+
}

0 commit comments

Comments
 (0)