From 2322641be19e928c1dae0e2536f43f154d5c73a6 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Thu, 2 Sep 2021 13:31:46 +0100 Subject: [PATCH 01/15] Add a Gherkin formatter As part of #907, we want to be able to format our Gherkin source files automagically. To do this, we can utilise the upstream gherkin-formatter project to do the heavy lifting, and add a few test cases within this project to make sure that functionality looks correct. We're calling this a `simple` formatter as it doesn't allow much to be configured other than the indentation size in spaces. --- .../spotless/gherkin/GherkinSimpleStep.java | 77 +++++++++++ .../gherkin/complex_backgroundAfter.feature | 24 ++++ .../gherkin/complex_backgroundBefore.feature | 24 ++++ .../gherkin/descriptionsAfter.feature | 47 +++++++ .../gherkin/descriptionsBefore.feature | 51 ++++++++ .../main/resources/gherkin/emptyAfter.feature | 0 .../resources/gherkin/emptyBefore.feature | 1 + .../gherkin/invalidGherkinAfter.feature | 0 .../gherkin/invalidGherkinBefore.feature | 9 ++ .../resources/gherkin/minimalAfter.feature | 4 + .../gherkin/minimalAfter0Spaces.feature | 4 + .../gherkin/minimalAfter6Spaces.feature | 4 + .../resources/gherkin/minimalBefore.feature | 3 + .../resources/gherkin/notGherkinAfter.feature | 0 .../gherkin/notGherkinBefore.feature | 1 + .../gherkin/rule_with_tagAfter.feature | 19 +++ .../gherkin/rule_with_tagBefore.feature | 19 +++ .../gherkin/GherkinSimpleStepTest.java | 120 ++++++++++++++++++ 18 files changed, 407 insertions(+) create mode 100644 lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java create mode 100644 testlib/src/main/resources/gherkin/complex_backgroundAfter.feature create mode 100644 testlib/src/main/resources/gherkin/complex_backgroundBefore.feature create mode 100644 testlib/src/main/resources/gherkin/descriptionsAfter.feature create mode 100644 testlib/src/main/resources/gherkin/descriptionsBefore.feature create mode 100644 testlib/src/main/resources/gherkin/emptyAfter.feature create mode 100644 testlib/src/main/resources/gherkin/emptyBefore.feature create mode 100644 testlib/src/main/resources/gherkin/invalidGherkinAfter.feature create mode 100644 testlib/src/main/resources/gherkin/invalidGherkinBefore.feature create mode 100644 testlib/src/main/resources/gherkin/minimalAfter.feature create mode 100644 testlib/src/main/resources/gherkin/minimalAfter0Spaces.feature create mode 100644 testlib/src/main/resources/gherkin/minimalAfter6Spaces.feature create mode 100644 testlib/src/main/resources/gherkin/minimalBefore.feature create mode 100644 testlib/src/main/resources/gherkin/notGherkinAfter.feature create mode 100644 testlib/src/main/resources/gherkin/notGherkinBefore.feature create mode 100644 testlib/src/main/resources/gherkin/rule_with_tagAfter.feature create mode 100644 testlib/src/main/resources/gherkin/rule_with_tagBefore.feature create mode 100644 testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java new file mode 100644 index 000000000..1f41835c0 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java @@ -0,0 +1,77 @@ +/* + * Copyright 2021 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.gherkin; + +import java.io.IOException; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Objects; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.JarState; +import com.diffplug.spotless.Provisioner; + +public class GherkinSimpleStep { + private static final String MAVEN_COORDINATE = "me.jvt.cucumber:gherkin-formatter:"; + private static final String DEFAULT_VERSION = "1.1.0"; + + public static FormatterStep create(int indent, Provisioner provisioner) { + Objects.requireNonNull(provisioner, "provisioner cannot be null"); + return FormatterStep.createLazy("gherkin", () -> new GherkinSimpleStep.State(indent, provisioner), GherkinSimpleStep.State::toFormatter); + } + + private static final class State implements Serializable { + private static final long serialVersionUID = 1L; + + private final int indentSpaces; + private final JarState jarState; + + private State(int indent, Provisioner provisioner) throws IOException { + this.indentSpaces = indent; + this.jarState = JarState.from(MAVEN_COORDINATE + DEFAULT_VERSION, provisioner); + } + + FormatterFunc toFormatter() { + Method format; + Object formatter; + try { + ClassLoader classLoader = jarState.getClassLoader(); + Class prettyFormatter = classLoader.loadClass("me.jvt.cucumber.gherkinformatter.PrettyFormatter"); + Class[] constructorArguments = new Class[]{int.class}; + Constructor constructor = prettyFormatter.getConstructor(constructorArguments); + format = prettyFormatter.getMethod("format", String.class); + formatter = constructor.newInstance(indentSpaces); + } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException(String.format("There was a problem preparing %s dependencies", MAVEN_COORDINATE), e); + } + + return s -> { + try { + return (String) format.invoke(formatter, s); + } catch (InvocationTargetException ex) { + throw new AssertionError("Unable to format Gherkin", ex.getCause()); + } + }; + } + } + + private GherkinSimpleStep() { + // cannot be directly instantiated + } +} diff --git a/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature new file mode 100644 index 000000000..eb4d4de89 --- /dev/null +++ b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature @@ -0,0 +1,24 @@ +Feature: Complex background + We want to ensure PickleStep all have different IDs + + Background: a simple background + Given the minimalism inside a background + + Scenario: minimalistic + Given the minimalism + + Scenario: also minimalistic + Given the minimalism + + Rule: My Rule + + Background: + Given a rule background step + + Scenario: with examples + Given the minimalism + + Examples: + | value | + | 1 | + | 2 | diff --git a/testlib/src/main/resources/gherkin/complex_backgroundBefore.feature b/testlib/src/main/resources/gherkin/complex_backgroundBefore.feature new file mode 100644 index 000000000..fde7c94d9 --- /dev/null +++ b/testlib/src/main/resources/gherkin/complex_backgroundBefore.feature @@ -0,0 +1,24 @@ +Feature: Complex background + We want to ensure PickleStep all have different IDs + + Background: a simple background + Given the minimalism inside a background + + Scenario: minimalistic + Given the minimalism + + Scenario: also minimalistic + Given the minimalism + + Rule: My Rule + + Background: + Given a rule background step + + Scenario: with examples + Given the minimalism + + Examples: + | value | + | 1 | + | 2 | diff --git a/testlib/src/main/resources/gherkin/descriptionsAfter.feature b/testlib/src/main/resources/gherkin/descriptionsAfter.feature new file mode 100644 index 000000000..e7998a203 --- /dev/null +++ b/testlib/src/main/resources/gherkin/descriptionsAfter.feature @@ -0,0 +1,47 @@ +Feature: Descriptions everywhere + This is a single line description + + Scenario: two lines + This description + has two lines and indented with two spaces + Given the minimalism + + Scenario: without indentation + This is a description without indentation + Given the minimalism + + Scenario: empty lines in the middle + This description + + has an empty line in the middle + Given the minimalism + + Scenario: empty lines around + This description + has an empty lines around + Given the minimalism + + Scenario: comment after description + This description + has a comment after + # this is a comment + Given the minimalism + + Scenario: comment right after description + This description + has a comment right after + # this is another comment + Given the minimalism + + Scenario: description with escaped docstring separator + This description has an \"\"\" (escaped docstring sparator) + Given the minimalism + + Scenario Outline: scenario outline with a description + This is a scenario outline description + Given the minimalism + + Examples: examples with description + This is an examples description + | foo | + | bar | diff --git a/testlib/src/main/resources/gherkin/descriptionsBefore.feature b/testlib/src/main/resources/gherkin/descriptionsBefore.feature new file mode 100644 index 000000000..690ae3a75 --- /dev/null +++ b/testlib/src/main/resources/gherkin/descriptionsBefore.feature @@ -0,0 +1,51 @@ +Feature: Descriptions everywhere + This is a single line description + + Scenario: two lines + This description + has two lines and indented with two spaces + Given the minimalism + +Scenario: without indentation +This is a description without indentation + Given the minimalism + + Scenario: empty lines in the middle + This description + + has an empty line in the middle + Given the minimalism + + Scenario: empty lines around + + This description + has an empty lines around + + Given the minimalism + + Scenario: comment after description + This description + has a comment after + +# this is a comment + Given the minimalism + + Scenario: comment right after description + This description + has a comment right after + # this is another comment + Given the minimalism + + Scenario: description with escaped docstring separator + This description has an \"\"\" (escaped docstring sparator) + + Given the minimalism + + Scenario Outline: scenario outline with a description +This is a scenario outline description + Given the minimalism + + Examples: examples with description +This is an examples description + | foo | + | bar | diff --git a/testlib/src/main/resources/gherkin/emptyAfter.feature b/testlib/src/main/resources/gherkin/emptyAfter.feature new file mode 100644 index 000000000..e69de29bb diff --git a/testlib/src/main/resources/gherkin/emptyBefore.feature b/testlib/src/main/resources/gherkin/emptyBefore.feature new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/testlib/src/main/resources/gherkin/emptyBefore.feature @@ -0,0 +1 @@ + diff --git a/testlib/src/main/resources/gherkin/invalidGherkinAfter.feature b/testlib/src/main/resources/gherkin/invalidGherkinAfter.feature new file mode 100644 index 000000000..e69de29bb diff --git a/testlib/src/main/resources/gherkin/invalidGherkinBefore.feature b/testlib/src/main/resources/gherkin/invalidGherkinBefore.feature new file mode 100644 index 000000000..665bf227c --- /dev/null +++ b/testlib/src/main/resources/gherkin/invalidGherkinBefore.feature @@ -0,0 +1,9 @@ + +invalid line here + +Feature: Multiple parser errors + + Scenario: minimalistic + Given the minimalism + + another invalid line here diff --git a/testlib/src/main/resources/gherkin/minimalAfter.feature b/testlib/src/main/resources/gherkin/minimalAfter.feature new file mode 100644 index 000000000..44467df36 --- /dev/null +++ b/testlib/src/main/resources/gherkin/minimalAfter.feature @@ -0,0 +1,4 @@ +Feature: Minimal + + Scenario: minimalistic + Given the minimalism diff --git a/testlib/src/main/resources/gherkin/minimalAfter0Spaces.feature b/testlib/src/main/resources/gherkin/minimalAfter0Spaces.feature new file mode 100644 index 000000000..aa94821bb --- /dev/null +++ b/testlib/src/main/resources/gherkin/minimalAfter0Spaces.feature @@ -0,0 +1,4 @@ +Feature: Minimal + +Scenario: minimalistic +Given the minimalism diff --git a/testlib/src/main/resources/gherkin/minimalAfter6Spaces.feature b/testlib/src/main/resources/gherkin/minimalAfter6Spaces.feature new file mode 100644 index 000000000..cbad451b4 --- /dev/null +++ b/testlib/src/main/resources/gherkin/minimalAfter6Spaces.feature @@ -0,0 +1,4 @@ +Feature: Minimal + + Scenario: minimalistic + Given the minimalism diff --git a/testlib/src/main/resources/gherkin/minimalBefore.feature b/testlib/src/main/resources/gherkin/minimalBefore.feature new file mode 100644 index 000000000..a474cf141 --- /dev/null +++ b/testlib/src/main/resources/gherkin/minimalBefore.feature @@ -0,0 +1,3 @@ +Feature: Minimal +Scenario: minimalistic +Given the minimalism diff --git a/testlib/src/main/resources/gherkin/notGherkinAfter.feature b/testlib/src/main/resources/gherkin/notGherkinAfter.feature new file mode 100644 index 000000000..e69de29bb diff --git a/testlib/src/main/resources/gherkin/notGherkinBefore.feature b/testlib/src/main/resources/gherkin/notGherkinBefore.feature new file mode 100644 index 000000000..517db4bd1 --- /dev/null +++ b/testlib/src/main/resources/gherkin/notGherkinBefore.feature @@ -0,0 +1 @@ +not gherkin diff --git a/testlib/src/main/resources/gherkin/rule_with_tagAfter.feature b/testlib/src/main/resources/gherkin/rule_with_tagAfter.feature new file mode 100644 index 000000000..bba6b044a --- /dev/null +++ b/testlib/src/main/resources/gherkin/rule_with_tagAfter.feature @@ -0,0 +1,19 @@ +@tag_feature +Feature: Some tagged rules + + Rule: Untagged rule + The untagged rule description + + Scenario: Scenario with only a feature tag + Given a + + @tag_rule + Rule: Tagged rule + The tagged rule description + + Scenario: Scenario with feature and rule tags + Given b + + @tag_scenario + Scenario: Scenario with feature, rule and scenario tags + Given b diff --git a/testlib/src/main/resources/gherkin/rule_with_tagBefore.feature b/testlib/src/main/resources/gherkin/rule_with_tagBefore.feature new file mode 100644 index 000000000..bba6b044a --- /dev/null +++ b/testlib/src/main/resources/gherkin/rule_with_tagBefore.feature @@ -0,0 +1,19 @@ +@tag_feature +Feature: Some tagged rules + + Rule: Untagged rule + The untagged rule description + + Scenario: Scenario with only a feature tag + Given a + + @tag_rule + Rule: Tagged rule + The tagged rule description + + Scenario: Scenario with feature and rule tags + Given b + + @tag_scenario + Scenario: Scenario with feature, rule and scenario tags + Given b diff --git a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java new file mode 100644 index 000000000..1210bf21d --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2021 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.gherkin; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.SerializableEqualityTester; +import com.diffplug.spotless.StepHarness; +import com.diffplug.spotless.TestProvisioner; + +public class GherkinSimpleStepTest { + + private static final int INDENT = 2; + + private final FormatterStep step = GherkinSimpleStep.create(INDENT, TestProvisioner.mavenCentral()); + private final StepHarness stepHarness = StepHarness.forStep(step); + + @Test + public void cannotProvidedNullProvisioner() { + assertThatThrownBy(() -> GherkinSimpleStep.create(INDENT, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); + } + + @Test + public void handlesEmptyFeature() throws Exception { + doWithResource(stepHarness, "empty"); + } + + @Test + public void handlesComplexBackground() throws Exception { + doWithResource(stepHarness, "complex_background"); + } + + @Test + public void handlesDescriptions() throws Exception { + doWithResource(stepHarness, "descriptions"); + } + + @Test + public void handlesRuleWithTag() throws Exception { + doWithResource(stepHarness, "rule_with_tag"); + } + + @Test + public void handlesInvalidGherkin() { + assertThatThrownBy(() -> doWithResource(stepHarness, "invalidGherkin")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format Gherkin"); + } + + @Test + public void handlesNotGherkin() { + assertThatThrownBy(() -> doWithResource(stepHarness, "notGherkin")) + .isInstanceOf(AssertionError.class) + .hasMessage("Unable to format Gherkin"); + } + + @Test + public void canSetCustomIndentationLevel() throws Exception { + FormatterStep step = GherkinSimpleStep.create(6, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "gherkin/minimalBefore.feature"; + String after = "gherkin/minimalAfter6Spaces.feature"; + stepHarness.testResource(before, after); + } + + @Test + public void canSetIndentationLevelTo0() throws Exception { + FormatterStep step = GherkinSimpleStep.create(0, TestProvisioner.mavenCentral()); + StepHarness stepHarness = StepHarness.forStep(step); + + String before = "gherkin/minimalBefore.feature"; + String after = "gherkin/minimalAfter0Spaces.feature"; + stepHarness.testResource(before, after); + } + + @Test + public void equality() { + new SerializableEqualityTester() { + int spaces = 0; + + @Override + protected void setupTest(API api) { + // no changes, are the same + api.areDifferentThan(); + + // with different spacing + spaces = 1; + api.areDifferentThan(); + } + + @Override + protected FormatterStep create() { + return GherkinSimpleStep.create(spaces, TestProvisioner.mavenCentral()); + } + }.testEquals(); + } + + private static void doWithResource(StepHarness stepHarness, String name) throws Exception { + String before = String.format("gherkin/%sBefore.feature", name); + String after = String.format("gherkin/%sAfter.feature", name); + stepHarness.testResource(before, after); + } +} From 184aa5ed29e7d4cde02e00e63dd17468baa401de Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Thu, 2 Sep 2021 17:16:37 +0100 Subject: [PATCH 02/15] Add Gradle bindings for Gherkin formatter As we've created a Gherkin formatter as part of #907, we should make it possible to use it natively in Gradle, which requires we add it as a new supported type in `SpotlessExtension`. --- plugin-gradle/README.md | 29 +++++++++ .../gradle/spotless/GherkinExtension.java | 62 +++++++++++++++++++ .../gradle/spotless/SpotlessExtension.java | 6 ++ .../gradle/spotless/GherkinExtensionTest.java | 62 +++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java create mode 100644 plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 28f8f85b5..92d8b1553 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -69,6 +69,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [SQL](#sql) ([dbeaver](#dbeaver), [prettier](#prettier)) - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier)) - [JSON](#json) + - [Gherkin](#gherkin) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection)) - javascript, jsx, angular, vue, flow, typescript, css, less, scss, html, json, graphql, markdown, ymaml @@ -558,6 +559,34 @@ spotless { } ``` +## Gherkin + +- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/5.15.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) + +```gradle +spotless { + gherkin { + target 'src/**/*.feature' // you have to set the target manually + simple() // has its own section below + } +} +``` + +### simple + +Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: + +```gradle +spotless { + gherkin { + target 'src/**/*.feature' + simple() + // optional: specify the number of spaces to use + simple().indentWithSpaces(6) + } +} +``` + ## Prettier diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java new file mode 100644 index 000000000..59ff16805 --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java @@ -0,0 +1,62 @@ +/* + * Copyright 2016-2021 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 javax.inject.Inject; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.gherkin.GherkinSimpleStep; + +public class GherkinExtension extends FormatExtension { + private static final int DEFAULT_INDENTATION = 4; + static final String NAME = "gherkin"; + + @Inject + public GherkinExtension(SpotlessExtension spotless) { + super(spotless); + } + + @Override + protected void setupTask(SpotlessTask task) { + if (target == null) { + throw noDefaultTargetException(); + } + super.setupTask(task); + } + + public SimpleConfig simple() { + return new SimpleConfig(DEFAULT_INDENTATION); + } + + public class SimpleConfig { + private int indent; + + public SimpleConfig(int indent) { + this.indent = indent; + addStep(createStep()); + } + + public void indentWithSpaces(int indent) { + this.indent = indent; + replaceStep(createStep()); + } + + private FormatterStep createStep() { + return GherkinSimpleStep.create(indent, provisioner()); + } + } + +} 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 7959bdc71..ba42d7595 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 @@ -175,6 +175,12 @@ public void json(Action closure) { format(JsonExtension.NAME, JsonExtension.class, closure); } + /** Configures the special Gherkin-specific extension. */ + public void gherkin(Action closure) { + requireNonNull(closure); + format(GherkinExtension.NAME, GherkinExtension.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/GherkinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java new file mode 100644 index 000000000..4b1fdc7ef --- /dev/null +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2021 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.Test; + +public class GherkinExtensionTest extends GradleIntegrationHarness { + @Test + public void defaultFormatting() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " gherkin {", + " target 'examples/**/*.feature'", + " simple()", + "}", + "}"); + setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); + setFile("examples/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.feature").sameAsResource("gherkin/minimalBefore.feature"); + assertFile("examples/main/resources/example.feature").sameAsResource("gherkin/minimalAfter.feature"); + } + + @Test + public void formattingWithCustomNumberOfSpaces() throws IOException { + setFile("build.gradle").toLines( + "buildscript { repositories { mavenCentral() } }", + "plugins {", + " id 'java'", + " id 'com.diffplug.spotless'", + "}", + "spotless {", + " gherkin {", + " target 'src/**/*.feature'", + " simple().indentWithSpaces(6)", + "}", + "}"); + setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); + gradleRunner().withArguments("spotlessApply").build(); + assertFile("src/main/resources/example.feature").sameAsResource("gherkin/minimalAfter6Spaces.feature"); + } +} From 6f0a35c1f603744e3063711fab8d643141a11ae8 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Mon, 6 Sep 2021 22:12:58 +0100 Subject: [PATCH 03/15] Add Gherkin formatter changes to CHANGES --- CHANGES.md | 4 ++++ plugin-gradle/CHANGES.md | 3 +++ 2 files changed, 7 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ea30ad2ea..ae96f58b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added +* Added formatter for [Gherkin feature files](https://github.com/diffplug/spotless/issues/928) +* Added Gradle configuration for Gherkin feature files + ## [2.16.0] - 2021-09-04 ### Added * Added support for `google-java-format`'s `skip-reflowing-long-strings` option ([#929](https://github.com/diffplug/spotless/pull/929)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 162d8fbe6..677e9d9d3 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,6 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] +### Added +* Added Gradle configuration for Gherkin feature files + ## [5.15.0] - 2021-09-04 ### Added * Added support for `google-java-format`'s `skip-reflowing-long-strings` option ([#929](https://github.com/diffplug/spotless/pull/929)) From 39e40957bc26e5ac05b60e8678770590c9af61ee Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 1 Apr 2023 22:23:01 +0400 Subject: [PATCH 04/15] Rework based on Gherkin-utils --- .editorconfig | 10 ++++ lib/build.gradle | 6 +- .../glue/gherkin/GherkinFormatterFunc.java | 60 +++++++++++++++++++ .../spotless/gherkin/GherkinSimpleConfig.java | 36 +++++++++++ .../spotless/gherkin/GherkinSimpleStep.java | 50 ++++++---------- plugin-gradle/CHANGES.md | 4 +- plugin-gradle/README.md | 10 ++-- .../gradle/spotless/GherkinExtension.java | 15 +++-- .../gradle/spotless/GherkinExtensionTest.java | 4 +- plugin-maven/CHANGES.md | 1 + plugin-maven/README.md | 27 ++++++++- .../spotless/maven/AbstractSpotlessMojo.java | 6 +- .../spotless/maven/gherkin/Gherkin.java | 43 +++++++++++++ .../spotless/maven/gherkin/SimpleGherkin.java | 42 +++++++++++++ .../gherkin/descriptionsAfter.feature | 16 +++-- .../resources/gherkin/minimalAfter.feature | 4 +- .../gherkin/GherkinSimpleStepTest.java | 30 ++++++---- 17 files changed, 296 insertions(+), 68 deletions(-) create mode 100644 lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java create mode 100644 lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java create mode 100644 plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java diff --git a/.editorconfig b/.editorconfig index 1c19210c4..4042d549f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -25,3 +25,13 @@ indent_style = space [*.{yml,yaml}] indent_style = space indent_size = 2 + +# Prevent unexpected automatic indentation when crafting test-cases +[/testlib/src/main/resources/**] +charset = unset +end_of_line = unset +insert_final_newline = unset +trim_trailing_whitespace = unset +indent_style = unset +indent_size = unset +ij_formatter_enabled = false diff --git a/lib/build.gradle b/lib/build.gradle index 548032088..4d95cfe84 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -18,7 +18,8 @@ def NEEDS_GLUE = [ 'scalafmt', 'jackson', 'gson', - 'cleanthat' + 'cleanthat', + 'gherkin' ] for (glue in NEEDS_GLUE) { sourceSets.register(glue) { @@ -115,6 +116,9 @@ dependencies { cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.6' compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.6' + + gherkinCompileOnly 'io.cucumber:gherkin-utils:8.0.2' + gherkinCompileOnly 'org.slf4j:slf4j-api:2.0.0' } // we'll hold the core lib to a high standard diff --git a/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java new file mode 100644 index 000000000..f46f7da32 --- /dev/null +++ b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java @@ -0,0 +1,60 @@ +/* + * Copyright 2023 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.glue.gherkin; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.FormatterFunc; +import com.diffplug.spotless.gherkin.GherkinSimpleConfig; + +import io.cucumber.gherkin.GherkinParser; +import io.cucumber.gherkin.utils.pretty.Pretty; +import io.cucumber.gherkin.utils.pretty.Syntax; +import io.cucumber.messages.types.Envelope; +import io.cucumber.messages.types.GherkinDocument; +import io.cucumber.messages.types.Source; +import io.cucumber.messages.types.SourceMediaType; + +public class GherkinFormatterFunc implements FormatterFunc { + private static final Logger LOGGER = LoggerFactory.getLogger(GherkinFormatterFunc.class); + + private final GherkinSimpleConfig gherkinSimpleConfig; + + public GherkinFormatterFunc(GherkinSimpleConfig gherkinSimpleConfig) { + this.gherkinSimpleConfig = gherkinSimpleConfig; + } + + // Follows https://github.com/cucumber/gherkin-utils/blob/main/java/src/test/java/io/cucumber/gherkin/utils/pretty/PrettyTest.java + private GherkinDocument parse(String gherkin) { + GherkinParser parser = GherkinParser + .builder() + .includeSource(false) + .build(); + return parser.parse(Envelope.of(new Source("test.feature", gherkin, SourceMediaType.TEXT_X_CUCUMBER_GHERKIN_PLAIN))) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("No envelope")) + .getGherkinDocument() + .orElseThrow(() -> new IllegalArgumentException("No gherkin document")); + } + + @Override + public String apply(String inputString) { + GherkinDocument gherkinDocument = parse(inputString); + + return Pretty.prettyPrint(gherkinDocument, Syntax.gherkin); + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java new file mode 100644 index 000000000..ba0d63763 --- /dev/null +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 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.gherkin; + +import java.io.Serializable; + +public class GherkinSimpleConfig implements Serializable { + public static int defaultIndentSpaces() { + // https://cucumber.io/docs/gherkin/reference/ + // Recommended indentation is 2 spaces + return 2; + } + + final int indentSpaces; + + public GherkinSimpleConfig(int indentSpaces) { + this.indentSpaces = indentSpaces; + } + + public int getIndentSpaces() { + return indentSpaces; + } +} diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java index 1f41835c0..10954f2bb 100644 --- a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Objects; import com.diffplug.spotless.FormatterFunc; @@ -28,46 +27,35 @@ import com.diffplug.spotless.Provisioner; public class GherkinSimpleStep { - private static final String MAVEN_COORDINATE = "me.jvt.cucumber:gherkin-formatter:"; - private static final String DEFAULT_VERSION = "1.1.0"; + private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:"; + private static final String DEFAULT_VERSION = "8.0.2"; - public static FormatterStep create(int indent, Provisioner provisioner) { + public static String defaultVersion() { + return DEFAULT_VERSION; + } + + public static FormatterStep create(GherkinSimpleConfig gherkinSimpleConfig, + String formatterVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("gherkin", () -> new GherkinSimpleStep.State(indent, provisioner), GherkinSimpleStep.State::toFormatter); + return FormatterStep.createLazy("gherkin", () -> new GherkinSimpleStep.State(gherkinSimpleConfig, formatterVersion, provisioner), GherkinSimpleStep.State::toFormatter); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final int indentSpaces; + private final GherkinSimpleConfig gherkinSimpleConfig; private final JarState jarState; - private State(int indent, Provisioner provisioner) throws IOException { - this.indentSpaces = indent; - this.jarState = JarState.from(MAVEN_COORDINATE + DEFAULT_VERSION, provisioner); + private State(GherkinSimpleConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) throws IOException { + this.gherkinSimpleConfig = gherkinSimpleConfig; + this.jarState = JarState.from(MAVEN_COORDINATE + formatterVersion, provisioner); } - FormatterFunc toFormatter() { - Method format; - Object formatter; - try { - ClassLoader classLoader = jarState.getClassLoader(); - Class prettyFormatter = classLoader.loadClass("me.jvt.cucumber.gherkinformatter.PrettyFormatter"); - Class[] constructorArguments = new Class[]{int.class}; - Constructor constructor = prettyFormatter.getConstructor(constructorArguments); - format = prettyFormatter.getMethod("format", String.class); - formatter = constructor.newInstance(indentSpaces); - } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new IllegalStateException(String.format("There was a problem preparing %s dependencies", MAVEN_COORDINATE), e); - } - - return s -> { - try { - return (String) format.invoke(formatter, s); - } catch (InvocationTargetException ex) { - throw new AssertionError("Unable to format Gherkin", ex.getCause()); - } - }; + FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, + InstantiationException, IllegalAccessException { + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GherkinSimpleConfig.class); + return (FormatterFunc) constructor.newInstance(gherkinSimpleConfig); } } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index de2ca7bdd..62df3eac8 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -14,6 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ``` Mirrors are selected by prefix match, for example `https://download.eclipse.org/eclipse/updates/4.26/` will be redirected to `https://some.internal.mirror/eclipse/eclipse/updates/4.26/`. The same configuration exists for `greclipse` and `eclipseCdt`. +* Added support for Gherkin feature files (#???(???)) ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) @@ -369,9 +370,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Spotless does not [yet](https://github.com/diffplug/spotless/pull/721) support configuration-cache, but now it can never interfere with configuration-cache for other tasks. ([#720](https://github.com/diffplug/spotless/pull/720)) * Bump minimum required Gradle from `5.4` to `6.1`. -### Added -* Added Gradle configuration for Gherkin feature files - ## [5.15.0] - 2021-09-04 ### Added * Added support for `google-java-format`'s `skip-reflowing-long-strings` option ([#929](https://github.com/diffplug/spotless/pull/929)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 6eb5bced6..fde7c55b8 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -66,6 +66,7 @@ Spotless supports all of Gradle's built-in performance features (incremental bui - [Typescript](#typescript) ([tsfmt](#tsfmt), [prettier](#prettier), [ESLint](#eslint-typescript)) - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) + - [YAML](#yaml) - [Gherkin](#gherkin) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install)) @@ -853,7 +854,7 @@ spotless { ## Gherkin -- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/5.15.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) +- `com.diffplug.gradle.spotless.GherkinExtension` [javadoc](https://javadoc.io/doc/com.diffplug.spotless/spotless-plugin-gradle/6.17.0/com/diffplug/gradle/spotless/GherkinExtension.html), [code](https://github.com/diffplug/spotless/blob/main/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java) ```gradle spotless { @@ -871,16 +872,13 @@ Uses a Gherkin pretty-printer that optionally allows configuring the number of s ```gradle spotless { gherkin { - target 'src/**/*.feature' + target 'src/**/*.feature' // required to be set explicitly simple() - // optional: specify the number of spaces to use - simple().indentWithSpaces(6) + .version('8.0.2') // optional: custom version of 'io.cucumber:gherkin-utils' } } ``` - - ## Prettier [homepage](https://prettier.io/). [changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md). [official plugins](https://prettier.io/docs/en/plugins.html#official-plugins). [community plugins](https://prettier.io/docs/en/plugins.html#community-plugins). Prettier is a formatter that can format almost every anything - JavaScript, JSX, Angular, Vue, Flow, TypeScript, CSS, Less, SCSS, HTML, JSON, GraphQL, Markdown (including GFM and MDX), and YAML. It can format even more [using plugins](https://prettier.io/docs/en/plugins.html) (PHP, Ruby, Swift, XML, Apex, Elm, Java (!!), Kotlin, pgSQL, .properties, solidity, svelte, toml, shellscript, ...). diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java index 59ff16805..f6f4c5a5c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.gherkin.GherkinSimpleConfig; import com.diffplug.spotless.gherkin.GherkinSimpleStep; public class GherkinExtension extends FormatExtension { - private static final int DEFAULT_INDENTATION = 4; static final String NAME = "gherkin"; @Inject @@ -38,12 +38,19 @@ protected void setupTask(SpotlessTask task) { } public SimpleConfig simple() { - return new SimpleConfig(DEFAULT_INDENTATION); + return new SimpleConfig(GherkinSimpleConfig.defaultIndentSpaces()); } public class SimpleConfig { + private String version; private int indent; + public SimpleConfig() { + this.version = GherkinSimpleStep.defaultVersion(); + this.indent = GherkinSimpleConfig.defaultIndentSpaces(); + addStep(createStep()); + } + public SimpleConfig(int indent) { this.indent = indent; addStep(createStep()); @@ -55,7 +62,7 @@ public void indentWithSpaces(int indent) { } private FormatterStep createStep() { - return GherkinSimpleStep.create(indent, provisioner()); + return GherkinSimpleStep.create(new GherkinSimpleConfig(indent), version, provisioner()); } } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java index 4b1fdc7ef..1be4f1f58 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class GherkinExtensionTest extends GradleIntegrationHarness { @Test diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 421b5e56e..f865ae4ea 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,6 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) +* Added support for Gherkin feature files (#???(???)) ## [2.35.0] - 2023-03-13 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 5971721e2..84ca19f58 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -53,6 +53,7 @@ user@machine repo % mvn spotless:check - [Javascript](#javascript) ([prettier](#prettier), [ESLint](#eslint-javascript)) - [JSON](#json) - [YAML](#yaml) + - [Gherkin](#gherkin) - Multiple languages - [Prettier](#prettier) ([plugins](#prettier-plugins), [npm detection](#npm-detection), [`.npmrc` detection](#npmrc-detection), [caching `npm install` results](#caching-results-of-npm-install)) - [eclipse web tools platform](#eclipse-web-tools-platform) @@ -973,7 +974,31 @@ Uses Jackson and YAMLFactory to pretty print objects: ``` - +## Gherkin + +- `com.diffplug.spotless.maven.FormatterFactory.addStepFactory(FormatterStepFactory)` [code](https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java) + +```gradle + + + + src/**/*.feature + + + + + +``` + +### simple + +Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: + +```xml + + 8.0.2 + +``` ## Prettier diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 2c0d6e35e..b864a28f4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -61,6 +61,7 @@ import com.diffplug.spotless.maven.cpp.Cpp; import com.diffplug.spotless.maven.generic.Format; import com.diffplug.spotless.maven.generic.LicenseHeader; +import com.diffplug.spotless.maven.gherkin.Gherkin; import com.diffplug.spotless.maven.groovy.Groovy; import com.diffplug.spotless.maven.incremental.UpToDateChecker; import com.diffplug.spotless.maven.incremental.UpToDateChecking; @@ -180,6 +181,9 @@ public abstract class AbstractSpotlessMojo extends AbstractMojo { @Parameter private Yaml yaml; + @Parameter + private Gherkin gherkin; + @Parameter(property = "spotlessFiles") private String filePatterns; @@ -354,7 +358,7 @@ private FileLocator getFileLocator() { } private List getFormatterFactories() { - return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown, json, yaml)) + return Stream.concat(formats.stream(), Stream.of(groovy, java, scala, kotlin, cpp, typescript, javascript, antlr4, pom, sql, python, markdown, json, yaml, gherkin)) .filter(Objects::nonNull) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java new file mode 100644 index 000000000..614e5026a --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023 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.maven.gherkin; + +import java.util.Collections; +import java.util.Set; + +import org.apache.maven.project.MavenProject; + +import com.diffplug.spotless.maven.FormatterFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class Gherkin extends FormatterFactory { + @Override + public Set defaultIncludes(MavenProject project) { + return Collections.emptySet(); + } + + @Override + public String licenseHeaderDelimiter() { + return null; + } + + public void addSimple(SimpleGherkin simple) { + addStepFactory(simple); + } + +} diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java new file mode 100644 index 000000000..e74bca929 --- /dev/null +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java @@ -0,0 +1,42 @@ +/* + * Copyright 2023 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.maven.gherkin; + +import org.apache.maven.plugins.annotations.Parameter; + +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.gherkin.GherkinSimpleConfig; +import com.diffplug.spotless.gherkin.GherkinSimpleStep; +import com.diffplug.spotless.maven.FormatterFactory; +import com.diffplug.spotless.maven.FormatterStepConfig; +import com.diffplug.spotless.maven.FormatterStepFactory; + +/** + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + */ +public class SimpleGherkin implements FormatterStepFactory { + + @Parameter + private String version = GherkinSimpleStep.defaultVersion(); + + @Parameter + private int indentWithSpaces = GherkinSimpleConfig.defaultIndentSpaces(); + + @Override + public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { + return GherkinSimpleStep.create(new GherkinSimpleConfig(indentWithSpaces), version, stepConfig.getProvisioner()); + } +} diff --git a/testlib/src/main/resources/gherkin/descriptionsAfter.feature b/testlib/src/main/resources/gherkin/descriptionsAfter.feature index e7998a203..9c0eb7e30 100644 --- a/testlib/src/main/resources/gherkin/descriptionsAfter.feature +++ b/testlib/src/main/resources/gherkin/descriptionsAfter.feature @@ -4,44 +4,52 @@ Feature: Descriptions everywhere Scenario: two lines This description has two lines and indented with two spaces + Given the minimalism Scenario: without indentation - This is a description without indentation +This is a description without indentation + Given the minimalism Scenario: empty lines in the middle This description has an empty line in the middle + Given the minimalism Scenario: empty lines around This description has an empty lines around + Given the minimalism Scenario: comment after description This description has a comment after + # this is a comment Given the minimalism Scenario: comment right after description This description has a comment right after - # this is another comment + + # this is another comment Given the minimalism Scenario: description with escaped docstring separator This description has an \"\"\" (escaped docstring sparator) + Given the minimalism Scenario Outline: scenario outline with a description - This is a scenario outline description +This is a scenario outline description + Given the minimalism Examples: examples with description - This is an examples description +This is an examples description | foo | | bar | diff --git a/testlib/src/main/resources/gherkin/minimalAfter.feature b/testlib/src/main/resources/gherkin/minimalAfter.feature index 44467df36..9a62d86f8 100644 --- a/testlib/src/main/resources/gherkin/minimalAfter.feature +++ b/testlib/src/main/resources/gherkin/minimalAfter.feature @@ -1,4 +1,4 @@ Feature: Minimal - Scenario: minimalistic - Given the minimalism + Scenario: minimalistic + Given the minimalism diff --git a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java index 1210bf21d..2c85d7206 100644 --- a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 DiffPlug + * Copyright 2021-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.SerializableEqualityTester; @@ -26,14 +27,15 @@ public class GherkinSimpleStepTest { - private static final int INDENT = 2; + private static final String VERSION = GherkinSimpleStep.defaultVersion(); + private static final int INDENT = GherkinSimpleConfig.defaultIndentSpaces(); - private final FormatterStep step = GherkinSimpleStep.create(INDENT, TestProvisioner.mavenCentral()); + private final FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(INDENT), VERSION, TestProvisioner.mavenCentral()); private final StepHarness stepHarness = StepHarness.forStep(step); @Test public void cannotProvidedNullProvisioner() { - assertThatThrownBy(() -> GherkinSimpleStep.create(INDENT, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); + assertThatThrownBy(() -> GherkinSimpleStep.create(new GherkinSimpleConfig(INDENT), VERSION, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); } @Test @@ -59,20 +61,21 @@ public void handlesRuleWithTag() throws Exception { @Test public void handlesInvalidGherkin() { assertThatThrownBy(() -> doWithResource(stepHarness, "invalidGherkin")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format Gherkin"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("No gherkin document"); } @Test public void handlesNotGherkin() { assertThatThrownBy(() -> doWithResource(stepHarness, "notGherkin")) - .isInstanceOf(AssertionError.class) - .hasMessage("Unable to format Gherkin"); + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("No gherkin document"); } + @Disabled("gherkin-utils does not allow custom indentation") @Test public void canSetCustomIndentationLevel() throws Exception { - FormatterStep step = GherkinSimpleStep.create(6, TestProvisioner.mavenCentral()); + FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(6), VERSION, TestProvisioner.mavenCentral()); StepHarness stepHarness = StepHarness.forStep(step); String before = "gherkin/minimalBefore.feature"; @@ -80,9 +83,10 @@ public void canSetCustomIndentationLevel() throws Exception { stepHarness.testResource(before, after); } + @Disabled("gherkin-utils does not allow custom indentation") @Test public void canSetIndentationLevelTo0() throws Exception { - FormatterStep step = GherkinSimpleStep.create(0, TestProvisioner.mavenCentral()); + FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(0), VERSION, TestProvisioner.mavenCentral()); StepHarness stepHarness = StepHarness.forStep(step); String before = "gherkin/minimalBefore.feature"; @@ -107,12 +111,12 @@ protected void setupTest(API api) { @Override protected FormatterStep create() { - return GherkinSimpleStep.create(spaces, TestProvisioner.mavenCentral()); + return GherkinSimpleStep.create(new GherkinSimpleConfig(spaces), VERSION, TestProvisioner.mavenCentral()); } }.testEquals(); } - private static void doWithResource(StepHarness stepHarness, String name) throws Exception { + private static void doWithResource(StepHarness stepHarness, String name) { String before = String.format("gherkin/%sBefore.feature", name); String after = String.format("gherkin/%sAfter.feature", name); stepHarness.testResource(before, after); From 1023d8cdb92a1c67accdfd13c6937cd5d07233a1 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sat, 1 Apr 2023 22:29:23 +0400 Subject: [PATCH 05/15] Fix MD related files --- CHANGES.md | 5 +---- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3911e67cd..31860d3bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)). +* Added formatter for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). ### Changes * **POTENTIALLY BREAKING** Converted `googleJavaFormat` to a compile-only dependency and drop support for versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) @@ -321,10 +322,6 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * `eclipse-jdt` from `4.19` to `4.20` * `eclipse-wtp` from `4.18` to `4.20` -### Added -* Added formatter for [Gherkin feature files](https://github.com/diffplug/spotless/issues/928) -* Added Gradle configuration for Gherkin feature files - ## [2.16.0] - 2021-09-04 ### Added * Added support for `google-java-format`'s `skip-reflowing-long-strings` option ([#929](https://github.com/diffplug/spotless/pull/929)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 62df3eac8..1d95606ab 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -14,7 +14,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ``` Mirrors are selected by prefix match, for example `https://download.eclipse.org/eclipse/updates/4.26/` will be redirected to `https://some.internal.mirror/eclipse/eclipse/updates/4.26/`. The same configuration exists for `greclipse` and `eclipseCdt`. -* Added support for Gherkin feature files (#???(???)) +* Added support for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f865ae4ea..1557fe396 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,7 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Added support for Gherkin feature files (#???(???)) +* Added support for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). ## [2.35.0] - 2023-03-13 ### Added From 3a1652a34a4c136cec5cac48060d71e6d67af5b5 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 2 Apr 2023 13:03:16 +0400 Subject: [PATCH 06/15] Fix tests --- .../gradle/spotless/GherkinExtension.java | 11 ++---- .../gradle/spotless/GherkinExtensionTest.java | 24 ++----------- .../maven/MavenIntegrationHarness.java | 4 +++ .../spotless/maven/gherkin/GherkinTest.java | 34 +++++++++++++++++++ 4 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java index f6f4c5a5c..ca2fcfbce 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java @@ -38,7 +38,7 @@ protected void setupTask(SpotlessTask task) { } public SimpleConfig simple() { - return new SimpleConfig(GherkinSimpleConfig.defaultIndentSpaces()); + return new SimpleConfig(); } public class SimpleConfig { @@ -51,13 +51,8 @@ public SimpleConfig() { addStep(createStep()); } - public SimpleConfig(int indent) { - this.indent = indent; - addStep(createStep()); - } - - public void indentWithSpaces(int indent) { - this.indent = indent; + public void version(String version) { + this.version = version; replaceStep(createStep()); } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java index 1be4f1f58..a89d0ae03 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java @@ -23,16 +23,16 @@ public class GherkinExtensionTest extends GradleIntegrationHarness { @Test public void defaultFormatting() throws IOException { setFile("build.gradle").toLines( - "buildscript { repositories { mavenCentral() } }", "plugins {", " id 'java'", " id 'com.diffplug.spotless'", "}", + "repositories { mavenCentral() }", "spotless {", - " gherkin {", + " gherkin {", " target 'examples/**/*.feature'", " simple()", - "}", + " }", "}"); setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); setFile("examples/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); @@ -41,22 +41,4 @@ public void defaultFormatting() throws IOException { assertFile("examples/main/resources/example.feature").sameAsResource("gherkin/minimalAfter.feature"); } - @Test - public void formattingWithCustomNumberOfSpaces() throws IOException { - setFile("build.gradle").toLines( - "buildscript { repositories { mavenCentral() } }", - "plugins {", - " id 'java'", - " id 'com.diffplug.spotless'", - "}", - "spotless {", - " gherkin {", - " target 'src/**/*.feature'", - " simple().indentWithSpaces(6)", - "}", - "}"); - setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("src/main/resources/example.feature").sameAsResource("gherkin/minimalAfter6Spaces.feature"); - } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 2891ee3b2..216502bc0 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -174,6 +174,10 @@ protected void writePomWithYamlSteps(String... steps) throws IOException { writePom(groupWithSteps("yaml", including("**/*.yaml"), steps)); } + protected void writePomWithGherkinSteps(String... steps) throws IOException { + writePom(groupWithSteps("gherkin", including("**/*.feature"), steps)); + } + protected void writePom(String... configuration) throws IOException { writePom(null, configuration, null, null); } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java new file mode 100644 index 000000000..314c4a58d --- /dev/null +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2023 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.maven.gherkin; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GherkinTest extends MavenIntegrationHarness { + @Test + public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { + writePomWithGherkinSteps(""); + + setFile("examples/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("examples/main/resources/example.feature").sameAsResource("gherkin/minimalAfter.feature"); + } + +} From 7661516567642de7931bd72ef3cd7a7118e6c1a9 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 2 Apr 2023 13:12:04 +0400 Subject: [PATCH 07/15] Fix style --- .../com/diffplug/gradle/spotless/GherkinExtensionTest.java | 2 +- .../com/diffplug/spotless/maven/gherkin/GherkinTest.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java index a89d0ae03..915322830 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java @@ -27,7 +27,7 @@ public void defaultFormatting() throws IOException { " id 'java'", " id 'com.diffplug.spotless'", "}", - "repositories { mavenCentral() }", + "repositories { mavenCentral() }", "spotless {", " gherkin {", " target 'examples/**/*.feature'", diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java index 314c4a58d..f4928da3d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java @@ -15,11 +15,9 @@ */ package com.diffplug.spotless.maven.gherkin; -import com.diffplug.spotless.maven.MavenIntegrationHarness; - import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import com.diffplug.spotless.maven.MavenIntegrationHarness; public class GherkinTest extends MavenIntegrationHarness { @Test From 9076bfb4271ed2f3aae71cc901b152f01c04f923 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 2 Apr 2023 18:51:54 +0400 Subject: [PATCH 08/15] Fix spotbugs --- .../java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java | 2 ++ .../src/main/resources/gherkin/complex_backgroundAfter.feature | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java index ba0d63763..6c718e038 100644 --- a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java @@ -18,6 +18,8 @@ import java.io.Serializable; public class GherkinSimpleConfig implements Serializable { + private static final long serialVersionUID = 1L; + public static int defaultIndentSpaces() { // https://cucumber.io/docs/gherkin/reference/ // Recommended indentation is 2 spaces diff --git a/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature index eb4d4de89..5a9553d98 100644 --- a/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature +++ b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature @@ -12,7 +12,7 @@ Feature: Complex background Rule: My Rule - Background: + Background: Given a rule background step Scenario: with examples From 86fc942a75e37c6ad0dea9348bbe858d382a91ae Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 5 Apr 2023 23:06:05 +0400 Subject: [PATCH 09/15] Rename simple to gherkinUtils --- plugin-gradle/README.md | 2 +- .../com/diffplug/gradle/spotless/GherkinExtension.java | 8 ++++---- .../diffplug/gradle/spotless/GherkinExtensionTest.java | 2 +- plugin-maven/README.md | 4 ++-- .../java/com/diffplug/spotless/maven/gherkin/Gherkin.java | 4 ++-- .../gherkin/{SimpleGherkin.java => GherkinUtils.java} | 4 ++-- .../com/diffplug/spotless/maven/gherkin/GherkinTest.java | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) rename plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/{SimpleGherkin.java => GherkinUtils.java} (91%) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 2caf22809..7a4673ccd 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -873,7 +873,7 @@ Uses a Gherkin pretty-printer that optionally allows configuring the number of s spotless { gherkin { target 'src/**/*.feature' // required to be set explicitly - simple() + gherkinUtils() .version('8.0.2') // optional: custom version of 'io.cucumber:gherkin-utils' } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java index ca2fcfbce..ab28e2213 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java @@ -37,15 +37,15 @@ protected void setupTask(SpotlessTask task) { super.setupTask(task); } - public SimpleConfig simple() { - return new SimpleConfig(); + public GherkinUtilsConfig gherkinUtils() { + return new GherkinUtilsConfig(); } - public class SimpleConfig { + public class GherkinUtilsConfig { private String version; private int indent; - public SimpleConfig() { + public GherkinUtilsConfig() { this.version = GherkinSimpleStep.defaultVersion(); this.indent = GherkinSimpleConfig.defaultIndentSpaces(); addStep(createStep()); diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java index 915322830..b78094cf1 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GherkinExtensionTest.java @@ -31,7 +31,7 @@ public void defaultFormatting() throws IOException { "spotless {", " gherkin {", " target 'examples/**/*.feature'", - " simple()", + " gherkinUtils()", " }", "}"); setFile("src/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 246452742..35caa4771 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -996,9 +996,9 @@ Uses Jackson and YAMLFactory to pretty print objects: Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: ```xml - + 8.0.2 - + ``` ## Prettier diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java index 614e5026a..60181d048 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/Gherkin.java @@ -36,8 +36,8 @@ public String licenseHeaderDelimiter() { return null; } - public void addSimple(SimpleGherkin simple) { - addStepFactory(simple); + public void addGherkinUtils(GherkinUtils gherkinUtils) { + addStepFactory(gherkinUtils); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java similarity index 91% rename from plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java rename to plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java index e74bca929..885d70187 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/SimpleGherkin.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java @@ -25,9 +25,9 @@ import com.diffplug.spotless.maven.FormatterStepFactory; /** - * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. + * A {@link FormatterFactory} implementation that corresponds to {@code ...} configuration element. */ -public class SimpleGherkin implements FormatterStepFactory { +public class GherkinUtils implements FormatterStepFactory { @Parameter private String version = GherkinSimpleStep.defaultVersion(); diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java index f4928da3d..95a60097d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/gherkin/GherkinTest.java @@ -22,7 +22,7 @@ public class GherkinTest extends MavenIntegrationHarness { @Test public void testFormatJson_WithSimple_defaultConfig_sortByKeys() throws Exception { - writePomWithGherkinSteps(""); + writePomWithGherkinSteps(""); setFile("examples/main/resources/example.feature").toResource("gherkin/minimalBefore.feature"); mavenRunner().withArguments("spotless:apply").runNoError(); From 9bc36a0745bd082635f56b700d14699351be395f Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 5 Apr 2023 23:09:45 +0400 Subject: [PATCH 10/15] Add link to homepage and changelog --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-gradle/README.md | 6 ++++-- plugin-maven/CHANGES.md | 2 +- plugin-maven/README.md | 4 +++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0905c1385..70200b092 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Support configuration of mirrors for P2 repositories in `EquoBasedStepBuilder` ([#1629](https://github.com/diffplug/spotless/issues/1629)). * The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). -* Added formatter for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). +* Added formatter for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). ### Changes * **POTENTIALLY BREAKING** Converted `googleJavaFormat` to a compile-only dependency and drop support for versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 61dca9cca..903064e2b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -15,7 +15,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( Mirrors are selected by prefix match, for example `https://download.eclipse.org/eclipse/updates/4.26/` will be redirected to `https://some.internal.mirror/eclipse/eclipse/updates/4.26/`. The same configuration exists for `greclipse` and `eclipseCdt`. * The `style` option in Palantir Java Format ([#1654](https://github.com/diffplug/spotless/pull/1654)). -* Added support for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). +* Added support for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 7a4673ccd..5ae9d2bd9 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -860,12 +860,14 @@ spotless { spotless { gherkin { target 'src/**/*.feature' // you have to set the target manually - simple() // has its own section below + gherkinUtils() // has its own section below } } ``` -### simple +### gherkinUtils + +[homepage](https://github.com/cucumber/gherkin-utils). [changelog](https://github.com/cucumber/gherkin-utils/blob/main/CHANGELOG.md). Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8fc3886d9..69877ce03 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -8,7 +8,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Changes * **POTENTIALLY BREAKING** Drop support for `googleJavaFormat` versions < `1.8`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) * Bump default `googleJavaFormat` version `1.15.0` -> `1.16.0`. ([#1630](https://github.com/diffplug/spotless/pull/1630)) -* Added support for Gherkin feature files ([1649](https://github.com/diffplug/spotless/issues/1649)). +* Added support for Gherkin feature files ([#1649](https://github.com/diffplug/spotless/issues/1649)). ## [2.35.0] - 2023-03-13 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 35caa4771..da7cc6ad0 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -986,13 +986,15 @@ Uses Jackson and YAMLFactory to pretty print objects: src/**/*.feature - + ``` ### simple +[homepage](https://github.com/cucumber/gherkin-utils). [changelog](https://github.com/cucumber/gherkin-utils/blob/main/CHANGELOG.md). + Uses a Gherkin pretty-printer that optionally allows configuring the number of spaces that are used to pretty print objects: ```xml From ac4884e3a688d0d0624e42e6b6ea8fc18b314134 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:13:17 -0700 Subject: [PATCH 11/15] Rename all the GherkinSimple classes to GherkinUtils. --- ...rFunc.java => GherkinUtilsFormatterFunc.java} | 10 +++++----- ...SimpleConfig.java => GherkinUtilsConfig.java} | 4 ++-- ...rkinSimpleStep.java => GherkinUtilsStep.java} | 16 ++++++++-------- .../gradle/spotless/GherkinExtension.java | 9 ++++----- .../spotless/maven/gherkin/GherkinUtils.java | 10 +++++----- .../spotless/gherkin/GherkinSimpleStepTest.java | 14 +++++++------- 6 files changed, 31 insertions(+), 32 deletions(-) rename lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/{GherkinFormatterFunc.java => GherkinUtilsFormatterFunc.java} (87%) rename lib/src/main/java/com/diffplug/spotless/gherkin/{GherkinSimpleConfig.java => GherkinUtilsConfig.java} (90%) rename lib/src/main/java/com/diffplug/spotless/gherkin/{GherkinSimpleStep.java => GherkinUtilsStep.java} (77%) diff --git a/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java similarity index 87% rename from lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java rename to lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java index f46f7da32..4b79347b2 100644 --- a/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinFormatterFunc.java +++ b/lib/src/gherkin/java/com/diffplug/spotless/glue/gherkin/GherkinUtilsFormatterFunc.java @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory; import com.diffplug.spotless.FormatterFunc; -import com.diffplug.spotless.gherkin.GherkinSimpleConfig; +import com.diffplug.spotless.gherkin.GherkinUtilsConfig; import io.cucumber.gherkin.GherkinParser; import io.cucumber.gherkin.utils.pretty.Pretty; @@ -29,12 +29,12 @@ import io.cucumber.messages.types.Source; import io.cucumber.messages.types.SourceMediaType; -public class GherkinFormatterFunc implements FormatterFunc { - private static final Logger LOGGER = LoggerFactory.getLogger(GherkinFormatterFunc.class); +public class GherkinUtilsFormatterFunc implements FormatterFunc { + private static final Logger LOGGER = LoggerFactory.getLogger(GherkinUtilsFormatterFunc.class); - private final GherkinSimpleConfig gherkinSimpleConfig; + private final GherkinUtilsConfig gherkinSimpleConfig; - public GherkinFormatterFunc(GherkinSimpleConfig gherkinSimpleConfig) { + public GherkinUtilsFormatterFunc(GherkinUtilsConfig gherkinSimpleConfig) { this.gherkinSimpleConfig = gherkinSimpleConfig; } diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsConfig.java similarity index 90% rename from lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java rename to lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsConfig.java index 6c718e038..d7962c654 100644 --- a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleConfig.java +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsConfig.java @@ -17,7 +17,7 @@ import java.io.Serializable; -public class GherkinSimpleConfig implements Serializable { +public class GherkinUtilsConfig implements Serializable { private static final long serialVersionUID = 1L; public static int defaultIndentSpaces() { @@ -28,7 +28,7 @@ public static int defaultIndentSpaces() { final int indentSpaces; - public GherkinSimpleConfig(int indentSpaces) { + public GherkinUtilsConfig(int indentSpaces) { this.indentSpaces = indentSpaces; } diff --git a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java similarity index 77% rename from lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java rename to lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java index 10954f2bb..78f5eacd3 100644 --- a/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinSimpleStep.java +++ b/lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java @@ -26,7 +26,7 @@ import com.diffplug.spotless.JarState; import com.diffplug.spotless.Provisioner; -public class GherkinSimpleStep { +public class GherkinUtilsStep { private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:"; private static final String DEFAULT_VERSION = "8.0.2"; @@ -34,32 +34,32 @@ public static String defaultVersion() { return DEFAULT_VERSION; } - public static FormatterStep create(GherkinSimpleConfig gherkinSimpleConfig, + public static FormatterStep create(GherkinUtilsConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) { Objects.requireNonNull(provisioner, "provisioner cannot be null"); - return FormatterStep.createLazy("gherkin", () -> new GherkinSimpleStep.State(gherkinSimpleConfig, formatterVersion, provisioner), GherkinSimpleStep.State::toFormatter); + return FormatterStep.createLazy("gherkin", () -> new GherkinUtilsStep.State(gherkinSimpleConfig, formatterVersion, provisioner), GherkinUtilsStep.State::toFormatter); } private static final class State implements Serializable { private static final long serialVersionUID = 1L; - private final GherkinSimpleConfig gherkinSimpleConfig; + private final GherkinUtilsConfig gherkinSimpleConfig; private final JarState jarState; - private State(GherkinSimpleConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) throws IOException { + private State(GherkinUtilsConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) throws IOException { this.gherkinSimpleConfig = gherkinSimpleConfig; this.jarState = JarState.from(MAVEN_COORDINATE + formatterVersion, provisioner); } FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { - Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinFormatterFunc"); - Constructor constructor = formatterFunc.getConstructor(GherkinSimpleConfig.class); + Class formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.gherkin.GherkinUtilsFormatterFunc"); + Constructor constructor = formatterFunc.getConstructor(GherkinUtilsConfig.class); return (FormatterFunc) constructor.newInstance(gherkinSimpleConfig); } } - private GherkinSimpleStep() { + private GherkinUtilsStep() { // cannot be directly instantiated } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java index ab28e2213..630528981 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GherkinExtension.java @@ -18,8 +18,7 @@ import javax.inject.Inject; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.gherkin.GherkinSimpleConfig; -import com.diffplug.spotless.gherkin.GherkinSimpleStep; +import com.diffplug.spotless.gherkin.GherkinUtilsStep; public class GherkinExtension extends FormatExtension { static final String NAME = "gherkin"; @@ -46,8 +45,8 @@ public class GherkinUtilsConfig { private int indent; public GherkinUtilsConfig() { - this.version = GherkinSimpleStep.defaultVersion(); - this.indent = GherkinSimpleConfig.defaultIndentSpaces(); + this.version = GherkinUtilsStep.defaultVersion(); + this.indent = com.diffplug.spotless.gherkin.GherkinUtilsConfig.defaultIndentSpaces(); addStep(createStep()); } @@ -57,7 +56,7 @@ public void version(String version) { } private FormatterStep createStep() { - return GherkinSimpleStep.create(new GherkinSimpleConfig(indent), version, provisioner()); + return GherkinUtilsStep.create(new com.diffplug.spotless.gherkin.GherkinUtilsConfig(indent), version, provisioner()); } } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java index 885d70187..2eeabb9ab 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/gherkin/GherkinUtils.java @@ -18,8 +18,8 @@ import org.apache.maven.plugins.annotations.Parameter; import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.gherkin.GherkinSimpleConfig; -import com.diffplug.spotless.gherkin.GherkinSimpleStep; +import com.diffplug.spotless.gherkin.GherkinUtilsConfig; +import com.diffplug.spotless.gherkin.GherkinUtilsStep; import com.diffplug.spotless.maven.FormatterFactory; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -30,13 +30,13 @@ public class GherkinUtils implements FormatterStepFactory { @Parameter - private String version = GherkinSimpleStep.defaultVersion(); + private String version = GherkinUtilsStep.defaultVersion(); @Parameter - private int indentWithSpaces = GherkinSimpleConfig.defaultIndentSpaces(); + private int indentWithSpaces = GherkinUtilsConfig.defaultIndentSpaces(); @Override public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { - return GherkinSimpleStep.create(new GherkinSimpleConfig(indentWithSpaces), version, stepConfig.getProvisioner()); + return GherkinUtilsStep.create(new GherkinUtilsConfig(indentWithSpaces), version, stepConfig.getProvisioner()); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java index 2c85d7206..56cad1273 100644 --- a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java @@ -27,15 +27,15 @@ public class GherkinSimpleStepTest { - private static final String VERSION = GherkinSimpleStep.defaultVersion(); - private static final int INDENT = GherkinSimpleConfig.defaultIndentSpaces(); + private static final String VERSION = GherkinUtilsStep.defaultVersion(); + private static final int INDENT = GherkinUtilsConfig.defaultIndentSpaces(); - private final FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(INDENT), VERSION, TestProvisioner.mavenCentral()); + private final FormatterStep step = GherkinUtilsStep.create(new GherkinUtilsConfig(INDENT), VERSION, TestProvisioner.mavenCentral()); private final StepHarness stepHarness = StepHarness.forStep(step); @Test public void cannotProvidedNullProvisioner() { - assertThatThrownBy(() -> GherkinSimpleStep.create(new GherkinSimpleConfig(INDENT), VERSION, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); + assertThatThrownBy(() -> GherkinUtilsStep.create(new GherkinUtilsConfig(INDENT), VERSION, null)).isInstanceOf(NullPointerException.class).hasMessage("provisioner cannot be null"); } @Test @@ -75,7 +75,7 @@ public void handlesNotGherkin() { @Disabled("gherkin-utils does not allow custom indentation") @Test public void canSetCustomIndentationLevel() throws Exception { - FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(6), VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GherkinUtilsStep.create(new GherkinUtilsConfig(6), VERSION, TestProvisioner.mavenCentral()); StepHarness stepHarness = StepHarness.forStep(step); String before = "gherkin/minimalBefore.feature"; @@ -86,7 +86,7 @@ public void canSetCustomIndentationLevel() throws Exception { @Disabled("gherkin-utils does not allow custom indentation") @Test public void canSetIndentationLevelTo0() throws Exception { - FormatterStep step = GherkinSimpleStep.create(new GherkinSimpleConfig(0), VERSION, TestProvisioner.mavenCentral()); + FormatterStep step = GherkinUtilsStep.create(new GherkinUtilsConfig(0), VERSION, TestProvisioner.mavenCentral()); StepHarness stepHarness = StepHarness.forStep(step); String before = "gherkin/minimalBefore.feature"; @@ -111,7 +111,7 @@ protected void setupTest(API api) { @Override protected FormatterStep create() { - return GherkinSimpleStep.create(new GherkinSimpleConfig(spaces), VERSION, TestProvisioner.mavenCentral()); + return GherkinUtilsStep.create(new GherkinUtilsConfig(spaces), VERSION, TestProvisioner.mavenCentral()); } }.testEquals(); } From aefa8c85be27498b6828f1299862a17ee6393280 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:13:35 -0700 Subject: [PATCH 12/15] Missing header update in plugin-maven/README. --- plugin-maven/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index da7cc6ad0..b12d777b2 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -991,7 +991,7 @@ Uses Jackson and YAMLFactory to pretty print objects: ``` -### simple +### gherkinUtils [homepage](https://github.com/cucumber/gherkin-utils). [changelog](https://github.com/cucumber/gherkin-utils/blob/main/CHANGELOG.md). From 8a4cee99837bfc92ab96b814bf7609832f03b7c2 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:13:42 -0700 Subject: [PATCH 13/15] Update the root README table. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 662c624bd..52628574d 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ lib('generic.TrimTrailingWhitespaceStep') +'{{yes}} | {{yes}} lib('antlr4.Antlr4FormatterStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', lib('cpp.ClangFormatStep') +'{{yes}} | {{no}} | {{no}} | {{no}} |', extra('cpp.EclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', +lib('gherkin.GherkinUtilsStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |', extra('groovy.GrEclipseFormatterStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.GoogleJavaFormatStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', lib('java.ImportOrderStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |', @@ -125,6 +126,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}} | [`antlr4.Antlr4FormatterStep`](lib/src/main/java/com/diffplug/spotless/antlr4/Antlr4FormatterStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`cpp.ClangFormatStep`](lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java) | :+1: | :white_large_square: | :white_large_square: | :white_large_square: | | [`cpp.EclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | +| [`gherkin.GherkinUtilsStep`](lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: | | [`groovy.GrEclipseFormatterStep`](lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.GoogleJavaFormatStep`](lib/src/main/java/com/diffplug/spotless/java/GoogleJavaFormatStep.java) | :+1: | :+1: | :+1: | :white_large_square: | | [`java.ImportOrderStep`](lib/src/main/java/com/diffplug/spotless/java/ImportOrderStep.java) | :+1: | :+1: | :+1: | :white_large_square: | From 051454677897ed410bb6287cfda7cba33852844e Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:40:01 -0700 Subject: [PATCH 14/15] Rename the test to match the rest. --- .../{GherkinSimpleStepTest.java => GherkinUtilsStepTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename testlib/src/test/java/com/diffplug/spotless/gherkin/{GherkinSimpleStepTest.java => GherkinUtilsStepTest.java} (99%) diff --git a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinUtilsStepTest.java similarity index 99% rename from testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java rename to testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinUtilsStepTest.java index 56cad1273..6bc478027 100644 --- a/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinSimpleStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/gherkin/GherkinUtilsStepTest.java @@ -25,7 +25,7 @@ import com.diffplug.spotless.StepHarness; import com.diffplug.spotless.TestProvisioner; -public class GherkinSimpleStepTest { +public class GherkinUtilsStepTest { private static final String VERSION = GherkinUtilsStep.defaultVersion(); private static final int INDENT = GherkinUtilsConfig.defaultIndentSpaces(); From 5bf01af2fee1c202868859aca4272e7472f1bc9f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Wed, 5 Apr 2023 14:41:57 -0700 Subject: [PATCH 15/15] Terrible trailing space is needed until cucumber/gherkin-utils#20 gets merged. --- .../src/main/resources/gherkin/complex_backgroundAfter.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature index eb4d4de89..5a9553d98 100644 --- a/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature +++ b/testlib/src/main/resources/gherkin/complex_backgroundAfter.feature @@ -12,7 +12,7 @@ Feature: Complex background Rule: My Rule - Background: + Background: Given a rule background step Scenario: with examples