Skip to content

Commit 92664eb

Browse files
committed
Fix round-tripping of DBeaver step.
1 parent 50429a8 commit 92664eb

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616
package com.diffplug.spotless.sql;
1717

1818
import java.io.File;
19-
import java.io.Serializable;
2019

2120
import com.diffplug.spotless.FileSignature;
2221
import com.diffplug.spotless.FormatterFunc;
@@ -32,24 +31,14 @@ public class DBeaverSQLFormatterStep {
3231
private DBeaverSQLFormatterStep() {}
3332

3433
public static FormatterStep create(Iterable<File> files) {
35-
return FormatterStep.createLazy(NAME,
36-
() -> new State(files),
37-
State::createFormat);
34+
return FormatterStep.create(NAME, FileSignature.promise(files),
35+
FileSignature.Promised::get,
36+
DBeaverSQLFormatterStep::createFormat);
3837
}
3938

40-
static final class State implements Serializable {
41-
private static final long serialVersionUID = 1L;
42-
43-
final FileSignature settingsSignature;
44-
45-
State(final Iterable<File> settingsFiles) throws Exception {
46-
this.settingsSignature = FileSignature.signAsList(settingsFiles);
47-
}
48-
49-
FormatterFunc createFormat() throws Exception {
50-
FormatterProperties preferences = FormatterProperties.from(settingsSignature.files());
51-
DBeaverSQLFormatter dbeaverSqlFormatter = new DBeaverSQLFormatter(preferences.getProperties());
52-
return dbeaverSqlFormatter::format;
53-
}
39+
private static FormatterFunc createFormat(FileSignature settings) {
40+
FormatterProperties preferences = FormatterProperties.from(settings.files());
41+
DBeaverSQLFormatter dbeaverSqlFormatter = new DBeaverSQLFormatter(preferences.getProperties());
42+
return dbeaverSqlFormatter::format;
5443
}
5544
}

testlib/src/test/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStepTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
2929
class DBeaverSQLFormatterStepTest extends ResourceHarness {
3030

3131
@Test
32-
void behavior() throws Exception {
32+
void behavior() {
3333
FormatterStep step = DBeaverSQLFormatterStep.create(Collections.emptySet());
3434
StepHarness.forStep(step)
3535
.testResource("sql/dbeaver/full.dirty", "sql/dbeaver/full.clean")
@@ -40,21 +40,21 @@ void behavior() throws Exception {
4040
}
4141

4242
@Test
43-
void behaviorWithConfigFile() throws Exception {
43+
void behaviorWithConfigFile() {
4444
FormatterStep step = DBeaverSQLFormatterStep.create(createTestFiles("sql/dbeaver/sqlConfig.properties"));
4545
StepHarness.forStep(step)
4646
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean");
4747
}
4848

4949
@Test
50-
void behaviorWithAlternativeConfigFile() throws Exception {
50+
void behaviorWithAlternativeConfigFile() {
5151
FormatterStep step = DBeaverSQLFormatterStep.create(createTestFiles("sql/dbeaver/sqlConfig2.properties"));
5252
StepHarness.forStep(step)
5353
.testResource("sql/dbeaver/create.dirty", "sql/dbeaver/create.clean.alternative");
5454
}
5555

5656
@Test
57-
void equality() throws Exception {
57+
void equality() {
5858
List<File> sqlConfig1 = createTestFiles("sql/dbeaver/sqlConfig.properties");
5959
List<File> sqlConfig2 = createTestFiles("sql/dbeaver/sqlConfig2.properties");
6060
new SerializableEqualityTester() {

0 commit comments

Comments
 (0)