Skip to content

Commit 1ded771

Browse files
committed
Introduce Spotless with Google Java Format
1 parent 4d0615a commit 1ded771

24 files changed

Lines changed: 601 additions & 567 deletions

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ indent_style = space
2121
indent_size = 4
2222

2323
[*.java]
24-
indent_style = tab
25-
tab_width = 4
24+
indent_style = space
25+
indent_size = 2
2626
ij_continuation_indent_size = 4
2727
### import rules
2828
# explicitly disable imports on demand

build.gradle.kts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins {
1515
id("maven-publish")
1616
id("signing")
1717
id("org.jreleaser") version "latest.release"
18+
id("com.diffplug.spotless") version "latest.release"
1819
}
1920

2021
group = "de.cronn"
@@ -29,6 +30,20 @@ repositories {
2930
mavenCentral()
3031
}
3132

33+
spotless {
34+
java {
35+
googleJavaFormat()
36+
removeUnusedImports()
37+
trimTrailingWhitespace()
38+
endWithNewline()
39+
}
40+
kotlinGradle {
41+
ktlint()
42+
trimTrailingWhitespace()
43+
endWithNewline()
44+
}
45+
}
46+
3247
tasks.bootJar {
3348
enabled = false
3449
}

buildscript-gradle.lockfile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4+
com.diffplug.durian:durian-collect:1.2.0=classpath
5+
com.diffplug.durian:durian-core:1.2.0=classpath
6+
com.diffplug.durian:durian-io:1.2.0=classpath
7+
com.diffplug.durian:durian-swt.os:4.3.0=classpath
8+
com.diffplug.spotless:com.diffplug.spotless.gradle.plugin:8.4.0=classpath
9+
com.diffplug.spotless:spotless-lib-extra:4.5.0=classpath
10+
com.diffplug.spotless:spotless-lib:4.5.0=classpath
11+
com.diffplug.spotless:spotless-plugin-gradle:8.4.0=classpath
412
com.fasterxml.jackson.core:jackson-annotations:2.21=classpath
513
com.fasterxml.jackson.core:jackson-core:2.21.2=classpath
614
com.fasterxml.jackson.core:jackson-databind:2.21.2=classpath
@@ -17,13 +25,18 @@ com.github.spullara.mustache.java:compiler:0.9.14=classpath
1725
com.github.victools:jsonschema-generator:4.38.0=classpath
1826
com.github.victools:jsonschema-module-jackson:4.38.0=classpath
1927
com.google.code.findbugs:jsr305:3.0.2=classpath
20-
com.googlecode.javaewah:JavaEWAH:1.1.13=classpath
28+
com.googlecode.concurrent-trees:concurrent-trees:2.6.1=classpath
29+
com.googlecode.javaewah:JavaEWAH:1.2.3=classpath
2130
com.hierynomus:asn-one:0.6.0=classpath
2231
com.hierynomus:sshj:0.40.0=classpath
32+
com.squareup.okhttp3:okhttp:4.12.0=classpath
33+
com.squareup.okio:okio-jvm:3.6.0=classpath
34+
com.squareup.okio:okio:3.6.0=classpath
2335
commons-codec:commons-codec:1.22.0=classpath
2436
commons-io:commons-io:2.22.0=classpath
2537
commons-logging:commons-logging:1.3.5=classpath
2638
commons-net:commons-net:3.13.0=classpath
39+
dev.equo.ide:solstice:1.8.1=classpath
2740
dev.failsafe:failsafe:3.3.2=classpath
2841
io.github.openfeign.form:feign-form:3.8.0=classpath
2942
io.github.openfeign:feign-core:13.12=classpath
@@ -60,8 +73,14 @@ org.codehaus.plexus:plexus-utils:3.2.1=classpath
6073
org.codehaus.woodstox:stax2-api:4.2.2=classpath
6174
org.commonmark:commonmark-ext-autolink:0.21.0=classpath
6275
org.commonmark:commonmark:0.21.0=classpath
63-
org.eclipse.jgit:org.eclipse.jgit:5.13.5.202508271544-r=classpath
76+
org.eclipse.jgit:org.eclipse.jgit:7.5.0.202512021534-r=classpath
77+
org.eclipse.platform:org.eclipse.osgi:3.24.100=classpath
6478
org.eclipse.sisu:org.eclipse.sisu.inject:0.3.4=classpath
79+
org.jetbrains.kotlin:kotlin-stdlib-common:2.3.20=classpath
80+
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10=classpath
81+
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10=classpath
82+
org.jetbrains.kotlin:kotlin-stdlib:2.3.20=classpath
83+
org.jetbrains:annotations:13.0=classpath
6584
org.jreleaser:jreleaser-artifactory-java-sdk:1.24.0=classpath
6685
org.jreleaser:jreleaser-azure-java-sdk:1.24.0=classpath
6786
org.jreleaser:jreleaser-bluesky-java-sdk:1.24.0=classpath

src/main/java/de/cronn/liquibase/ext/postgres/AbstractPostgresEnumChange.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
import java.util.Arrays;
44
import java.util.List;
5-
65
import liquibase.change.AbstractChange;
76
import liquibase.database.Database;
87
import liquibase.database.core.PostgresDatabase;
98

109
abstract class AbstractPostgresEnumChange extends AbstractChange {
1110

12-
protected static List<String> splitListOfValues(String valuesToAdd) {
13-
return Arrays.stream(valuesToAdd.split(",")).map(String::trim).toList();
14-
}
15-
16-
@Override
17-
public boolean supports(Database database) {
18-
return database instanceof PostgresDatabase && super.supports(database);
19-
}
11+
protected static List<String> splitListOfValues(String valuesToAdd) {
12+
return Arrays.stream(valuesToAdd.split(",")).map(String::trim).toList();
13+
}
2014

15+
@Override
16+
public boolean supports(Database database) {
17+
return database instanceof PostgresDatabase && super.supports(database);
18+
}
2119
}
Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package de.cronn.liquibase.ext.postgres;
22

33
import java.util.List;
4-
54
import liquibase.change.ChangeMetaData;
65
import liquibase.change.DatabaseChange;
76
import liquibase.change.DatabaseChangeProperty;
@@ -10,58 +9,62 @@
109
import liquibase.statement.SqlStatement;
1110
import liquibase.statement.core.RawParameterizedSqlStatement;
1211

13-
@DatabaseChange(name = "addPostgresEnumValues",
14-
description = "Adds enum values to an existing Postgres enum type",
15-
priority = ChangeMetaData.PRIORITY_DEFAULT)
12+
@DatabaseChange(
13+
name = "addPostgresEnumValues",
14+
description = "Adds enum values to an existing Postgres enum type",
15+
priority = ChangeMetaData.PRIORITY_DEFAULT)
1616
public class AddPostgresEnumValuesChange extends AbstractPostgresEnumChange {
1717

18-
private String enumTypeName;
19-
private List<String> valuesToAdd;
18+
private String enumTypeName;
19+
private List<String> valuesToAdd;
2020

21-
public AddPostgresEnumValuesChange() {
22-
}
21+
public AddPostgresEnumValuesChange() {}
2322

24-
public AddPostgresEnumValuesChange(String enumTypeName, List<String> valuesToAdd) {
25-
this.enumTypeName = enumTypeName;
26-
this.valuesToAdd = valuesToAdd;
27-
}
23+
public AddPostgresEnumValuesChange(String enumTypeName, List<String> valuesToAdd) {
24+
this.enumTypeName = enumTypeName;
25+
this.valuesToAdd = valuesToAdd;
26+
}
2827

29-
@Override
30-
public ValidationErrors validate(Database database) {
31-
ValidationErrors validationErrors = super.validate(database);
32-
validationErrors.checkRequiredField("enumTypeName", enumTypeName);
33-
validationErrors.checkRequiredField("valuesToAdd", valuesToAdd);
34-
return validationErrors;
35-
}
28+
@Override
29+
public ValidationErrors validate(Database database) {
30+
ValidationErrors validationErrors = super.validate(database);
31+
validationErrors.checkRequiredField("enumTypeName", enumTypeName);
32+
validationErrors.checkRequiredField("valuesToAdd", valuesToAdd);
33+
return validationErrors;
34+
}
3635

37-
@DatabaseChangeProperty(description = "The name of the enum type", exampleValue = "color")
38-
public String getEnumTypeName() {
39-
return enumTypeName;
40-
}
36+
@DatabaseChangeProperty(description = "The name of the enum type", exampleValue = "color")
37+
public String getEnumTypeName() {
38+
return enumTypeName;
39+
}
4140

42-
public void setEnumTypeName(String enumTypeName) {
43-
this.enumTypeName = enumTypeName;
44-
}
41+
public void setEnumTypeName(String enumTypeName) {
42+
this.enumTypeName = enumTypeName;
43+
}
4544

46-
@DatabaseChangeProperty(description = "The comma-separated list of new values of the enum type",
47-
exampleValue = "RED, GREEN")
48-
public String getValuesToAdd() {
49-
return String.join(", ", valuesToAdd);
50-
}
45+
@DatabaseChangeProperty(
46+
description = "The comma-separated list of new values of the enum type",
47+
exampleValue = "RED, GREEN")
48+
public String getValuesToAdd() {
49+
return String.join(", ", valuesToAdd);
50+
}
5151

52-
public void setValuesToAdd(String valuesToAdd) {
53-
this.valuesToAdd = splitListOfValues(valuesToAdd);
54-
}
52+
public void setValuesToAdd(String valuesToAdd) {
53+
this.valuesToAdd = splitListOfValues(valuesToAdd);
54+
}
5555

56-
@Override
57-
public String getConfirmationMessage() {
58-
return "Added value %s to enum %s".formatted(getValuesToAdd(), getEnumTypeName());
59-
}
56+
@Override
57+
public String getConfirmationMessage() {
58+
return "Added value %s to enum %s".formatted(getValuesToAdd(), getEnumTypeName());
59+
}
6060

61-
@Override
62-
public SqlStatement[] generateStatements(Database database) {
63-
return valuesToAdd.stream()
64-
.map(valueToAdd -> new RawParameterizedSqlStatement("alter type %s add value '%s'".formatted(enumTypeName, valueToAdd)))
65-
.toArray(SqlStatement[]::new);
66-
}
61+
@Override
62+
public SqlStatement[] generateStatements(Database database) {
63+
return valuesToAdd.stream()
64+
.map(
65+
valueToAdd ->
66+
new RawParameterizedSqlStatement(
67+
"alter type %s add value '%s'".formatted(enumTypeName, valueToAdd)))
68+
.toArray(SqlStatement[]::new);
69+
}
6770
}

src/main/java/de/cronn/liquibase/ext/postgres/CreatePostgresEnumTypeChange.java

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.List;
55
import java.util.stream.Collectors;
6-
76
import liquibase.change.ChangeMetaData;
87
import liquibase.change.DatabaseChange;
98
import liquibase.change.DatabaseChangeProperty;
@@ -13,64 +12,64 @@
1312
import liquibase.statement.core.RawParameterizedSqlStatement;
1413

1514
@DatabaseChange(
16-
name = "createPostgresEnumType",
17-
description = "Creates a Postgres enum type",
18-
priority = ChangeMetaData.PRIORITY_DEFAULT)
15+
name = "createPostgresEnumType",
16+
description = "Creates a Postgres enum type",
17+
priority = ChangeMetaData.PRIORITY_DEFAULT)
1918
public class CreatePostgresEnumTypeChange extends AbstractPostgresEnumChange {
2019

21-
private String name;
22-
private List<String> values = new ArrayList<>();
20+
private String name;
21+
private List<String> values = new ArrayList<>();
2322

24-
public CreatePostgresEnumTypeChange() {
25-
}
23+
public CreatePostgresEnumTypeChange() {}
2624

27-
public CreatePostgresEnumTypeChange(String name, List<String> values) {
28-
this.name = name;
29-
this.values = values;
30-
}
25+
public CreatePostgresEnumTypeChange(String name, List<String> values) {
26+
this.name = name;
27+
this.values = values;
28+
}
3129

32-
@Override
33-
public ValidationErrors validate(Database database) {
34-
ValidationErrors validationErrors = super.validate(database);
35-
validationErrors.checkRequiredField("name", name);
36-
validationErrors.checkRequiredField("values", values);
37-
return validationErrors;
38-
}
30+
@Override
31+
public ValidationErrors validate(Database database) {
32+
ValidationErrors validationErrors = super.validate(database);
33+
validationErrors.checkRequiredField("name", name);
34+
validationErrors.checkRequiredField("values", values);
35+
return validationErrors;
36+
}
3937

40-
@DatabaseChangeProperty(
41-
description = "The name of the enum type",
42-
exampleValue = "color")
43-
public String getName() {
44-
return name;
45-
}
38+
@DatabaseChangeProperty(description = "The name of the enum type", exampleValue = "color")
39+
public String getName() {
40+
return name;
41+
}
4642

47-
public void setName(String name) {
48-
this.name = name;
49-
}
43+
public void setName(String name) {
44+
this.name = name;
45+
}
5046

51-
@DatabaseChangeProperty(
52-
description = "The comma-separated list of values of the enum type",
53-
exampleValue = "red, green, blue")
54-
public String getValues() {
55-
return String.join(", ", values);
56-
}
47+
@DatabaseChangeProperty(
48+
description = "The comma-separated list of values of the enum type",
49+
exampleValue = "red, green, blue")
50+
public String getValues() {
51+
return String.join(", ", values);
52+
}
5753

58-
public void setValues(String values) {
59-
this.values = splitListOfValues(values);
60-
}
54+
public void setValues(String values) {
55+
this.values = splitListOfValues(values);
56+
}
6157

62-
@Override
63-
public String getConfirmationMessage() {
64-
return "Created enum type %s".formatted(getName());
65-
}
58+
@Override
59+
public String getConfirmationMessage() {
60+
return "Created enum type %s".formatted(getName());
61+
}
6662

67-
@Override
68-
public SqlStatement[] generateStatements(Database database) {
69-
String valuesForSql = values.stream().map(value -> "'" + value + "'").collect(Collectors.joining(", "));
70-
return new SqlStatement[] {
71-
new RawParameterizedSqlStatement("create type %s as enum (%s)".formatted(name, valuesForSql)),
72-
new RawParameterizedSqlStatement("create cast (varchar as %s) with inout as implicit".formatted(name)),
73-
new RawParameterizedSqlStatement("create cast (%s as varchar) with inout as implicit".formatted(name))
74-
};
75-
}
63+
@Override
64+
public SqlStatement[] generateStatements(Database database) {
65+
String valuesForSql =
66+
values.stream().map(value -> "'" + value + "'").collect(Collectors.joining(", "));
67+
return new SqlStatement[] {
68+
new RawParameterizedSqlStatement("create type %s as enum (%s)".formatted(name, valuesForSql)),
69+
new RawParameterizedSqlStatement(
70+
"create cast (varchar as %s) with inout as implicit".formatted(name)),
71+
new RawParameterizedSqlStatement(
72+
"create cast (%s as varchar) with inout as implicit".formatted(name))
73+
};
74+
}
7675
}

0 commit comments

Comments
 (0)