From 7da4090540a0b7d1639e7eda47c9b003367dfe34 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 19:38:48 -0400 Subject: [PATCH 01/18] implement buf format gradle step --- README.md | 1 + .../diffplug/spotless/protobuf/BufStep.java | 99 +++++++++++++++++++ .../spotless/protobuf/ProtobufConstants.java | 20 ++++ plugin-gradle/README.md | 18 ++++ .../gradle/spotless/ProtobufExtension.java | 76 ++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 6 ++ .../gradle/spotless/BufIntegrationTest.java | 55 +++++++++++ .../src/main/resources/protobuf/buf/buf.proto | 5 + .../resources/protobuf/buf/buf.proto.clean | 5 + .../main/resources/protobuf/buf/license.proto | 7 ++ .../protobuf/buf/license.proto.clean | 8 ++ .../spotless/protobuf/BufStepTest.java | 31 ++++++ 12 files changed, 331 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java create mode 100644 lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java create mode 100644 testlib/src/main/resources/protobuf/buf/buf.proto create mode 100644 testlib/src/main/resources/protobuf/buf/buf.proto.clean create mode 100644 testlib/src/main/resources/protobuf/buf/license.proto create mode 100644 testlib/src/main/resources/protobuf/buf/license.proto.clean create mode 100644 testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java diff --git a/README.md b/README.md index f95ea7a7ca..fbdf738104 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ extra('wtp.EclipseWtpFormatterStep') +'{{yes}} | {{yes}} | [`npm.PrettierFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`npm.TsFmtFormatterStep`](lib/src/main/java/com/diffplug/spotless/npm/TsFmtFormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`pom.SortPomStepStep`](lib/src/main/java/com/diffplug/spotless/pom/SortPomStepStep.java) | :white_large_square: | :+1: | :white_large_square: | :white_large_square: | +| [`protobuf.BufStep`](lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`python.BlackStep`](lib/src/main/java/com/diffplug/spotless/python/BlackStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`scala.ScalaFmtStep`](lib/src/main/java/com/diffplug/spotless/scala/ScalaFmtStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`sql.DBeaverSQLFormatterStep`](lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java new file mode 100644 index 0000000000..601a47f193 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -0,0 +1,99 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.spotless.protobuf; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +import javax.annotation.Nullable; + +import com.diffplug.spotless.ForeignExe; +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.ProcessRunner; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +public class BufStep { + public static String name() { + return "buf"; + } + + public static String defaultVersion() { + return "1.4.0"; + } + + private final String version; + private final @Nullable String pathToExe; + + private BufStep(String version, @Nullable String pathToExe) { + this.version = version; + this.pathToExe = pathToExe; + } + + public static BufStep withVersion(String version) { + return new BufStep(version, null); + } + + public BufStep withPathToExe(String pathToExe) { + return new BufStep(version, pathToExe); + } + + public FormatterStep create() { + return FormatterStep.createLazy(name(), this::createState, State::toFunc); + } + + private State createState() throws IOException, InterruptedException { + String instructions = "https://docs.buf.build/installation"; + String exeAbsPath = ForeignExe.nameAndVersion("buf", version) + .pathToExe(pathToExe) + .versionRegex(Pattern.compile("(\\S*)")) + .fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}") + .confirmVersionAndGetAbsolutePath(); + return new State(this, exeAbsPath); + } + + @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") + static class State implements Serializable { + private static final long serialVersionUID = -1825662356883926318L; + // used for up-to-date checks and caching + final String version; + // used for executing + final transient List args; + + State(BufStep step, String exeAbsPath) { + this.version = step.version; + this.args = Arrays.asList(exeAbsPath, "format"); + } + + String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { + String[] processArgs = args.toArray(new String[args.size() + 1]); + // add an argument to the end + processArgs[args.size()] = file.getAbsolutePath(); + return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8); + } + + FormatterFunc.Closeable toFunc() { + ProcessRunner runner = new ProcessRunner(); + return FormatterFunc.Closeable.of(runner, this::format); + } + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java new file mode 100644 index 0000000000..b24df7cc38 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.spotless.protobuf; + +public class ProtobufConstants { + public static final String LICENSE_HEADER_DELIMITER = "syntax"; +} diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 48572377b8..7bf684923c 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -65,6 +65,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Kotlin](#kotlin) ([ktfmt](#ktfmt), [ktlint](#ktlint), [diktat](#diktat), [prettier](#prettier)) - [Scala](#scala) ([scalafmt](#scalafmt)) - [C/C++](#cc) ([clang-format](#clang-format), [eclipse cdt](#eclipse-cdt)) + - [Protobuf](#protobuf) ([buf](#buf), [clang-format](#clang-format)) - [Python](#python) ([black](#black)) - [FreshMark](#freshmark) aka markdown - [Antlr4](#antlr4) ([antlr4formatter](#antlr4formatter)) @@ -457,6 +458,23 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe') +## Protobuf + +### buf + +`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java) + +```gradle +spotless { + protobuf { + // by default the target is every '.proto' file in the project + buf() + + licenseHeader '/* (C) $YEAR */' // or licenseHeaderFile + } +} +``` + ## FreshMark `com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java new file mode 100644 index 0000000000..44565e8073 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -0,0 +1,76 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.gradle.spotless; + +import static com.diffplug.spotless.protobuf.ProtobufConstants.LICENSE_HEADER_DELIMITER; + +import java.util.Objects; + +import javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.protobuf.BufStep; + +public class ProtobufExtension extends FormatExtension implements HasBuiltinDelimiterForLicense { + static final String NAME = "protobuf"; + + @Inject + public ProtobufExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + public LicenseHeaderConfig licenseHeader(String licenseHeader) { + return licenseHeader(licenseHeader, LICENSE_HEADER_DELIMITER); + } + + @Override + public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { + return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); + } + + /** Adds the specified version of ktlint. */ + public BufFormatExtension buf(String version) { + Objects.requireNonNull(version); + return new BufFormatExtension(version); + } + + public BufFormatExtension buf() { + return buf(BufStep.defaultVersion()); + } + + public class BufFormatExtension { + private final String version; + + BufFormatExtension(String version) { + this.version = version; + addStep(createStep()); + } + + private FormatterStep createStep() { + return BufStep.withVersion(version).create(); + } + } + + /** If the user hasn't specified files, assume all protobuf files should be checked. */ + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target = parseTarget("**/*.proto"); + } + super.setupTask(task); + } +} diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 57aa3b2d83..8aa9d2e619 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -188,6 +188,12 @@ public void json(Action closure) { format(JsonExtension.NAME, JsonExtension.class, closure); } + /** Configures the special protobuf-specific extension. */ + public void protobuf(Action closure) { + requireNonNull(closure); + format(ProtobufExtension.NAME, ProtobufExtension.class, closure); + } + /** Configures a custom extension. */ public void format(String name, Action closure) { requireNonNull(name, "name"); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java new file mode 100644 index 0000000000..03f45a46c8 --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.gradle.spotless; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class BufIntegrationTest extends GradleIntegrationHarness { + @Test + void buf() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " protobuf {", + " buf()", + " }", + "}"); + setFile("buf.proto").toResource("protobuf/buf/buf.proto"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("buf.proto").sameAsResource("protobuf/buf/buf.proto.clean"); + } + + @Test + void bufWithLicense() throws IOException { + setFile("build.gradle").toLines( + "plugins {", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " protobuf {", + " buf()", + " licenseHeader '/* (C) 2022 */'", + " }", + "}"); + setFile("license.proto").toResource("protobuf/buf/license.proto"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("license.proto").sameAsResource("protobuf/buf/license.proto.clean"); + } +} diff --git a/testlib/src/main/resources/protobuf/buf/buf.proto b/testlib/src/main/resources/protobuf/buf/buf.proto new file mode 100644 index 0000000000..a90d58bbd0 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/buf.proto @@ -0,0 +1,5 @@ +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} \ No newline at end of file diff --git a/testlib/src/main/resources/protobuf/buf/buf.proto.clean b/testlib/src/main/resources/protobuf/buf/buf.proto.clean new file mode 100644 index 0000000000..faa8d91f24 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/buf.proto.clean @@ -0,0 +1,5 @@ +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/main/resources/protobuf/buf/license.proto b/testlib/src/main/resources/protobuf/buf/license.proto new file mode 100644 index 0000000000..aabedc5093 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/license.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/main/resources/protobuf/buf/license.proto.clean b/testlib/src/main/resources/protobuf/buf/license.proto.clean new file mode 100644 index 0000000000..11761efc28 --- /dev/null +++ b/testlib/src/main/resources/protobuf/buf/license.proto.clean @@ -0,0 +1,8 @@ +/* (C) 2022 */ +syntax = "proto3"; + +message Testing { + required string field1 = 1; + required int32 field2 = 2; + optional string field3 = 3; +} diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java new file mode 100644 index 0000000000..c2079f462f --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.spotless.protobuf; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +import com.diffplug.spotless.StepHarnessWithFile; + +class BufStepTest { + @Test + void test() throws Exception { + try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(BufStep.withVersion(BufStep.defaultVersion()).create())) { + harness.testResource(new File("src/main/resources/protobuf/buf/buf.proto"), "protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean"); + } + } +} From ef357fccb31837434a00680de5b56fc43bb91025 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 19:58:04 -0400 Subject: [PATCH 02/18] update changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d2011de17..bd3b15a4cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Added support for Protobuf formatting based on [Buf](https://buf.build/) (#1208). ## [2.25.3] - 2022-05-10 ### Fixed diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index fe7b0f879f..9d172a4cfd 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Added support for Protobuf formatting based on [Buf](https://buf.build/) (#1208). ## [6.6.0] - 2022-05-10 ### Added From 4e56621aa8858ea528ea5eb0689f55dbd502503a Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 20:02:52 -0400 Subject: [PATCH 03/18] fix bad comment --- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 44565e8073..660f0b3efb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -42,7 +42,7 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } - /** Adds the specified version of ktlint. */ + /** Adds the specified version of buf. */ public BufFormatExtension buf(String version) { Objects.requireNonNull(version); return new BufFormatExtension(version); From 5b16ed1324116bd46f3364d8c5ccca4fce5b6703 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 20:45:28 -0400 Subject: [PATCH 04/18] allow specification of path to exe --- .../gradle/spotless/ProtobufExtension.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 660f0b3efb..59a63b97fd 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -42,6 +42,15 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } + /** If the user hasn't specified files, assume all protobuf files should be checked. */ + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + target = parseTarget("**/*.proto"); + } + super.setupTask(task); + } + /** Adds the specified version of buf. */ public BufFormatExtension buf(String version) { Objects.requireNonNull(version); @@ -53,24 +62,21 @@ public BufFormatExtension buf() { } public class BufFormatExtension { - private final String version; + BufStep step; BufFormatExtension(String version) { - this.version = version; + this.step = BufStep.withVersion(version); addStep(createStep()); } - private FormatterStep createStep() { - return BufStep.withVersion(version).create(); + public BufFormatExtension pathToExe(String pathToExe) { + step = step.withPathToExe(pathToExe); + replaceStep(createStep()); + return this; } - } - /** If the user hasn't specified files, assume all protobuf files should be checked. */ - @Override - protected void setupTask(SpotlessTask task) { - if (target == null) { - target = parseTarget("**/*.proto"); + private FormatterStep createStep() { + return step.create(); } - super.setupTask(task); } } From 85759c82067a2f1104b9b0ddfdaef51c50acf500 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:03:04 -0400 Subject: [PATCH 05/18] fix table --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fbdf738104..b55c4c4518 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', +lib('protobuf.BufSetp') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', From 2ec3dcef2c4c24b52e9e315317cd522b2273c8d4 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:03:16 -0400 Subject: [PATCH 06/18] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b55c4c4518..e6455348a0 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ lib('markdown.FlexmarkStep') +'{{no}} | {{yes}} lib('npm.PrettierFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('npm.TsFmtFormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('pom.SortPomStepStep') +'{{no}} | {{yes}} | {{no}} | {{no}} |', -lib('protobuf.BufSetp') +'{{yes}} | {{no}} | {{no}} | {{no}} |', +lib('protobuf.BufStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('python.BlackStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', lib('scala.ScalaFmtStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('sql.DBeaverSQLFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', From 8d25fd8a65b5c80232b58f94373b29efa6f97cb7 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:21:19 -0400 Subject: [PATCH 07/18] add tag to disable buf tests in CI --- gradle/special-tests.gradle | 3 +- .../gradle/spotless/BufIntegrationTest.java | 3 ++ .../com/diffplug/spotless/tag/BufTest.java | 30 +++++++++++++++++++ .../spotless/protobuf/BufStepTest.java | 3 ++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java diff --git a/gradle/special-tests.gradle b/gradle/special-tests.gradle index c435bc7e81..c3fa9cec0b 100644 --- a/gradle/special-tests.gradle +++ b/gradle/special-tests.gradle @@ -3,7 +3,8 @@ apply plugin: 'com.adarshr.test-logger' def special = [ 'Npm', 'Black', - 'Clang' + 'Clang', + 'Buf' ] boolean isCiServer = System.getenv().containsKey("CI") diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java index 03f45a46c8..5625f927ce 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -17,8 +17,11 @@ import java.io.IOException; +import com.diffplug.spotless.tag.BufTest; + import org.junit.jupiter.api.Test; +@BufTest class BufIntegrationTest extends GradleIntegrationHarness { @Test void buf() throws IOException { diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java new file mode 100644 index 0000000000..cf358c3816 --- /dev/null +++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 DiffPlug + * + * 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. + */ +package com.diffplug.spotless.tag; + +import org.junit.jupiter.api.Tag; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +@Tag("Buf") +public @interface BufTest {} diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java index c2079f462f..f54cd2cae3 100644 --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -17,10 +17,13 @@ import java.io.File; +import com.diffplug.spotless.tag.BufTest; + import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarnessWithFile; +@BufTest class BufStepTest { @Test void test() throws Exception { From 78712ba6c3e67acc310287da30bd3f284f7edff5 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Thu, 12 May 2022 23:36:27 -0400 Subject: [PATCH 08/18] lint --- .../com/diffplug/gradle/spotless/BufIntegrationTest.java | 4 ++-- .../src/main/java/com/diffplug/spotless/tag/BufTest.java | 8 ++++---- .../java/com/diffplug/spotless/protobuf/BufStepTest.java | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java index 5625f927ce..ba08c51838 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java @@ -17,10 +17,10 @@ import java.io.IOException; -import com.diffplug.spotless.tag.BufTest; - import org.junit.jupiter.api.Test; +import com.diffplug.spotless.tag.BufTest; + @BufTest class BufIntegrationTest extends GradleIntegrationHarness { @Test diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java index cf358c3816..490218ef7b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java +++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java @@ -15,14 +15,14 @@ */ package com.diffplug.spotless.tag; -import org.junit.jupiter.api.Tag; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import org.junit.jupiter.api.Tag; @Target({TYPE, METHOD}) @Retention(RUNTIME) diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java index f54cd2cae3..0cd72129c6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java @@ -17,11 +17,10 @@ import java.io.File; -import com.diffplug.spotless.tag.BufTest; - import org.junit.jupiter.api.Test; import com.diffplug.spotless.StepHarnessWithFile; +import com.diffplug.spotless.tag.BufTest; @BufTest class BufStepTest { From 5c44a8e906dbf3d404d7d38758d4980f66cb1996 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:50:09 -0400 Subject: [PATCH 09/18] add doc to pathToExe noting executable path trick --- .../gradle/spotless/ProtobufExtension.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 59a63b97fd..ac9f37ec8c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -69,6 +69,30 @@ public class BufFormatExtension { addStep(createStep()); } + /** + * When used in conjunction with the {@code buf-gradle-plugin}, + * the {@code buf} executable can be resolved from its {@code bufTool} configuration: + * + *
+		 * {@code
+		 * spotless {
+         *     protobuf {
+         *         buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).singleFile.absolutePath)
+         *     }
+		 * }
+		 * }
+		 * 
+ * + * Be sure to disable the {@code buf-gradle-plugin}'s native support of {@code buf format}: + * + *
+		 * {@code
+		 * buf {
+         *     enforceFormat = false
+		 * }
+		 * }
+		 * 
+ */ public BufFormatExtension pathToExe(String pathToExe) { step = step.withPathToExe(pathToExe); replaceStep(createStep()); From 580037dc7b6bf58aa7b7072327b0c12649c29968 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:55:45 -0400 Subject: [PATCH 10/18] add to readme as well --- plugin-gradle/README.md | 15 +++++++++++++++ .../gradle/spotless/ProtobufExtension.java | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7bf684923c..273afb54d1 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -475,6 +475,21 @@ spotless { } ``` +When used in conjunction with the [buf-gradle-plugin](https://github.com/andrewparmet/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: + +```gradle +spotless { + protobuf { + buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath()) + } +} + +// Be sure to disable the buf-gradle-plugin's native support of `buf format`: +buf { + enforceFormat = false +} +``` + ## FreshMark `com.diffplug.gradle.spotless.FreshMarkExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/FreshMarkExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FreshMarkExtension.java) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index ac9f37ec8c..8754880f69 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -76,9 +76,9 @@ public class BufFormatExtension { *
 		 * {@code
 		 * spotless {
-         *     protobuf {
-         *         buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).singleFile.absolutePath)
-         *     }
+         *   protobuf {
+         *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
+         *   }
 		 * }
 		 * }
 		 * 
@@ -88,7 +88,7 @@ public class BufFormatExtension { *
 		 * {@code
 		 * buf {
-         *     enforceFormat = false
+         *   enforceFormat = false
 		 * }
 		 * }
 		 * 
From 3f7b1e87995210c852f87035e2eb396d993d66fd Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 13 May 2022 00:58:23 -0400 Subject: [PATCH 11/18] tidy up diction --- plugin-gradle/README.md | 2 +- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 273afb54d1..ec97352749 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -484,7 +484,7 @@ spotless { } } -// Be sure to disable the buf-gradle-plugin's native support of `buf format`: +// Be sure to disable the buf-gradle-plugin's execution of `buf format`: buf { enforceFormat = false } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 8754880f69..5f24b97a02 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -83,7 +83,7 @@ public class BufFormatExtension { * } * * - * Be sure to disable the {@code buf-gradle-plugin}'s native support of {@code buf format}: + * Be sure to disable the {@code buf-gradle-plugin}'s execution of {@code buf format}: * *
 		 * {@code

From 24a913c20c4eff623c08dd2d9e97d5866c735f2b Mon Sep 17 00:00:00 2001
From: Andrew Parmet 
Date: Fri, 13 May 2022 00:59:21 -0400
Subject: [PATCH 12/18] tabs

---
 .../com/diffplug/gradle/spotless/ProtobufExtension.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
index 5f24b97a02..283fe21c58 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
@@ -76,9 +76,9 @@ public class BufFormatExtension {
 		 * 
 		 * {@code
 		 * spotless {
-         *   protobuf {
-         *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
-         *   }
+		 *   protobuf {
+		 *     buf().pathToExe(configurations.getByName(BUF_BINARY_CONFIGURATION_NAME).getSingleFile().getAbsolutePath())
+		 *   }
 		 * }
 		 * }
 		 * 
@@ -88,7 +88,7 @@ public class BufFormatExtension { *
 		 * {@code
 		 * buf {
-         *   enforceFormat = false
+		 *   enforceFormat = false
 		 * }
 		 * }
 		 * 
From 0e3be7dc7eec2f967adc709f1834955296df6be8 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 14 Jul 2023 20:37:10 -0400 Subject: [PATCH 13/18] update link --- plugin-gradle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index ec97352749..afbb91ef4f 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -475,7 +475,7 @@ spotless { } ``` -When used in conjunction with the [buf-gradle-plugin](https://github.com/andrewparmet/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: +When used in conjunction with the [buf-gradle-plugin](https://github.com/bufbuild/buf-gradle-plugin), the `buf` executable can be resolved from its `bufTool` configuration: ```gradle spotless { From 3c1bb4c186021ba9a35dc893622cf93a9f76ab65 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Fri, 14 Jul 2023 20:37:31 -0400 Subject: [PATCH 14/18] update link --- .../java/com/diffplug/gradle/spotless/ProtobufExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java index 283fe21c58..f0d5a0245c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java @@ -70,7 +70,7 @@ public class BufFormatExtension { } /** - * When used in conjunction with the {@code buf-gradle-plugin}, + * When used in conjunction with the {@code buf-gradle-plugin}, * the {@code buf} executable can be resolved from its {@code bufTool} configuration: * *

From 3d2d2b86adee71213521d8953b7e4b0e05ed6fce Mon Sep 17 00:00:00 2001
From: Andrew Parmet 
Date: Sat, 15 Jul 2023 12:34:53 -0400
Subject: [PATCH 15/18] update default version

---
 lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
index 601a47f193..28058ffd4f 100644
--- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
+++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
@@ -38,7 +38,7 @@ public static String name() {
 	}
 
 	public static String defaultVersion() {
-		return "1.4.0";
+		return "1.24.0";
 	}
 
 	private final String version;

From 6e7556f527e8c4bedaa82367c6f24164d91722d5 Mon Sep 17 00:00:00 2001
From: Ned Twigg 
Date: Sat, 15 Jul 2023 19:32:31 -0700
Subject: [PATCH 16/18] spotlessApply

---
 lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java   | 2 +-
 .../java/com/diffplug/spotless/protobuf/ProtobufConstants.java  | 2 +-
 plugin-gradle/README.md                                         | 2 +-
 .../java/com/diffplug/gradle/spotless/ProtobufExtension.java    | 2 +-
 .../java/com/diffplug/gradle/spotless/SpotlessExtension.java    | 2 +-
 .../java/com/diffplug/gradle/spotless/BufIntegrationTest.java   | 2 +-
 testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java    | 2 +-
 .../test/java/com/diffplug/spotless/protobuf/BufStepTest.java   | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
index 28058ffd4f..c9b9efa543 100644
--- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
+++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
index b24df7cc38..cd91e2671c 100644
--- a/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
+++ b/lib/src/main/java/com/diffplug/spotless/protobuf/ProtobufConstants.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
index 716de842aa..efec76a048 100644
--- a/plugin-gradle/README.md
+++ b/plugin-gradle/README.md
@@ -522,7 +522,7 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
 
 ### buf
 
-`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.6.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
+`com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
 
 ```gradle
 spotless {
diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
index f0d5a0245c..77e4fbc7c7 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
index 2e6bf0e9b7..c3cf5123c0 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java
@@ -197,7 +197,7 @@ public void json(Action closure) {
 	public void protobuf(Action closure) {
 		requireNonNull(closure);
 		format(ProtobufExtension.NAME, ProtobufExtension.class, closure);
-  }
+	}
 
 	/** Configures the special YAML-specific extension. */
 	public void yaml(Action closure) {
diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
index ba08c51838..b91512c7ed 100644
--- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
+++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/BufIntegrationTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
index 490218ef7b..90f32ec6c3 100644
--- a/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
+++ b/testlib/src/main/java/com/diffplug/spotless/tag/BufTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
index 0cd72129c6..9b5fa2fcf5 100644
--- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
+++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 DiffPlug
+ * Copyright 2022-2023 DiffPlug
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.

From 0943a81bec7b3327b9b3e706d928af00cf49b4ed Mon Sep 17 00:00:00 2001
From: Ned Twigg 
Date: Sat, 15 Jul 2023 19:47:21 -0700
Subject: [PATCH 17/18] Fix BufStepTest for the changes we've had in test
 infrastructure.

---
 .../java/com/diffplug/spotless/protobuf/BufStepTest.java | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
index 9b5fa2fcf5..ce22eb5ed2 100644
--- a/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
+++ b/testlib/src/test/java/com/diffplug/spotless/protobuf/BufStepTest.java
@@ -15,19 +15,18 @@
  */
 package com.diffplug.spotless.protobuf;
 
-import java.io.File;
-
 import org.junit.jupiter.api.Test;
 
+import com.diffplug.spotless.ResourceHarness;
 import com.diffplug.spotless.StepHarnessWithFile;
 import com.diffplug.spotless.tag.BufTest;
 
 @BufTest
-class BufStepTest {
+class BufStepTest extends ResourceHarness {
 	@Test
 	void test() throws Exception {
-		try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(BufStep.withVersion(BufStep.defaultVersion()).create())) {
-			harness.testResource(new File("src/main/resources/protobuf/buf/buf.proto"), "protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean");
+		try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, BufStep.withVersion(BufStep.defaultVersion()).create())) {
+			harness.testResource("protobuf/buf/buf.proto", "protobuf/buf/buf.proto.clean");
 		}
 	}
 }

From 0fc9036455f1b5090e484c3f7b34e69bdb86c80d Mon Sep 17 00:00:00 2001
From: Ned Twigg 
Date: Sat, 15 Jul 2023 23:26:40 -0700
Subject: [PATCH 18/18] Add warnings that buf must be the first step.

---
 plugin-gradle/README.md                                        | 2 ++
 .../java/com/diffplug/gradle/spotless/ProtobufExtension.java   | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md
index efec76a048..55b6e98a30 100644
--- a/plugin-gradle/README.md
+++ b/plugin-gradle/README.md
@@ -524,6 +524,8 @@ black().pathToExe('C:/myuser/.pyenv/versions/3.8.0/scripts/black.exe')
 
 `com.diffplug.gradle.spotless.ProtobufExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.19.0/com/diffplug/gradle/spotless/ProtobufExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java)
 
+**WARNING** this step **must** be the first step in the chain, steps before it will be ignored. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.
+
 ```gradle
 spotless {
   protobuf {
diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
index 77e4fbc7c7..7b0a6bb30a 100644
--- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
+++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/ProtobufExtension.java
@@ -66,6 +66,9 @@ public class BufFormatExtension {
 
 		BufFormatExtension(String version) {
 			this.step = BufStep.withVersion(version);
+			if (!steps.isEmpty()) {
+				throw new IllegalArgumentException("buf() must be the first step, move other steps after it. Thumbs up [this issue](https://github.com/bufbuild/buf/issues/1035) for a resolution, see [here](https://github.com/diffplug/spotless/pull/1208#discussion_r1264439669) for more details on the problem.");
+			}
 			addStep(createStep());
 		}